public void WarehouseReturnsPendingWhenBuyingItemsInStock() { var items = TestData.CreateTestData(); var cntItems = items.Count(); var c = new ItemsController(new Repository(items)); setupItemsController(c); var request = new AcquisitionRequest { Account = null, ProductName = "Item a", Quantity = 1 }; IHttpActionResult actionResult = c.Buy(request); var contentResult = actionResult as OkNegotiatedContentResult <AcquisitionResponse>; Assert.IsNotNull(contentResult); var result = contentResult.Content; Assert.AreEqual(RequestStatus.Pending, result.RepositoryResponse.Status); Assert.IsNotNull(result.RepositoryResponse.ReceiptID); Assert.IsNotNull(result.UrlToCheckStatusAt); }
public void GetStatusReturnsExpectedValues() { var items = TestData.CreateTestData(); var cntItems = items.Count(); var c = new ItemsController(new Repository(items)); setupItemsController(c); var request = new AcquisitionRequest { Account = null, ProductName = "Item a", Quantity = 1 }; IHttpActionResult actionResult = c.Buy(request); var contentResult = actionResult as OkNegotiatedContentResult <AcquisitionResponse>; var receiptId = contentResult.Content.RepositoryResponse.ReceiptID; IHttpActionResult statusResult = c.GetStatus(receiptId); var statusResponse = statusResult as OkNegotiatedContentResult <AcquisitionResponse>; var content = statusResponse.Content; Assert.AreEqual(RequestStatus.Pending, content.RepositoryResponse.Status); Assert.IsNotNull(content.RepositoryResponse.ReceiptID); Assert.IsNotNull(content.UrlToCheckStatusAt); }
public IHttpActionResult Buy(AcquisitionRequest request) { var response = _repository.Buy(request); if (response.Status == RequestStatus.OutOfStock) { return(NotFound()); } return(Ok(new AcquisitionResponse { RepositoryResponse = response, UrlToCheckStatusAt = Url.Link("items", new { controller = "items", action = "GetStatus", receiptId = response.ReceiptID }) })); }
public void BuyingNonExistingItemReturnsProperValue() { var items = TestData.CreateTestData(); int cntItems = items.Count(); var repository = new Repository(items); var request = new AcquisitionRequest { Account = new Account(), ProductName = "Item c", Quantity = 1 }; var response = repository.Buy(request); Assert.AreEqual(RequestStatus.OutOfStock, response.Status); Assert.AreEqual("Element with name Item c could not be found.", response.Description); }
public void WarehouseReturnsNotFoundWhenBuyingItemsOutOfStock() { var items = TestData.CreateTestData(); var cntItems = items.Count(); var c = new ItemsController(new Repository(items)); setupItemsController(c); var request = new AcquisitionRequest { Account = null, ProductName = "Item d", Quantity = 1 }; IHttpActionResult actionResult = c.Buy(request); Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void BuyingExistingItemReturnsProperValues() { var items = TestData.CreateTestData(); int cntItems = items.Count(); var repository = new Repository(items); var request = new AcquisitionRequest { Account = new Account(), ProductName = "Item a", Quantity = 1 }; var response = repository.Buy(request); Assert.AreEqual(RequestStatus.Pending, response.Status); Assert.AreEqual("Your order is being processed.", response.Description); Assert.IsNotNull(response.ReceiptID); }