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)}\"."); }
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."); }
public void HaveOnAfterMaterializeMethodInfo() { var modelMapper = new ConventionModelMapper(); TableInfo tableInfo = modelMapper.GetTableInfo <AliasedModel>(); tableInfo.OnAfterMaterialize.Name.Should().Be("OnAfterMaterialize"); }
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."); }
public void UseConventionForGettingTableNameWhenAliasDoesNotExist() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.Name.Should().Be("Foo"); }
public void GetTableInfoWithAutoIncrementKey() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <FooWithAutoIncrement>(); tableInfo.PrimaryKey.Single().AutoIncrementMethodType.Should().Be(AutoIncrementMethodType.Custom); }
public void GetTableInfoWithoutNoMapAttribute() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.GetColumnInfo("Ignore").Should().BeNull(); }
public void GetTableInfoWithoutReadOnlyProperty() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.GetColumnInfo("ReadOnlyProperty").Should().BeNull(); }
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); }
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>(); }
public void UseSetsTableName() { var modelMapper = new ConventionModelMapper(); (modelMapper as IModelMapperInternal).SetTableName <Foo>("Foo2"); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.Name.Should().Be("Foo2"); }
public void GetTableInfoWithoutNoMap() { var modelMapper = new ConventionModelMapper(); ((IModelMapperInternal)modelMapper).SetNoMap <Foo>("LastName"); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.GetColumnInfo("LastName").Should().BeNull(); }
public void GetTableInfoWithColumnConverter() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <Foo>(); var columns = tableInfo.Columns.ToList(); columns[5].Converter.Should().BeOfType <TestConverter>(); }
public void GetTableInfoWithoutAutoIncrementKey() { var modelMapper = new ConventionModelMapper(); var tableInfo = modelMapper.GetTableInfo <Foo>(); tableInfo.PrimaryKey .Any(p => p.AutoIncrementMethodType != AutoIncrementMethodType.None) .Should().BeFalse(); }
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."); }
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>(); }
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(); }
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(); }
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"); }
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); }
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); }
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); }
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"); }
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>(); }
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(); }
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"); }
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."); }
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(); }