public void ShouldCovertValidStringToDate() { PrimitiveMapper mapper = new PrimitiveMapper(); DateTime original = DateTime.Today; // date only DateTime actual = mapper.ToDateTime(mapper.ToString(original)); Assert.AreEqual(original, actual, "The date/time was not parsed correctly."); }
public void ShouldThrowAdapterExceptionForInvalidDate() { try { PrimitiveMapper mapper = new PrimitiveMapper(); mapper.ToDateTime("hello"); Assert.Fail("The invalid date/time should have caused an exception to be thrown."); } catch (AdapterException exception) { Assert.AreEqual(HttpStatusCode.BadRequest, exception.StatusCode, "The wrong status code was sent."); } }
public void ShouldConvertDataObjectToViewModel() { Customer customer = new Customer() { CustomerId = Guid.NewGuid(), Name = "Bob", Height = 123, BirthDate = new DateTime(2012, 12, 31) }; CustomerMapper mapper = new CustomerMapper(); CustomerData viewModel = mapper.Convert(customer); PrimitiveMapper primitiveMapper = new PrimitiveMapper(); Assert.AreEqual(customer.BirthDate, primitiveMapper.ToDateTime(viewModel.BirthDate), "The birth date was not mapped."); Assert.AreEqual(customer.CustomerId, Guid.Parse(viewModel.CustomerId), "The customer ID was not mapped."); Assert.AreEqual(customer.Height, viewModel.Height, "The height was not mapped."); Assert.AreEqual(customer.Name, viewModel.Name, "The name was not mapped."); }