public void should_create_parameters_for_any_parameters_found_in_the_command_text_with_matching_properties_in_the_static_object() { // Arrange var task = SimpleTask.New<BuildParameters>(); 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("doesnt matter"); task.In.Command = mockDbCommand.Object; var mockObject = new MockObject { Name = "John Doe", Age = 21 }; task.In.Values = mockObject; task.FindParameters = Fake.Task<FindParameters>(j => j.Out.ParameterNames = new[] { "@Age" }); // 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_static_object_is_null() { // Arrange var task = SimpleTask.New<BuildParameters>(); 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("doesnt matter"); task.In.Command = mockDbCommand.Object; var mockObject = new MockObject {Age = null}; task.In.Values = mockObject; task.FindParameters = Fake.Task<FindParameters>(j => j.Out.ParameterNames = new[] { "@Age" }); // 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()); }