コード例 #1
0
        public void GenerateCanReturnNullAndRandomValuesTest()
        {
            var nullFound = false;
            var valueFound = false;

            var target = new GuidValueGenerator();

            for (var index = 0; index < 1000; index++)
            {
                var value = (Guid?)target.Generate(typeof(Guid?), null, null);

                if (value == null)
                {
                    nullFound = true;
                }
                else if (value.Value != Guid.Empty)
                {
                    valueFound = true;
                }

                if (nullFound && valueFound)
                {
                    break;
                }
            }

            nullFound.Should().BeTrue();
            valueFound.Should().BeTrue();
        }
コード例 #2
0
        public async Task Creates_GUIDs_test(bool async)
        {
            var sequentialGuidIdentityGenerator = new GuidValueGenerator();

            var stateEntry = TestHelpers.CreateStateEntry <WithGuid>(_model);
            var property   = stateEntry.EntityType.GetProperty("Id");

            var values = new HashSet <Guid>();

            for (var i = 0; i < 100; i++)
            {
                if (async)
                {
                    await sequentialGuidIdentityGenerator.NextAsync(stateEntry, property);
                }
                else
                {
                    sequentialGuidIdentityGenerator.Next(stateEntry, property);
                }

                Assert.False(stateEntry.HasTemporaryValue(property));

                values.Add((Guid)stateEntry[property]);
            }

            Assert.Equal(100, values.Count);
        }
コード例 #3
0
        public void IsSupportedReturnsWhetherTypeIsSupportedTest(Type type, bool supportedType)
        {
            var target = new GuidValueGenerator();

            var actual = target.IsSupported(type, null, null);

            actual.Should().Be(supportedType);
        }
コード例 #4
0
        public void GenerateReturnsRandomGuidValueTest()
        {
            var target = new GuidValueGenerator();

            var first = (Guid)target.Generate(typeof(Guid), null, null);
            var second = (Guid)target.Generate(typeof(Guid), null, null);

            first.Should().NotBeEmpty();
            second.Should().NotBeEmpty();
            first.Should().NotBe(second);
        }
コード例 #5
0
        public void Creates_GUIDs()
        {
            var sequentialGuidIdentityGenerator = new GuidValueGenerator();

            var values = new HashSet<Guid>();
            for (var i = 0; i < 100; i++)
            {
                var generatedValue = sequentialGuidIdentityGenerator.Next();

                values.Add(generatedValue);
            }

            Assert.Equal(100, values.Count);
        }
コード例 #6
0
        public void GenerateEvaluatesWhetherTypeIsSupportedTest(Type type, bool supportedType)
        {
            var target = new GuidValueGenerator();

            Action action = () => target.Generate(type, null, null);

            if (supportedType)
            {
                action.ShouldNotThrow();
            }
            else
            {
                action.ShouldThrow<NotSupportedException>();
            }
        }
コード例 #7
0
        public void Creates_GUIDs()
        {
            var sequentialGuidIdentityGenerator = new GuidValueGenerator();

            var values = new HashSet <Guid>();

            for (var i = 0; i < 100; i++)
            {
                var generatedValue = sequentialGuidIdentityGenerator.Next(null);

                values.Add(generatedValue);
            }

            Assert.Equal(100, values.Count);
        }
コード例 #8
0
        public async Task Creates_GUIDs_test(bool async)
        {
            var sequentialGuidIdentityGenerator = new GuidValueGenerator();

            var values = new HashSet <Guid>();

            for (var i = 0; i < 100; i++)
            {
                var guid = async
                    ? await sequentialGuidIdentityGenerator.NextAsync(Mock.Of <StateEntry>(), Mock.Of <IProperty>())
                    : sequentialGuidIdentityGenerator.Next(Mock.Of <StateEntry>(), Mock.Of <IProperty>());

                values.Add((Guid)guid);
            }

            Assert.Equal(100, values.Count);
        }
コード例 #9
0
        public async Task Creates_GUIDs_test(bool async)
        {
            var sequentialGuidIdentityGenerator = new GuidValueGenerator();

            var stateEntry = TestHelpers.CreateStateEntry <WithGuid>(_model);
            var property   = stateEntry.EntityType.GetProperty("Id");

            var values = new HashSet <Guid>();

            for (var i = 0; i < 100; i++)
            {
                var generatedValue = async
                    ? await sequentialGuidIdentityGenerator.NextAsync(property, new DbContextService <DataStoreServices>(() => null))
                    : sequentialGuidIdentityGenerator.Next(property, new DbContextService <DataStoreServices>(() => null));

                values.Add((Guid)generatedValue);
            }

            Assert.Equal(100, values.Count);
        }
コード例 #10
0
        public void IsSupportedThrowsExceptionWithNullTypeTest()
        {
            var buildChain = new LinkedList<object>();

            buildChain.AddFirst(Guid.NewGuid().ToString());

            var target = new GuidValueGenerator();

            Action action = () => target.IsSupported(null, Guid.NewGuid().ToString(), buildChain);

            action.ShouldThrow<ArgumentNullException>();
        }