public string SerialiseCustomer(Customer customer) { if(string.IsNullOrEmpty(customer.ContactNumber)) throw new ArgumentNullException("ContactNumber"); if(string.IsNullOrEmpty(customer.Name)) throw new ArgumentNullException("Name"); return $"{customer.Name},{customer.ContactNumber}\n"; }
public void SerialiseCustomer_GivenNameAndContactNumber_ShouldNotThrowException() { //---------------Set up test pack------------------- var customer = new Customer { Name = "Bob", ContactNumber = "085" }; var serialiser = CreateSerialiser(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- //---------------Test Result ----------------------- Assert.DoesNotThrow(() => serialiser.SerialiseCustomer(customer)); }
public void SerialiseCustomer_GivenEmptyContactNumber_ShouldThrowException() { //---------------Set up test pack------------------- var customer = new Customer { Name = "Bob", ContactNumber = "" }; var serialiser = CreateSerialiser(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var exception = Assert.Throws<ArgumentNullException>(() => serialiser.SerialiseCustomer(customer)); //---------------Test Result ----------------------- Assert.AreEqual("ContactNumber", exception.ParamName); }
public void SerialiseCustomer_GivenNameAndNumber_ShouldReturnConcatenatedStringsWithCommas() { //---------------Set up test pack------------------- var customer = new Customer { Name = "Bob", ContactNumber = "085" }; const string expectedResult = "Bob,085\n"; var serialiser = CreateSerialiser(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var serialised = serialiser.SerialiseCustomer(customer); //---------------Test Result ----------------------- Assert.AreEqual(expectedResult, serialised); }
public void Capture_GivenCustomer_ShouldSerialise() { //---------------Set up test pack------------------- var serialiser = Substitute.For<ISerialiser>(); var customerCapturer = CreateCustomerCapturer(serialiser: serialiser); var customer = new Customer(); var customers = new List<Customer> {customer}; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- customerCapturer.Capture(customers, "", 10); //---------------Test Result ----------------------- serialiser.Received().SerialiseCustomer(customer); }
public void Capture_GivenSerialiedCustomerShouldSave() { //---------------Set up test pack------------------- var csvWriter = Substitute.For<ICsvWriter>(); var customer = new Customer(); var customers = new List<Customer> {customer}; var serialiser = Substitute.For<ISerialiser>(); const string serialisedCustomer = "Bob,083"; serialiser.SerialiseCustomer(customer).Returns(serialisedCustomer); var customerCapturer = CreateCustomerCapturer(csvWriter, serialiser); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- customerCapturer.Capture(customers, "", 10); //---------------Test Result ----------------------- csvWriter.Received().Save(Arg.Any<string>(), serialisedCustomer); }
public void Capture_GivenFileNameShouldSaveWithFileNameWithNumber() { //---------------Set up test pack------------------- var csvWriter = Substitute.For<ICsvWriter>(); var customer = new Customer(); var serialiser = Substitute.For<ISerialiser>(); serialiser.SerialiseCustomer(customer).Returns("Bob"); var customerCapturer = CreateCustomerCapturer(csvWriter, serialiser); var customers = new List<Customer> {customer}; const string fileName = "stuff"; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- customerCapturer.Capture(customers, fileName, 10); //---------------Test Result ----------------------- csvWriter.Received().Save(fileName+".1", Arg.Any<string>()); }