public void ShouldUseTheModelNameAsTableNameByDefault() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>(); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); Assert.Equal("PersonModel", tableConfiguration.TableName); }
public void ShouldBeAbleToCreateADublicateConfiguration() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>(); configuration.Configure<PersonModel>(); //Assert var numberOfConfigurations = configuration.TableConfigurations.Count; Assert.Equal(1, numberOfConfigurations); }
public void ShouldBeAbleToRegisterACstomTableName() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>() .WithTableName("Persons"); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); Assert.Equal("Persons", tableConfiguration.TableName); }
public void ShouldBeAbleToSetASinglePrimary() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>() .WithKey(x => new { x.Id }); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); Assert.Equal(1, tableConfiguration.PrimaryKeys.Count()); Assert.Equal("Id", tableConfiguration.PrimaryKeys.First().Name); }
public void ShouldBeAbleToMapAPropertyWithADefaultValue() { const string defaultValue = "Oliver"; //Arrange var context = new EmptyDbContext(); var configuration = new EasyConfiguration(context); //Act configuration.Configure<PersonModel>() .Map(x => x.FirstName, defaultValue: defaultValue); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); var fields = tableConfiguration.Fields; var fieldConfiguraton = fields.GetByProperty<PersonModel, String>(x => x.FirstName); Assert.Equal(defaultValue, fieldConfiguraton.DefaultValue); }
public void ShouldBeAbleToMapAPropertyuWithSpecficLength() { const int fieldLength = 200; //Arrange var context = new EmptyDbContext(); var configuration = new EasyConfiguration(context); //Act configuration.Configure<PersonModel>() .Map(x => x.FirstName, length: fieldLength); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); var fields = tableConfiguration.Fields; var fieldConfiguraton = fields.GetByProperty<PersonModel, String>(x => x.FirstName); Assert.Equal(fieldLength, fieldConfiguraton.Length); }
public void ShouldBeAbleToSetMultiplePrimaryKeys() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>() .WithKey(x => new { x.FirstName, x.LastName }); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); Assert.Equal(2, tableConfiguration.PrimaryKeys.Count()); Assert.True(tableConfiguration.PrimaryKeys.Any(x => x.Name == "FirstName")); Assert.True(tableConfiguration.PrimaryKeys.Any(x => x.Name == "LastName")); }
public void ShouldBeAbleToMapAProperty() { //Arrange var context = new EmptyDbContext(); var configuration = new EasyConfiguration(context); var expectedType = new NVarCharFieldType(); //Act configuration.Configure<PersonModel>() .Map(x => x.FirstName); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); var fields = tableConfiguration.Fields; var fieldConfiguraton = fields.GetByProperty<PersonModel, String>(x => x.FirstName); Assert.Equal(1, fields.Count); Assert.NotNull(fieldConfiguraton); Assert.Equal("FirstName", fieldConfiguraton.FieldName); Assert.Null(fieldConfiguraton.DefaultValue); //FieldType validation Assert.Equal(expectedType.Name, fieldConfiguraton.FieldType.Name); Assert.Equal(expectedType.DefaultLength, fieldConfiguraton.FieldType.DefaultLength); }
public void ShouldSetADefaultEmptyListForFields() { //Arrange var contextMock = new Mock<IEasyContext>(); var configuration = new EasyConfiguration(contextMock.Object); //Act configuration.Configure<PersonModel>(); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); Assert.NotNull(tableConfiguration.Fields); Assert.IsType(typeof(List<EasyTableFieldConfiguration>), tableConfiguration.Fields); Assert.Equal(0, tableConfiguration.Fields.Count); }
public void ShouldBeAbleToMapAPropertyWithCustomFieldName() { const string fieldName = "Fornavn"; //Arrange var context = new EmptyDbContext(); var configuration = new EasyConfiguration(context); //Act configuration.Configure<PersonModel>() .Map(x => x.FirstName, field: fieldName); //Assert var tableConfiguration = configuration.TableConfigurations.FindByType<PersonModel>(); var fields = tableConfiguration.Fields; var fieldConfiguraton = fields.GetByProperty<PersonModel, String>(x => x.FirstName); Assert.Equal(fieldName, fieldConfiguraton.FieldName); }