public void should_create_parameters_for_any_parameters_found_in_the_command_text_with_matching_properties_in_the_object()
        {
            // Arrange
            var task = TaskFactory<BuildParametersUsing<MockObject>>.Create();

            var mockDbCommand = new Mock<IDbCommand> { DefaultValue = DefaultValue.Mock };
            var mockDbDataParameter = new Mock<IDbDataParameter>();
            mockDbCommand.Setup(dbCommand => dbCommand.CreateParameter()).Returns(mockDbDataParameter.Object);
            mockDbCommand.Setup(dbCommand => dbCommand.CommandText).Returns("select blah");
            task.CommandWithParameters = mockDbCommand.Object;

            var mockObject = new MockObject { Name = "John Doe", Age = 21 };
            task.ObjectWithValues = mockObject;

            var mockFindParameters = new Mock<FindParametersInCommandText>();
            mockFindParameters.Setup(findParams => findParams.ParameterNames).Returns(new string[] { "@Age" });
            task.FindParametersInCommandText = mockFindParameters.Object;

            // Act
            task.Execute();

            // Assert
            mockDbDataParameter.VerifySet(param => param.ParameterName = "@Age");
            mockDbDataParameter.VerifySet(param => param.Value = 21);
            mockDbCommand.Verify(dbCommand => dbCommand.Parameters.Add(mockDbDataParameter.Object), Times.Once());
        }
        public void should_set_parameter_to_dbnull_if_value_found_in_the_matching_property_of_the_object_is_null()
        {
            // Arrange
            var task = TaskFactory<BuildParametersUsing<MockObject>>.Create();

            var mockDbCommand = new Mock<IDbCommand> { DefaultValue = DefaultValue.Mock };
            var mockDbDataParameter = new Mock<IDbDataParameter>();
            mockDbCommand.Setup(dbCommand => dbCommand.CreateParameter()).Returns(mockDbDataParameter.Object);
            mockDbCommand.Setup(dbCommand => dbCommand.CommandText).Returns("select blah");
            task.CommandWithParameters = mockDbCommand.Object;

            var mockObject = new MockObject { Age = null };
            task.ObjectWithValues = mockObject;

            var mockFindParameters = new Mock<FindParametersInCommandText>();
            mockFindParameters.Setup(findParams => findParams.ParameterNames).Returns(new string[] { "@Age" });
            task.FindParametersInCommandText = mockFindParameters.Object;

            // Act
            task.Execute();

            // Assert
            mockDbDataParameter.VerifySet(parameter => parameter.ParameterName = "@Age");
            mockDbDataParameter.VerifySet(parameter => parameter.Value = DBNull.Value);
            mockDbCommand.Verify(dbCommand => dbCommand.Parameters.Add(mockDbDataParameter.Object), Times.Once());
        }
        public void should_call_command_to_persist_the_object()
        {
            // Arrange
            var task = TaskFactory<PersistSingleOf<MockObject>>.Create();

            var mockBuildParameters = new Mock<BuildParametersUsing<MockObject>>();
            task.BuildParameters = mockBuildParameters.Object;

            var mockObject = new MockObject();
            task.ObjectToPersist = mockObject;

            var mockPersistCommand = new Mock<IDbCommand>();
            mockPersistCommand.Setup(command => command.ExecuteNonQuery()).Returns(1);
            task.PersistCommand = mockPersistCommand.Object;

            // Act
            task.Execute();

            // Assert
            mockBuildParameters.VerifySet(buildParams => buildParams.CommandWithParameters = mockPersistCommand.Object);
            mockBuildParameters.VerifySet(buildParams => buildParams.ObjectWithValues = mockObject);
            mockPersistCommand.Verify(buildParams => buildParams.ExecuteNonQuery(), Times.Once());
        }