Beispiel #1
0
        public void ThrowIfCompositePrimaryKeyHasColumnsWithInvalidAutoIncrementMethodType()
        {
            var    modelMapper     = new ConventionModelMapper();
            Action tableInfoAction = () => modelMapper.GetTableInfo <CompositePrivateKeyWithInvalidAutoIncrementMethodType>();

            tableInfoAction.Should().Throw <CompositePrimaryKeyException>(
                $"All columns of the composite primary key must have \"{nameof(KeyAttribute.AutoIncrementMethodType)}\" set to \"{nameof(AutoIncrementMethodType.None)}\".");
        }
Beispiel #2
0
        public void ThrowIfCompositePrimaryKeyHasColumnsWithInvalidName()
        {
            var    modelMapper     = new ConventionModelMapper();
            Action tableInfoAction = () => modelMapper.GetTableInfo <CompositePrivateKeyWithInvalidName>();

            tableInfoAction.Should().Throw <CompositePrimaryKeyException>(
                "If composite primary key has specified name, this name must be the same for all the columns.");
        }
Beispiel #3
0
        public void HaveOnAfterMaterializeMethodInfo()
        {
            var modelMapper = new ConventionModelMapper();

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

            tableInfo.OnAfterMaterialize.Name.Should().Be("OnAfterMaterialize");
        }
Beispiel #4
0
        public void ThrowIfCompositePrimaryKeyHasColumnsWithInvalidOrder()
        {
            var    modelMapper     = new ConventionModelMapper();
            Action tableInfoAction = () => modelMapper.GetTableInfo <CompositePrivateKeyWithInvalidOrder>();

            tableInfoAction.Should().Throw <CompositePrimaryKeyException>(
                "Composite primary key columns must have specified order and this order must be unique for every column.");
        }
Beispiel #5
0
        public void UseConventionForGettingTableNameWhenAliasDoesNotExist()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.Name.Should().Be("Foo");
        }
Beispiel #6
0
        public void GetTableInfoWithAutoIncrementKey()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <FooWithAutoIncrement>();

            tableInfo.PrimaryKey.Single().AutoIncrementMethodType.Should().Be(AutoIncrementMethodType.Custom);
        }
Beispiel #7
0
        public void GetTableInfoWithoutNoMapAttribute()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.GetColumnInfo("Ignore").Should().BeNull();
        }
Beispiel #8
0
        public void GetTableInfoWithoutReadOnlyProperty()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.GetColumnInfo("ReadOnlyProperty").Should().BeNull();
        }
Beispiel #9
0
        public void GetTableInfoWithoutPrimarKey()
        {
            var modelMapper = new ConventionModelMapper();
            var tableInfo   = modelMapper.GetTableInfo <NoPrivateKeyModel>();

            tableInfo.Columns.Should().HaveCount(2);
            tableInfo.Columns.Count(c => c.IsPrimaryKey).Should().Be(0);
            tableInfo.PrimaryKey.Should().HaveCount(0);
        }
Beispiel #10
0
        public void GetTableInfoWithColumnConverter()
        {
            var modelMapper = new ConventionModelMapper();
            var tableInfo   = modelMapper.GetTableInfo <Foo>();

            var columnWithConverter = tableInfo.Columns.Single(c => c.Name == "PropertyEnum");

            columnWithConverter.Converter.Should().BeOfType <TestConverter>();
        }
Beispiel #11
0
        public void UseSetsTableName()
        {
            var modelMapper = new ConventionModelMapper();

            (modelMapper as IModelMapperInternal).SetTableName <Foo>("Foo2");

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.Name.Should().Be("Foo2");
        }
Beispiel #12
0
        public void GetTableInfoWithoutNoMap()
        {
            var modelMapper = new ConventionModelMapper();

            ((IModelMapperInternal)modelMapper).SetNoMap <Foo>("LastName");

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.GetColumnInfo("LastName").Should().BeNull();
        }
Beispiel #13
0
        public void GetTableInfoWithColumnConverter()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = tableInfo.Columns.ToList();

            columns[5].Converter.Should().BeOfType <TestConverter>();
        }
Beispiel #14
0
        public void GetTableInfoWithoutAutoIncrementKey()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            tableInfo.PrimaryKey
            .Any(p => p.AutoIncrementMethodType != AutoIncrementMethodType.None)
            .Should().BeFalse();
        }
Beispiel #15
0
        public void UseAliasAttributeForGettingNames()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = tableInfo.Columns.ToList();

            columns[1].Name.Should().Be("PostCode", "Becouse have alias.");
            columns[2].Name.Should().Be("FirstName", "Becouse have alias.");
        }
Beispiel #16
0
        public void GetTableInfoWithColumnConverterSetByConfiguration()
        {
            var modelMapper = new ConventionModelMapper();

            ((IModelMapperInternal)modelMapper).SetConverter <Foo>("LastName", new TestConverter());
            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var columnWithConverter = tableInfo.Columns.Single(c => c.Name == "LastName");

            columnWithConverter.Converter.Should().BeOfType <TestConverter>();
        }
Beispiel #17
0
        public void GetTableInfoWithPrimaryKeyByConvention()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo1>();

            var key = tableInfo.PrimaryKey.ToList();

            key.Should().HaveCount(1, "Becouse Foo1 dont have key attribute, but have one property which match Id convention");
            key[0].Name.Should().Be("Id");
            key[0].IsPrimaryKey.Should().BeTrue();
        }
Beispiel #18
0
        public void GetTableInfoWithoutPrimarKeyWhenDontHaveKeyAttributeAndNoConventionMatch()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo2>();

            var  key    = tableInfo.PrimaryKey.ToList();
            bool anyKey = key.Any(p => p.IsPrimaryKey);

            key.Should().HaveCount(0);
            anyKey.Should().BeFalse();
        }
