コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }