Skip to content

Commit

Permalink
Add API and tests for value converters
Browse files Browse the repository at this point in the history
Part of issue #242

As always, fluent API names subject to change in API review.

This PR also makes a change to never pass nulls to value converters. This makes it significantly easier to write custom converters that compose well with built-in converters and can be used for both PKs and FKs where the nullability is different.
  • Loading branch information
ajcvickers committed Jan 2, 2018
1 parent 5c46824 commit d4bc77c
Show file tree
Hide file tree
Showing 49 changed files with 2,328 additions and 871 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,32 @@ const string query
BuiltInDataTypes.TestUnsignedInt16 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypes.TestUnsignedInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInDataTypes.TestUnsignedInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInDataTypesShadow.Enum16 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInDataTypesShadow.Enum32 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.Enum64 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInDataTypesShadow.Enum8 ---> [NUMBER] [MaxLength = 22] [Precision = 3 [Precision = 3 Scale = 0]
BuiltInDataTypesShadow.EnumS8 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInDataTypesShadow.EnumU16 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.EnumU32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInDataTypesShadow.EnumU64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInDataTypesShadow.Id ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.PartitionId ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.TestBoolean ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.TestByte ---> [NUMBER] [MaxLength = 22] [Precision = 3 [Precision = 3 Scale = 0]
BuiltInDataTypesShadow.TestCharacter ---> [NVARCHAR2] [MaxLength = 2]
BuiltInDataTypesShadow.TestDateTime ---> [TIMESTAMP(6)] [MaxLength = 11] Scale = 6]
BuiltInDataTypesShadow.TestDateTimeOffset ---> [TIMESTAMP(6) WITH TIME ZONE] [MaxLength = 13] Scale = 6]
BuiltInDataTypesShadow.TestDecimal ---> [NUMBER] [MaxLength = 22] [Precision = 29 [Precision = 29 Scale = 4]
BuiltInDataTypesShadow.TestDouble ---> [FLOAT] [MaxLength = 22] [Precision = 49 [Precision = 49]
BuiltInDataTypesShadow.TestInt16 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInDataTypesShadow.TestInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.TestInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInDataTypesShadow.TestSignedByte ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInDataTypesShadow.TestSingle ---> [FLOAT] [MaxLength = 22] [Precision = 63 [Precision = 63]
BuiltInDataTypesShadow.TestTimeSpan ---> [INTERVAL DAY(2) TO SECOND(6)] [MaxLength = 11] [Precision = 2 [Precision = 2 Scale = 6]
BuiltInDataTypesShadow.TestUnsignedInt16 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInDataTypesShadow.TestUnsignedInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInDataTypesShadow.TestUnsignedInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInNullableDataTypes.Enum16 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInNullableDataTypes.Enum32 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypes.Enum64 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
Expand Down Expand Up @@ -1877,6 +1903,34 @@ const string query
BuiltInNullableDataTypes.TestNullableUnsignedInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInNullableDataTypes.TestNullableUnsignedInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInNullableDataTypes.TestString ---> [NVARCHAR2] [MaxLength = 4000]
BuiltInNullableDataTypesShadow.Enum16 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInNullableDataTypesShadow.Enum32 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.Enum64 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInNullableDataTypesShadow.Enum8 ---> [NUMBER] [MaxLength = 22] [Precision = 3 [Precision = 3 Scale = 0]
BuiltInNullableDataTypesShadow.EnumS8 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInNullableDataTypesShadow.EnumU16 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.EnumU32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInNullableDataTypesShadow.EnumU64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInNullableDataTypesShadow.Id ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.PartitionId ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.TestByteArray ---> [BLOB] [MaxLength = 4000]
BuiltInNullableDataTypesShadow.TestNullableBoolean ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableByte ---> [NUMBER] [MaxLength = 22] [Precision = 3 [Precision = 3 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableCharacter ---> [NVARCHAR2] [MaxLength = 2]
BuiltInNullableDataTypesShadow.TestNullableDateTime ---> [TIMESTAMP(6)] [MaxLength = 11] Scale = 6]
BuiltInNullableDataTypesShadow.TestNullableDateTimeOffset ---> [TIMESTAMP(6) WITH TIME ZONE] [MaxLength = 13] Scale = 6]
BuiltInNullableDataTypesShadow.TestNullableDecimal ---> [NUMBER] [MaxLength = 22] [Precision = 29 [Precision = 29 Scale = 4]
BuiltInNullableDataTypesShadow.TestNullableDouble ---> [FLOAT] [MaxLength = 22] [Precision = 49 [Precision = 49]
BuiltInNullableDataTypesShadow.TestNullableInt16 ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableSignedByte ---> [NUMBER] [MaxLength = 22] [Precision = 6 [Precision = 6 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableSingle ---> [FLOAT] [MaxLength = 22] [Precision = 63 [Precision = 63]
BuiltInNullableDataTypesShadow.TestNullableTimeSpan ---> [INTERVAL DAY(2) TO SECOND(6)] [MaxLength = 11] [Precision = 2 [Precision = 2 Scale = 6]
BuiltInNullableDataTypesShadow.TestNullableUnsignedInt16 ---> [NUMBER] [MaxLength = 22] [Precision = 10 [Precision = 10 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableUnsignedInt32 ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
BuiltInNullableDataTypesShadow.TestNullableUnsignedInt64 ---> [NUMBER] [MaxLength = 22] [Precision = 20 [Precision = 20 Scale = 0]
BuiltInNullableDataTypesShadow.TestString ---> [NVARCHAR2] [MaxLength = 4000]
MappedDataTypes.Bigint ---> [NUMBER] [MaxLength = 22] [Precision = 19 [Precision = 19 Scale = 0]
MappedDataTypes.Bit ---> [NUMBER] [MaxLength = 22] [Precision = 1 [Precision = 1 Scale = 0]
MappedDataTypes.Char_varyingMax ---> [VARCHAR2] [MaxLength = 2000]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Microsoft.EntityFrameworkCore
{
public class ConvertToStoreTypesOracleTest : ConvertToStoreTypesTestBase<ConvertToStoreTypesOracleTest.ConvertToStoreTypesOracleFixture>
{
public ConvertToStoreTypesOracleTest(ConvertToStoreTypesOracleFixture fixture, ITestOutputHelper testOutputHelper)
: base(fixture)
{
fixture.TestSqlLoggerFactory.Clear();
//fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

public override void Can_perform_query_with_max_length()
{
// Disabled--sample Oracle cannot query against large data types
}

public class ConvertToStoreTypesOracleFixture : ConvertToStoreTypesFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => OracleTestStoreFactory.Instance;
public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ServiceProvider.GetRequiredService<ILoggerFactory>();

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(
c => c.Log(RelationalEventId.QueryClientEvaluationWarning));

public override bool SupportsBinaryKeys => true;

public override DateTime DefaultDateTime => new DateTime();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class CustomConvertersOracleTest : CustomConvertersTestBase<CustomConvertersOracleTest.CustomConvertersOracleFixture>
{
public CustomConvertersOracleTest(CustomConvertersOracleFixture fixture)
: base(fixture)
{
}

public override void Can_perform_query_with_max_length()
{
// Disabled--sample Oracle cannot query against large data types
}

public class CustomConvertersOracleFixture : CustomConvertersFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => OracleTestStoreFactory.Instance;

public override bool SupportsBinaryKeys => true;

public override DateTime DefaultDateTime => new DateTime();

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base
.AddOptions(builder)
.ConfigureWarnings(
c => c.Log(RelationalEventId.QueryClientEvaluationWarning));
}
}
}
Loading

0 comments on commit d4bc77c

Please sign in to comment.