예제 #1
0
        public void Returns_null_when_no_value_generation_not_required()
        {
            var selector = new ValueGeneratorSelector(new SimpleValueGeneratorFactory <GuidValueGenerator>());

            Assert.Null(selector.Select(CreateProperty(typeof(int), ValueGeneration.None)));
            Assert.Null(selector.Select(CreateProperty(typeof(int), ValueGeneration.OnAddAndUpdate)));
        }
예제 #2
0
        public void Returns_in_memory_GUID_generator_for_GUID_types_setup_for_value_generation()
        {
            var guidFactory = new SimpleValueGeneratorFactory <GuidValueGenerator>();

            var selector = new ValueGeneratorSelector(guidFactory);

            Assert.Same(guidFactory, selector.Select(CreateProperty(typeof(Guid), ValueGeneration.OnAdd)));
        }
예제 #3
0
        public void Throws_for_unsupported_combinations()
        {
            var selector = new ValueGeneratorSelector(
                new SimpleValueGeneratorFactory <GuidValueGenerator>());

            var typeMock = new Mock <IEntityType>();

            typeMock.Setup(m => m.Name).Returns("AnEntity");

            var property = CreateProperty(typeof(Random), ValueGeneration.OnAdd);

            Assert.Equal(
                Strings.FormatNoValueGenerator("MyProperty", "MyType", "Random"),
                Assert.Throws <NotSupportedException>(() => selector.Select(property)).Message);
        }
예제 #4
0
        public void Returns_built_in_generators_for_types_setup_for_value_generation()
        {
            var model      = BuildModel();
            var entityType = model.FindEntityType(typeof(AnEntity));

            var selector = new ValueGeneratorSelector(new ValueGeneratorSelectorDependencies(new ValueGeneratorCache(new ValueGeneratorCacheDependencies())));

            Assert.IsType <CustomValueGenerator>(selector.Select(entityType.FindProperty("Custom"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Id"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Long"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Short"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Byte"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableInt"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableLong"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableShort"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableByte"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("UInt"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("ULong"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("UShort"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("SByte"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableUInt"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableULong"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableUShort"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableSByte"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Decimal"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableDecimal"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Float"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableFloat"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("Double"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableDouble"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("DateTime"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableDateTime"), entityType));

            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("DateTimeOffset"), entityType));
            Assert.Throws <NotSupportedException>(() => selector.Select(entityType.FindProperty("NullableDateTimeOffset"), entityType));

            Assert.IsType <StringValueGenerator>(selector.Select(entityType.FindProperty("String"), entityType));

            Assert.IsType <GuidValueGenerator>(selector.Select(entityType.FindProperty("Guid"), entityType));
            Assert.IsType <GuidValueGenerator>(selector.Select(entityType.FindProperty("NullableGuid"), entityType));

            Assert.IsType <BinaryValueGenerator>(selector.Select(entityType.FindProperty("Binary"), entityType));
        }