Esempio n. 1
0
        public void KnowConfigureInjection()
        {
            var modelMapper = new ConventionModelMapper();

            var configurator = modelMapper.InjectionConfigurator <Foo>()
                               .FillProperty(p => p.PropertyString, () => "lorem")
                               .FillProperty(p => p.PropertyDouble, () => 1);

            modelMapper.GetInjector <Foo>().Should().Be(configurator);
        }
Esempio n. 2
0
        public void KnowConfigureInjectionExternal()
        {
            var modelMapper  = new ConventionModelMapper();
            var configurator = new InjectionConfiguration <Foo>()
                               .FillProperty(p => p.PropertyDouble, () => 1);

            ((IModelMapperInternal)modelMapper).SetInjector <Foo>((IInjector)configurator);

            modelMapper.GetInjector <Foo>().Should().Be(configurator);
        }
Esempio n. 3
0
        public void BuildConfiguration()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest")
            .HasPrimaryKey(f => f.Id).AutoIncrement(AutoIncrementMethodType.Custom)
            .Property(p => p.Address)
            .HasColumnName("COL_ADDRESS")
            .UseConverter <AddressConverter>()
            .Property(p => p.NoMapped).NoMap()
            .Property(p => p.FirstName).HasColumnName("Name")
            .Property(p => p.DateTime).InjectValue(() => DateTime.Now)
            .Property(p => p.GeneratedValue).UseValueGeneratorOnInsert <AutoIncrementValueGenerator>();

            modelBuilder.Build(modelMapper);

            TableInfo tableInfo = modelMapper.GetTableInfo <BuilderTestEntity>();

            var columns = new List <ColumnInfo>()
            {
                new ColumnInfo()
                {
                    Name                    = "Id",
                    IsPrimaryKey            = true,
                    AutoIncrementMethodType = AutoIncrementMethodType.Custom
                },
                new ColumnInfo()
                {
                    Name = "COL_ADDRESS", Converter = new AddressConverter()
                },
                new ColumnInfo()
                {
                    Name = "Name"
                },
                new ColumnInfo()
                {
                    Name = "GeneratedValue", ValueGenerator = new AutoIncrementValueGenerator()
                }
            };
            TableInfo tableInfoExpected = CreateExpectedTableInfo(columns, "BuilderTest");

            AreSame(tableInfo, tableInfoExpected);
            modelMapper.GetInjector <BuilderTestEntity>().IsInjectable("DateTime")
            .Should()
            .BeTrue("DateTime property has injector.");
        }
Esempio n. 4
0
        public void DontThrowExceptionIfInjectionIsNotConfigured()
        {
            var modelMapper = new ConventionModelMapper();

            modelMapper.GetInjector <Foo>().Should().NotBeNull();
        }