public void Promote_cannot_promote_a_gold_customer() { Customer customer = CreateCustomer(status: CustomerStatus.Gold); var emailGateway = new FakeEmailGateway(); Response response = Invoke(x => x.Promote(customer.Id), emailGateway); response.ShouldBeError("The customer has the highest status possible"); emailGateway.ShouldContainNumberOfPromotionNotificationsSent(0); }
protected Response Invoke(Func <CustomerController, IActionResult> action, FakeEmailGateway emailGateway = null) { using (var unitOfWork = new UnitOfWork()) { var controller = new CustomerController(unitOfWork, emailGateway ?? new FakeEmailGateway()); var result = (ObjectResult)action(controller); var statusCode = (HttpStatusCode)result.StatusCode; var envelope = (Envelope <string>)result.Value; return(new Response(envelope.ErrorMessage, statusCode)); } }
public void Promote_promotes_customer() { Customer customer = CreateCustomer(); var emailGateway = new FakeEmailGateway(); Response response = Invoke(x => x.Promote(customer.Id), emailGateway); response.ShouldBeOk(); using (var db = new CustomerDatabase()) { db.ShouldContainCustomer(customer.Id) .WithStatus(CustomerStatus.Preferred); emailGateway.ShouldContainNumberOfPromotionNotificationsSent(1); } }
protected Response Invoke(Func <CustomerController, HttpResponseMessage> action, FakeEmailGateway emailGateway = null) { using (var unitOfWork = new UnitOfWork()) { var controller = new CustomerController(unitOfWork, emailGateway ?? new FakeEmailGateway()) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; HttpResponseMessage message = action(controller); HttpStatusCode statusCode = message.StatusCode; Envelope <string> envelope = message.Content.ReadAsAsync <Envelope <string> >().Result; return(new Response(envelope.ErrorMessage, statusCode)); } }