diff --git a/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs b/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs index a43e3f44142..c85ec68e652 100644 --- a/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs +++ b/src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs @@ -5,7 +5,6 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.ValueGeneration; -using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; namespace Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration.Internal { @@ -23,7 +22,7 @@ public override ValueGenerator Create(IProperty property, IEntityType entityType if (property.GetJsonPropertyName() == "" && type == typeof(int)) { - return new TemporaryIntValueGenerator(); + return new TemporaryNumberValueGeneratorFactory().Create(property); } return base.Create(property, entityType); diff --git a/src/EFCore/ValueGeneration/Internal/BinaryValueGenerator.cs b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryBinaryValueGenerator.cs similarity index 70% rename from src/EFCore/ValueGeneration/Internal/BinaryValueGenerator.cs rename to src/EFCore.Relational/ValueGeneration/Internal/TemporaryBinaryValueGenerator.cs index 8ce3a65ec3a..ac7614041fc 100644 --- a/src/EFCore/ValueGeneration/Internal/BinaryValueGenerator.cs +++ b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryBinaryValueGenerator.cs @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class BinaryValueGenerator : ValueGenerator + public class TemporaryBinaryValueGenerator : ValueGenerator { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -20,18 +20,7 @@ public class BinaryValueGenerator : ValueGenerator /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public BinaryValueGenerator(bool generateTemporaryValues) - { - GeneratesTemporaryValues = generateTemporaryValues; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public override bool GeneratesTemporaryValues { get; } + public override bool GeneratesTemporaryValues => true; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/ValueGeneration/Internal/TemporaryDateTimeOffsetValueGenerator.cs b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryDateTimeOffsetValueGenerator.cs similarity index 100% rename from src/EFCore/ValueGeneration/Internal/TemporaryDateTimeOffsetValueGenerator.cs rename to src/EFCore.Relational/ValueGeneration/Internal/TemporaryDateTimeOffsetValueGenerator.cs diff --git a/src/EFCore/ValueGeneration/Internal/TemporaryDateTimeValueGenerator.cs b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryDateTimeValueGenerator.cs similarity index 100% rename from src/EFCore/ValueGeneration/Internal/TemporaryDateTimeValueGenerator.cs rename to src/EFCore.Relational/ValueGeneration/Internal/TemporaryDateTimeValueGenerator.cs diff --git a/src/EFCore/ValueGeneration/Internal/StringValueGenerator.cs b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryStringValueGenerator.cs similarity index 70% rename from src/EFCore/ValueGeneration/Internal/StringValueGenerator.cs rename to src/EFCore.Relational/ValueGeneration/Internal/TemporaryStringValueGenerator.cs index 6a36aa8d3d7..5a1e936c754 100644 --- a/src/EFCore/ValueGeneration/Internal/StringValueGenerator.cs +++ b/src/EFCore.Relational/ValueGeneration/Internal/TemporaryStringValueGenerator.cs @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public class StringValueGenerator : ValueGenerator + public class TemporaryStringValueGenerator : ValueGenerator { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -20,18 +20,7 @@ public class StringValueGenerator : ValueGenerator /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public StringValueGenerator(bool generateTemporaryValues) - { - GeneratesTemporaryValues = generateTemporaryValues; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public override bool GeneratesTemporaryValues { get; } + public override bool GeneratesTemporaryValues => true; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs index 0982fe2dfaf..9f2d598e8e7 100644 --- a/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs +++ b/src/EFCore.Relational/ValueGeneration/RelationalValueGeneratorSelector.cs @@ -28,9 +28,7 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration public class RelationalValueGeneratorSelector : ValueGeneratorSelector { private readonly TemporaryNumberValueGeneratorFactory _numberFactory -#pragma warning disable EF1001 // Internal EF Core API usage. = new TemporaryNumberValueGeneratorFactory(); -#pragma warning restore EF1001 // Internal EF Core API usage. /// /// Initializes a new instance of the class. @@ -64,23 +62,17 @@ public override ValueGenerator Create(IProperty property, IEntityType entityType || propertyType == typeof(float) || propertyType == typeof(double)) { -#pragma warning disable EF1001 // Internal EF Core API usage. return _numberFactory.Create(property); -#pragma warning restore EF1001 // Internal EF Core API usage. } if (propertyType == typeof(DateTime)) { -#pragma warning disable EF1001 // Internal EF Core API usage. return new TemporaryDateTimeValueGenerator(); -#pragma warning restore EF1001 // Internal EF Core API usage. } if (propertyType == typeof(DateTimeOffset)) { -#pragma warning disable EF1001 // Internal EF Core API usage. return new TemporaryDateTimeOffsetValueGenerator(); -#pragma warning restore EF1001 // Internal EF Core API usage. } if (property.GetDefaultValueSql() != null) @@ -92,16 +84,12 @@ public override ValueGenerator Create(IProperty property, IEntityType entityType if (propertyType == typeof(string)) { -#pragma warning disable EF1001 // Internal EF Core API usage. - return new StringValueGenerator(generateTemporaryValues: true); -#pragma warning restore EF1001 // Internal EF Core API usage. + return new TemporaryStringValueGenerator(); } if (propertyType == typeof(byte[])) { -#pragma warning disable EF1001 // Internal EF Core API usage. - return new BinaryValueGenerator(generateTemporaryValues: true); -#pragma warning restore EF1001 // Internal EF Core API usage. + return new TemporaryBinaryValueGenerator(); } } } diff --git a/src/EFCore/ValueGeneration/BinaryValueGenerator.cs b/src/EFCore/ValueGeneration/BinaryValueGenerator.cs new file mode 100644 index 00000000000..913a09f6b75 --- /dev/null +++ b/src/EFCore/ValueGeneration/BinaryValueGenerator.cs @@ -0,0 +1,27 @@ +// 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.ChangeTracking; + +namespace Microsoft.EntityFrameworkCore.ValueGeneration +{ + /// + /// Generates an array bytes from . + /// The generated values are non-temporary, meaning they will be saved to the database. + /// + public class BinaryValueGenerator : ValueGenerator + { + /// + /// Gets a value indicating whether the values generated are temporary or permanent. This implementation + /// always returns false, meaning the generated values will be saved to the database. + /// + public override bool GeneratesTemporaryValues => false; + + /// + /// Gets a value to be assigned to a property. + /// + /// The value to be assigned to a property. + public override byte[] Next(EntityEntry entry) => Guid.NewGuid().ToByteArray(); + } +} diff --git a/src/EFCore/ValueGeneration/GuidValueGenerator.cs b/src/EFCore/ValueGeneration/GuidValueGenerator.cs index 9e367121d50..19ed62f18c8 100644 --- a/src/EFCore/ValueGeneration/GuidValueGenerator.cs +++ b/src/EFCore/ValueGeneration/GuidValueGenerator.cs @@ -15,7 +15,7 @@ public class GuidValueGenerator : ValueGenerator /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The value to be assigned to a property. public override Guid Next(EntityEntry entry) => Guid.NewGuid(); diff --git a/src/EFCore/ValueGeneration/HiLoValueGenerator.cs b/src/EFCore/ValueGeneration/HiLoValueGenerator.cs index 73af4562389..55e1cb484b0 100644 --- a/src/EFCore/ValueGeneration/HiLoValueGenerator.cs +++ b/src/EFCore/ValueGeneration/HiLoValueGenerator.cs @@ -40,14 +40,15 @@ protected HiLoValueGenerator([NotNull] HiLoValueGeneratorState generatorState) /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The value to be assigned to a property. public override TValue Next(EntityEntry entry) => _generatorState.Next(GetNewLowValue); /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. + /// A to observe while waiting for the task to complete. /// The value to be assigned to a property. public override ValueTask NextAsync( EntityEntry entry, CancellationToken cancellationToken = default) diff --git a/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs b/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs index 872ae587f02..c05281a33b5 100644 --- a/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs +++ b/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs @@ -20,7 +20,7 @@ public class SequentialGuidValueGenerator : ValueGenerator /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The value to be assigned to a property. public override Guid Next(EntityEntry entry) { diff --git a/src/EFCore/ValueGeneration/StringValueGenerator.cs b/src/EFCore/ValueGeneration/StringValueGenerator.cs new file mode 100644 index 00000000000..58929604e77 --- /dev/null +++ b/src/EFCore/ValueGeneration/StringValueGenerator.cs @@ -0,0 +1,27 @@ +// 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.ChangeTracking; + +namespace Microsoft.EntityFrameworkCore.ValueGeneration +{ + /// + /// Generates values using a string representation of . + /// The generated values are non-temporary, meaning they will be saved to the database. + /// + public class StringValueGenerator : ValueGenerator + { + /// + /// Gets a value indicating whether the values generated are temporary or permanent. This implementation + /// always returns false, meaning the generated values will be saved to the database. + /// + public override bool GeneratesTemporaryValues => false; + + /// + /// Gets a value to be assigned to a property. + /// + /// The value to be assigned to a property. + public override string Next(EntityEntry entry) => Guid.NewGuid().ToString(); + } +} diff --git a/src/EFCore/ValueGeneration/TemporaryGuidValueGenerator.cs b/src/EFCore/ValueGeneration/TemporaryGuidValueGenerator.cs index 87f59906f35..21575fde7ea 100644 --- a/src/EFCore/ValueGeneration/TemporaryGuidValueGenerator.cs +++ b/src/EFCore/ValueGeneration/TemporaryGuidValueGenerator.cs @@ -13,10 +13,9 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration public class TemporaryGuidValueGenerator : GuidValueGenerator { /// - /// Gets a value indicating whether the values generated are temporary or permanent. This implementation - /// always returns true, meaning the generated values will be replaced by database generated values when - /// the entity is saved + /// Gets a value to be assigned to a property. /// + /// The value to be assigned to a property. public override bool GeneratesTemporaryValues => true; } } diff --git a/src/EFCore/ValueGeneration/Internal/TemporaryNumberValueGeneratorFactory.cs b/src/EFCore/ValueGeneration/TemporaryNumberValueGeneratorFactory.cs similarity index 71% rename from src/EFCore/ValueGeneration/Internal/TemporaryNumberValueGeneratorFactory.cs rename to src/EFCore/ValueGeneration/TemporaryNumberValueGeneratorFactory.cs index a507dee85ca..82f7a6f1dd0 100644 --- a/src/EFCore/ValueGeneration/Internal/TemporaryNumberValueGeneratorFactory.cs +++ b/src/EFCore/ValueGeneration/TemporaryNumberValueGeneratorFactory.cs @@ -4,23 +4,28 @@ using System; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; -namespace Microsoft.EntityFrameworkCore.ValueGeneration.Internal +namespace Microsoft.EntityFrameworkCore.ValueGeneration { /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// + /// Factory for creation of temporary integer value generators appropriate + /// for the numeric type of the property. + /// + /// + /// Types supported are: , , , , + /// , , , , , + /// , , + /// /// public class TemporaryNumberValueGeneratorFactory : ValueGeneratorFactory { /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. + /// Creates a new value generator. /// + /// The property to create the value generator for. + /// The newly created value generator. public override ValueGenerator Create(IProperty property) { var type = property.ClrType.UnwrapNullableType().UnwrapEnumType(); diff --git a/src/EFCore/ValueGeneration/ValueGenerator.cs b/src/EFCore/ValueGeneration/ValueGenerator.cs index 6f30f559d71..c4504b55423 100644 --- a/src/EFCore/ValueGeneration/ValueGenerator.cs +++ b/src/EFCore/ValueGeneration/ValueGenerator.cs @@ -17,7 +17,7 @@ public abstract class ValueGenerator /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The value to be assigned to a property. public virtual object Next([NotNull] EntityEntry entry) => NextValue(entry); @@ -25,14 +25,15 @@ public virtual object Next([NotNull] EntityEntry entry) /// /// Template method to be overridden by implementations to perform value generation. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The generated value. protected abstract object NextValue([NotNull] EntityEntry entry); /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. + /// A to observe while waiting for the task to complete. /// The value to be assigned to a property. public virtual ValueTask NextAsync( [NotNull] EntityEntry entry, @@ -42,7 +43,8 @@ public virtual ValueTask NextAsync( /// /// Template method to be overridden by implementations to perform value generation. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. + /// A to observe while waiting for the task to complete. /// The generated value. protected virtual ValueTask NextValueAsync( [NotNull] EntityEntry entry, diff --git a/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs b/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs index afb761a6fcf..a7308e8b744 100644 --- a/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs +++ b/src/EFCore/ValueGeneration/ValueGeneratorSelector.cs @@ -7,7 +7,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; -using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.EntityFrameworkCore.ValueGeneration @@ -118,12 +117,12 @@ public virtual ValueGenerator Create([NotNull] IProperty property, [NotNull] IEn if (propertyType == typeof(string)) { - return new StringValueGenerator(generateTemporaryValues: false); + return new StringValueGenerator(); } if (propertyType == typeof(byte[])) { - return new BinaryValueGenerator(generateTemporaryValues: false); + return new BinaryValueGenerator(); } throw new NotSupportedException( diff --git a/src/EFCore/ValueGeneration/ValueGenerator`.cs b/src/EFCore/ValueGeneration/ValueGenerator`.cs index 922daed32dc..e81bf78f7fa 100644 --- a/src/EFCore/ValueGeneration/ValueGenerator`.cs +++ b/src/EFCore/ValueGeneration/ValueGenerator`.cs @@ -16,14 +16,15 @@ public abstract class ValueGenerator : ValueGenerator /// /// Template method to be overridden by implementations to perform value generation. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The generated value. public new abstract TValue Next([NotNull] EntityEntry entry); /// /// Template method to be overridden by implementations to perform value generation. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. + /// A to observe while waiting for the task to complete. /// The generated value. public new virtual ValueTask NextAsync( [NotNull] EntityEntry entry, @@ -33,7 +34,7 @@ public abstract class ValueGenerator : ValueGenerator /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. /// The value to be assigned to a property. protected override object NextValue(EntityEntry entry) => Next(entry); @@ -41,7 +42,8 @@ protected override object NextValue(EntityEntry entry) /// /// Gets a value to be assigned to a property. /// - /// The change tracking entry of the entity for which the value is being generated. + /// The change tracking entry of the entity for which the value is being generated. + /// A to observe while waiting for the task to complete. /// The value to be assigned to a property. protected override ValueTask NextValueAsync( EntityEntry entry, diff --git a/test/EFCore.Relational.Tests/ValueGeneration/TemporaryBinaryValueGeneratorTest.cs b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryBinaryValueGeneratorTest.cs new file mode 100644 index 00000000000..99317485dd3 --- /dev/null +++ b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryBinaryValueGeneratorTest.cs @@ -0,0 +1,35 @@ +// 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 System.Collections.Generic; +using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; +using Xunit; + +namespace Microsoft.EntityFrameworkCore.ValueGeneration +{ + public class TemporaryBinaryValueGeneratorTest + { + [ConditionalFact] + public void Creates_GUID_arrays() + { + var generator = new TemporaryBinaryValueGenerator(); + + var values = new HashSet(); + for (var i = 0; i < 100; i++) + { + var generatedValue = generator.Next(null); + + values.Add(new Guid(generatedValue)); + } + + Assert.Equal(100, values.Count); + } + + [ConditionalFact] + public void Generates_temp_values() + { + Assert.True(new TemporaryBinaryValueGenerator().GeneratesTemporaryValues); + } + } +} diff --git a/test/EFCore.Tests/ValueGeneration/TemporaryDateTimeOffsetValueGeneratorTest.cs b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryDateTimeOffsetValueGeneratorTest.cs similarity index 100% rename from test/EFCore.Tests/ValueGeneration/TemporaryDateTimeOffsetValueGeneratorTest.cs rename to test/EFCore.Relational.Tests/ValueGeneration/TemporaryDateTimeOffsetValueGeneratorTest.cs diff --git a/test/EFCore.Relational.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs new file mode 100644 index 00000000000..984efe05edd --- /dev/null +++ b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs @@ -0,0 +1,27 @@ +// 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.ValueGeneration.Internal; +using Xunit; + +namespace Microsoft.EntityFrameworkCore.ValueGeneration +{ + public class TemporaryDateTimeValueGeneratorTest + { + [ConditionalFact] + public void Can_create_values_for_DateTime_types() + { + var generator = new TemporaryDateTimeValueGenerator(); + + Assert.Equal(new DateTime(1), generator.Next(null)); + Assert.Equal(new DateTime(2), generator.Next(null)); + } + + [ConditionalFact] + public void Generates_temporary_values() + { + Assert.True(new TemporaryDateTimeValueGenerator().GeneratesTemporaryValues); + } + } +} diff --git a/test/EFCore.Relational.Tests/ValueGeneration/TemporaryStringValueGeneratorTest.cs b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryStringValueGeneratorTest.cs new file mode 100644 index 00000000000..c13d181975e --- /dev/null +++ b/test/EFCore.Relational.Tests/ValueGeneration/TemporaryStringValueGeneratorTest.cs @@ -0,0 +1,35 @@ +// 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 System.Collections.Generic; +using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; +using Xunit; + +namespace Microsoft.EntityFrameworkCore.ValueGeneration +{ + public class TemporaryStringValueGeneratorTest + { + [ConditionalFact] + public void Creates_GUID_strings() + { + var generator = new TemporaryStringValueGenerator(); + + var values = new HashSet(); + for (var i = 0; i < 100; i++) + { + var generatedValue = generator.Next(null); + + values.Add(Guid.Parse(generatedValue)); + } + + Assert.Equal(100, values.Count); + } + + [ConditionalFact] + public void Generates_temp_values() + { + Assert.True(new TemporaryStringValueGenerator().GeneratesTemporaryValues); + } + } +} diff --git a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs index 14f34567050..f15d7a262f8 100644 --- a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs +++ b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs @@ -95,7 +95,7 @@ public void Returns_temp_string_generator_when_default_sql_set() var selector = SqlServerTestHelpers.Instance.CreateContextServices(model).GetRequiredService(); var generator = selector.Select(entityType.FindProperty("String"), entityType); - Assert.IsType(generator); + Assert.IsType(generator); Assert.True(generator.GeneratesTemporaryValues); } @@ -115,7 +115,7 @@ public void Returns_temp_binary_generator_when_default_sql_set() var selector = SqlServerTestHelpers.Instance.CreateContextServices(model).GetRequiredService(); var generator = selector.Select(entityType.FindProperty("Binary"), entityType); - Assert.IsType(generator); + Assert.IsType(generator); Assert.True(generator.GeneratesTemporaryValues); } diff --git a/test/EFCore.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs index 9aa5115919c..4a5465bc91d 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/KeyPropagatorTest.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.TestUtilities; -using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; +using Microsoft.EntityFrameworkCore.ValueGeneration; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/test/EFCore.Tests/ValueGeneration/BinaryValueGeneratorTest.cs b/test/EFCore.Tests/ValueGeneration/BinaryValueGeneratorTest.cs index 94637cf9090..560f8746a85 100644 --- a/test/EFCore.Tests/ValueGeneration/BinaryValueGeneratorTest.cs +++ b/test/EFCore.Tests/ValueGeneration/BinaryValueGeneratorTest.cs @@ -13,7 +13,7 @@ public class BinaryValueGeneratorTest [ConditionalFact] public void Creates_GUID_arrays() { - var generator = new BinaryValueGenerator(generateTemporaryValues: true); + var generator = new BinaryValueGenerator(); var values = new HashSet(); for (var i = 0; i < 100; i++) @@ -27,10 +27,9 @@ public void Creates_GUID_arrays() } [ConditionalFact] - public void Generates_temp_or_non_temp_values() + public void Generates_non_temp_values() { - Assert.True(new BinaryValueGenerator(generateTemporaryValues: true).GeneratesTemporaryValues); - Assert.False(new BinaryValueGenerator(generateTemporaryValues: false).GeneratesTemporaryValues); + Assert.False(new BinaryValueGenerator().GeneratesTemporaryValues); } } } diff --git a/test/EFCore.Tests/ValueGeneration/StringValueGeneratorTest.cs b/test/EFCore.Tests/ValueGeneration/StringValueGeneratorTest.cs index 5814b046aec..c77aa91d59f 100644 --- a/test/EFCore.Tests/ValueGeneration/StringValueGeneratorTest.cs +++ b/test/EFCore.Tests/ValueGeneration/StringValueGeneratorTest.cs @@ -13,7 +13,7 @@ public class StringValueGeneratorTest [ConditionalFact] public void Creates_GUID_strings() { - var generator = new StringValueGenerator(generateTemporaryValues: true); + var generator = new StringValueGenerator(); var values = new HashSet(); for (var i = 0; i < 100; i++) @@ -27,10 +27,9 @@ public void Creates_GUID_strings() } [ConditionalFact] - public void Generates_temp_or_non_temp_values() + public void Generates_non_temp_values() { - Assert.True(new StringValueGenerator(generateTemporaryValues: true).GeneratesTemporaryValues); - Assert.False(new StringValueGenerator(generateTemporaryValues: false).GeneratesTemporaryValues); + Assert.False(new StringValueGenerator().GeneratesTemporaryValues); } } } diff --git a/test/EFCore.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs b/test/EFCore.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs index 984efe05edd..957457e25e0 100644 --- a/test/EFCore.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs +++ b/test/EFCore.Tests/ValueGeneration/TemporaryDateTimeValueGeneratorTest.cs @@ -7,21 +7,4 @@ namespace Microsoft.EntityFrameworkCore.ValueGeneration { - public class TemporaryDateTimeValueGeneratorTest - { - [ConditionalFact] - public void Can_create_values_for_DateTime_types() - { - var generator = new TemporaryDateTimeValueGenerator(); - - Assert.Equal(new DateTime(1), generator.Next(null)); - Assert.Equal(new DateTime(2), generator.Next(null)); - } - - [ConditionalFact] - public void Generates_temporary_values() - { - Assert.True(new TemporaryDateTimeValueGenerator().GeneratesTemporaryValues); - } - } }