public void Throws_when_type_conversion_would_overflow()
        {
            var generator = new TemporaryValueGenerator();

            var stateEntry   = TestHelpers.CreateStateEntry <AnEntity>(_model);
            var byteProperty = stateEntry.EntityType.GetProperty("Byte");

            Assert.Throws <OverflowException>(() => generator.Next(stateEntry, byteProperty));
        }
示例#2
0
        public void Throws_when_type_conversion_would_overflow()
        {
            var entityType = _model.GetEntityType(typeof(AnEntity));

            var generator = new TemporaryValueGenerator();

            Assert.Throws <OverflowException>(() => generator.Next(entityType.GetProperty("Byte")));
            Assert.Throws <OverflowException>(() => generator.Next(entityType.GetProperty("NullableByte")));
        }
示例#3
0
        public async Task Can_create_values_for_all_integer_types_except_byte()
        {
            var generator = new TemporaryValueGenerator();

            Assert.Equal(-1L, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(long))));
            Assert.Equal(-2, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(int))));
            Assert.Equal((short)-3, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(short))));

            Assert.Equal(-4L, generator.Next(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(long))));
            Assert.Equal(-5, generator.Next(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(int))));
            Assert.Equal((short)-6, generator.Next(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(short))));
        }
示例#4
0
        public async Task Creates_negative_values()
        {
            var generator = new TemporaryValueGenerator();

            var property = CreateProperty(typeof(int));

            Assert.Equal(-1, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), property));
            Assert.Equal(-2, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), property));
            Assert.Equal(-3, await generator.NextAsync(Mock.Of <DbContextConfiguration>(), property));

            Assert.Equal(-4, generator.Next(Mock.Of <DbContextConfiguration>(), property));
            Assert.Equal(-5, generator.Next(Mock.Of <DbContextConfiguration>(), property));
            Assert.Equal(-6, generator.Next(Mock.Of <DbContextConfiguration>(), property));
        }
        public async Task Can_create_values_for_all_integer_types_except_byte()
        {
            var generator = new TemporaryValueGenerator();

            var stateEntry    = TestHelpers.CreateStateEntry <AnEntity>(_model);
            var intProperty   = stateEntry.EntityType.GetProperty("Id");
            var longProperty  = stateEntry.EntityType.GetProperty("Long");
            var shortProperty = stateEntry.EntityType.GetProperty("Short");

            await generator.NextAsync(stateEntry, longProperty);

            Assert.Equal(-1L, stateEntry[longProperty]);
            Assert.True(stateEntry.HasTemporaryValue(longProperty));

            await generator.NextAsync(stateEntry, intProperty);

            Assert.Equal(-2, stateEntry[intProperty]);
            Assert.True(stateEntry.HasTemporaryValue(intProperty));

            await generator.NextAsync(stateEntry, shortProperty);

            Assert.Equal((short)-3, stateEntry[shortProperty]);
            Assert.True(stateEntry.HasTemporaryValue(shortProperty));

            generator.Next(stateEntry, longProperty);

            Assert.Equal(-4L, stateEntry[longProperty]);
            Assert.True(stateEntry.HasTemporaryValue(longProperty));

            generator.Next(stateEntry, intProperty);

            Assert.Equal(-5, stateEntry[intProperty]);
            Assert.True(stateEntry.HasTemporaryValue(intProperty));

            generator.Next(stateEntry, shortProperty);

            Assert.Equal((short)-6, stateEntry[shortProperty]);
            Assert.True(stateEntry.HasTemporaryValue(shortProperty));
        }
        public async Task Creates_negative_values()
        {
            var generator = new TemporaryValueGenerator();

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

            await generator.NextAsync(stateEntry, property);

            Assert.Equal(-1, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));

            await generator.NextAsync(stateEntry, property);

            Assert.Equal(-2, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));

            await generator.NextAsync(stateEntry, property);

            Assert.Equal(-3, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));

            generator.Next(stateEntry, property);

            Assert.Equal(-4, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));

            generator.Next(stateEntry, property);

            Assert.Equal(-5, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));

            generator.Next(stateEntry, property);

            Assert.Equal(-6, stateEntry[property]);
            Assert.True(stateEntry.HasTemporaryValue(property));
        }
示例#7
0
        public async Task Creates_negative_values()
        {
            var property = _model.GetEntityType(typeof(AnEntity)).GetProperty("Id");

            var generator = new TemporaryValueGenerator();

            var generatedValue = await generator.NextAsync(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-1, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-2, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-3, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-4, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-5, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(property, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-6, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);
        }
示例#8
0
        public async Task Can_create_values_for_all_integer_types_except_byte()
        {
            var entityType = _model.GetEntityType(typeof(AnEntity));

            var intProperty           = entityType.GetProperty("Id");
            var longProperty          = entityType.GetProperty("Long");
            var shortProperty         = entityType.GetProperty("Short");
            var nullableIntProperty   = entityType.GetProperty("NullableId");
            var nullableLongProperty  = entityType.GetProperty("NullableLong");
            var nullableShortProperty = entityType.GetProperty("NullableShort");

            var generator = new TemporaryValueGenerator();

            var generatedValue = await generator.NextAsync(longProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-1L, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(intProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-2, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(shortProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal((short)-3, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(longProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-4L, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(intProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-5, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(shortProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal((short)-6, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(nullableLongProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-7L, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(nullableIntProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-8, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = await generator.NextAsync(nullableShortProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal((short)-9, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(nullableLongProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-10L, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(nullableIntProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal(-11, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);

            generatedValue = generator.Next(nullableShortProperty, new DbContextService <DataStoreServices>(() => null));

            Assert.Equal((short)-12, generatedValue.Value);
            Assert.True(generatedValue.IsTemporary);
        }
示例#9
0
        public void Throws_when_type_conversion_would_overflow()
        {
            var generator = new TemporaryValueGenerator();

            Assert.Throws <OverflowException>(() => generator.Next(Mock.Of <DbContextConfiguration>(), CreateProperty(typeof(byte))));
        }