public void TestPropertyHandlerPrecedenceOnQueryFieldsExpression()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerTestClassForQueryFields>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Query <PropertyHandlerTestClassForQueryFields>((new QueryField("Id", 1)).AsEnumerable());
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Once);
        }
        public void TestPropertyHandlerWithAttributePrecedenceOnQueryGroupExpression()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerTestClassWithAttributeForQueryGroup>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Query <PropertyHandlerTestClassWithAttributeForQueryGroup>(new QueryGroup(new QueryField("Id", 1)));
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Never);
        }
        public void TestPropertyHandlerPrecedenceOnDynamicExpression()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerTestClassForDynamic>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Query <PropertyHandlerTestClassForDynamic>(new { Id = 1 });
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Once);
        }
        public void TestPropertyHandlerWithAttributePrecedenceOnLinqExpression()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerTestClassWithAttributeForLinq>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Query((Expression <Func <PropertyHandlerTestClassWithAttributeForLinq, bool> >)(e => e.Id == 1));
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Never);
        }
示例#5
0
        public void TestPropertyHandlerInvocationOnPrimaryKey()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerTestClassForPrimaryKey>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Query <PropertyHandlerTestClassForPrimaryKey>(1);
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Once);
        }
        public void TestPropertyHandlerGetInvocation()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <int, int> >();

            FluentMapper
            .Entity <PropertyHandlerQueryTestClass>()
            .PropertyHandler(e => e.Id, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                var result = connection.QueryAll <PropertyHandlerQueryTestClass>();
            }

            // Assert
            propertyHandler.Verify(c => c.Get(It.IsAny <int>(), It.IsAny <ClassProperty>()), Times.Once);
        }
        public void TestDbCommandCreateParametersPropertyHandlerTypeLevelInvocationViaQueryGroup()
        {
            // Arrange
            var param = new QueryGroup(new QueryField("Id", Guid.Parse("9963c864-ab4f-43f8-9dc9-43038565b971")));

            FluentMapper
            .Type <Guid>()
            .PropertyHandler <StringToGuidPropertyHandler>();

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CreateParameters(param);

                    // Assert
                    Assert.AreEqual(1, cmd.Parameters.Count);
                    Assert.AreEqual("9963c864-ab4f-43f8-9dc9-43038565b971", cmd.Parameters[0].Value);
                }
            }
        }
        public void TestPropertyHandlerSetInvocation()
        {
            // Prepare
            var propertyHandler = new Mock <IPropertyHandler <string, string> >();

            FluentMapper
            .Entity <PropertyHandlerInsertTestClass>()
            .PropertyHandler(e => e.Name, propertyHandler.Object);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                connection.Insert <PropertyHandlerInsertTestClass>(new PropertyHandlerInsertTestClass
                {
                    Id   = 1,
                    Name = "James Smith"
                });
            }

            // Assert
            propertyHandler.Verify(c => c.Set(It.IsAny <string>(), It.IsAny <ClassProperty>()), Times.Once);
        }
        public void TestDbCommandCreateParametersPropertyHandlerPropertyLevelInvocationViaClass()
        {
            // Arrange
            var param = new TestClass {
                Id = Guid.Parse("9963c864-ab4f-43f8-9dc9-43038565b971")
            };

            FluentMapper
            .Entity <TestClass>()
            .PropertyHandler <StringToGuidPropertyHandler>(e => e.Id);

            // Act
            using (var connection = new PropertyHandlerConnection())
            {
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CreateParameters(param);

                    // Assert
                    Assert.AreEqual(1, cmd.Parameters.Count);
                    Assert.AreEqual("9963c864-ab4f-43f8-9dc9-43038565b971", cmd.Parameters[0].Value);
                }
            }
        }