public void Create_CommandParameterProviderThrowsException_ExceptionIsPropogated() { var person = Person.Faker.Generate(1).Single(); var record = new { person.FirstName, person.LastName, person.MiddleInitial, person.Age, person.DateOfBirth, person.Gender }; var staticCommandParameters = DatabaseWriterCommandFactoryTests.CreateStaticParameters(record); var commandParameterProvider = MockRepository.GenerateMock <IDatabaseWriterCommandParameterProvider>(); commandParameterProvider.Stub(x => x.GetParameters(Arg <object> .Is.Equal(record))).Throw(new InternalTestFailureException()); var databaseWriterCommandFactory = new DatabaseWriterCommandFactory(commandParameterProvider) { CommandText = "dbo.InsertPerson", CommandType = CommandType.StoredProcedure, CommandTimeout = TimeSpan.FromMinutes(2) }; databaseWriterCommandFactory.Create(record); }
public void Create_StaticCommandParameters_CommandIsCreatedWithStaticParameters() { var person = Person.Faker.Generate(1).Single(); var record = new { person.FirstName, person.LastName, person.MiddleInitial, person.Age, person.DateOfBirth, person.Gender }; var commandType = CommandType.StoredProcedure; var commandText = "dbo.InsertPerson"; var staticCommandParameters = DatabaseWriterCommandFactoryTests.CreateStaticParameters(record); var databaseWriterCommandFactory = new DatabaseWriterCommandFactory(staticCommandParameters, commandType, commandText); using (var command = databaseWriterCommandFactory.Create(record)) { Assert.AreEqual(databaseWriterCommandFactory.CommandText, command.CommandText); Assert.AreEqual(databaseWriterCommandFactory.CommandType, command.CommandType); Assert.AreEqual(databaseWriterCommandFactory.CommandTimeout, TimeSpan.FromMilliseconds(command.CommandTimeout)); DatabaseWriterCommandFactoryTests.AssertCommandParametersAreCreatedAsExpected(command, record); } }
public void Create_CustomCommandParameterProvider_CommandIsCreatedAsExpected() { var person = Person.Faker.Generate(1).Single(); var record = new { person.FirstName, person.LastName, person.MiddleInitial, person.Age, person.DateOfBirth, person.Gender }; var staticCommandParameters = DatabaseWriterCommandFactoryTests.CreateStaticParameters(record); var commandParameterProvider = MockRepository.GenerateMock <IDatabaseWriterCommandParameterProvider>(); commandParameterProvider.Expect(x => x.GetParameters(Arg <object> .Is.Equal(record))).Return(staticCommandParameters).Repeat.Once(); var databaseWriterCommandFactory = new DatabaseWriterCommandFactory(commandParameterProvider) { CommandText = "dbo.InsertPerson", CommandType = CommandType.StoredProcedure, CommandTimeout = TimeSpan.FromMinutes(2) }; using (var command = databaseWriterCommandFactory.Create(record)) { commandParameterProvider.VerifyAllExpectations(); Assert.AreEqual(databaseWriterCommandFactory.CommandText, command.CommandText); Assert.AreEqual(databaseWriterCommandFactory.CommandType, command.CommandType); Assert.AreEqual(databaseWriterCommandFactory.CommandTimeout, TimeSpan.FromMilliseconds(command.CommandTimeout)); DatabaseWriterCommandFactoryTests.AssertCommandParametersAreCreatedAsExpected(command, record); } }