Beispiel #19
0
        public void UseConventionForGettingNamesWhenAliasDoesNotExist()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var columns = tableInfo.Columns.ToList();

            columns[0].Name.Should().Be("Id");
            columns[3].Name.Should().Be("LastName");
            columns[4].Name.Should().Be("PropertyDouble");
        }
Beispiel #20
0
        public void GetTableInfoWithPrimaryKeyFluentDefinition()
        {
            var modelMapper = new ConventionModelMapper();

            ((IModelMapperInternal)modelMapper).SetPrimaryKey <FluentPrivateKey>("RecordId", AutoIncrementMethodType.Identity);

            var tableInfo = modelMapper.GetTableInfo <FluentPrivateKey>();

            tableInfo.PrimaryKey
            .Should()
            .HaveCount(1)
            .And
            .ContainSingle((c) => c.Name == "RecordId" && c.AutoIncrementMethodType == AutoIncrementMethodType.Identity);
        }
Beispiel #21
0
        public void GetTableInfoWithPrimaryKey()
        {
            var modelMapper = new ConventionModelMapper();

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var key = tableInfo.PrimaryKey.ToList();

            key.Should().HaveCount(2, "Becouse class Foo have to property with Key attribute");
            key[0].Name.Should().Be("Id");
            key[0].IsPrimaryKey.Should().BeTrue();
            key[1].Name.Should().Be("PostCode");
            key[1].IsPrimaryKey.Should().BeTrue();
        }
        public void UseEmptyQuota()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest");

            modelBuilder.Build(modelMapper);

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

            tableInfo.Delimiters.Should().Be(Delimiters.Empty);
        }
Beispiel #23
0
        public void UseNamesFromConfigurationMap()
        {
            var modelMapper = new ConventionModelMapper();

            modelMapper.SetColumnName <Foo, string>(p => p.PropertyString, "Address");
            modelMapper.SetColumnName <Foo, double>(p => p.PropertyDouble, "Salary");

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var address = tableInfo.GetColumnInfoByPropertyName(nameof(Foo.PropertyString));
            var salary  = tableInfo.GetColumnInfoByPropertyName(nameof(Foo.PropertyDouble));

            address.Name.Should().Be("Address");
            salary.Name.Should().Be("Salary");
        }
        public void SetNamingQuota()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.UseIdentifierDelimiters(Delimiters.SquareBrackets);
            modelBuilder.Entity <BuilderTestEntity>()
            .HasTableName("BuilderTest");

            modelBuilder.Build(modelMapper);

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

            tableInfo.Delimiters.Should().Be(Delimiters.SquareBrackets);
        }
Beispiel #25
0
        public void ReturnColumnsWithCorrectNames()
        {
            var modelMapper = new ConventionModelMapper();
            var tableInfo   = modelMapper.GetTableInfo <Foo>();

            var columns = tableInfo.Columns.ToList();

            columns.Count.Should().Be(6);
            columns[0].Name.Should().Be("PostCode", "Property \"Code\" has alias \"PostCode\".");
            columns[1].Name.Should().Be("FirstName", "Property \"PropertyString\" has alias \"FirstName\".");
            columns[2].Name.Should().Be("LastName");
            columns[3].Name.Should().Be("PropertyDouble");
            columns[4].Name.Should().Be("PropertyEnum");
            columns[5].Name.Should().Be("DataTypeProperty");
        }
Beispiel #26
0
        public void UseCurrentTimeGeneratorOnInsert()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <BuilderTestEntity>()
            .Property(p => p.GeneratedValue).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert);

            modelBuilder.Build(modelMapper);

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

            tableInfo.GetColumnInfoByPropertyName("GeneratedValue").ValueGenerated.Should().Be(ValueGenerated.OnInsert);
            tableInfo.GetColumnInfoByPropertyName("GeneratedValue").ValueGenerator.Should().BeOfType <CurrentTimeValueGenerator>();
        }
Beispiel #27
0
        public void DoNotReturnQueryFilterIfWasNotConfigured()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <FooQueryFilter>()
            .HasTableName("Foo");

            modelBuilder.Build(modelMapper);

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

            tableInfo.QueryFilter
            .Should().BeNull();
        }
Beispiel #28
0
        public void UseNamesFromConfigurationMapWhenPropertyNameIsUsed()
        {
            var modelMapper = new ConventionModelMapper();

            ((IModelMapperInternal)modelMapper).SetColumnName <Foo>("PropertyString", "Address");
            ((IModelMapperInternal)modelMapper).SetColumnName <Foo>("PropertyDouble", "Salary");

            var tableInfo = modelMapper.GetTableInfo <Foo>();

            var address = tableInfo.GetColumnInfoByPropertyName(nameof(Foo.PropertyString));
            var salary  = tableInfo.GetColumnInfoByPropertyName(nameof(Foo.PropertyDouble));

            address.Name.Should().Be("Address");
            salary.Name.Should().Be("Salary");
        }
Beispiel #29
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.");
        }
Beispiel #30
0
        public void UseQueryFilter()
        {
            var modelBuilder = new ModelConfigurationBuilder();
            var modelMapper  = new ConventionModelMapper();

            modelBuilder.Entity <FooQueryFilter>()
            .HasTableName("Foo");

            modelBuilder.Table("Foo")
            .UseQueryFilter <FooQueryFilter>(f => f.AutorId == 5);

            modelBuilder.Build(modelMapper);

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

            tableInfo.QueryFilter
            .Should().NotBeNull();
        }