public void GetDispatchableDrugStock_WithInvalidInput_ReturnsBadRequest() { // Arrange DrugLocation drugLocation = (drugList.FirstOrDefault(d => d.Id == 1 && d.DrugLocation.Location == "Delhi")).DrugLocation; _drugServiceMock.Setup(p => p.GetDispatchableDrugStock(1, "Delhi")).Returns(drugLocation); // Act BadRequestResult data = _drugsController.GetDispatchableDrugStock(0, "55") as BadRequestResult; // Assert Assert.AreEqual(400, data.StatusCode); }
public void GetDispatchableDrugStock_WithInputNotPresentInList_ReturnsNotFound() { // Arrange DrugLocation drugLocation = (drugList.FirstOrDefault(d => d.Id == 1 && d.DrugLocation.Location == "Delhi")).DrugLocation; _drugServiceMock.Setup(p => p.GetDispatchableDrugStock(1, "Delhi")).Returns(drugLocation); // Act NotFoundObjectResult data = _drugsController.GetDispatchableDrugStock(10, "Agra") as NotFoundObjectResult; // Assert Assert.AreEqual(404, data.StatusCode); }
public void GetDispatchableDrugStock_WithValidInput_ReturnsOK(int drugId, string location) { // Arrange DrugLocation drugLocation = (drugList.FirstOrDefault(d => d.Id == drugId && d.DrugLocation.Location == location)).DrugLocation; _drugServiceMock.Setup(p => p.GetDispatchableDrugStock(drugId, location)).Returns(drugLocation); // Act OkObjectResult data = _drugsController.GetDispatchableDrugStock(drugId, location) as OkObjectResult; // Assert Assert.AreEqual(200, data.StatusCode); }
public DispatchableDrugStockDTO GetDispatchableDrugStock(int id, string location) { var drug = _dbHelper.drugs.FirstOrDefault(d => d.DrugId == id); if (drug != null) { DrugLocation available = drug.QuantityByLocation.Find(dl => dl.Location == location); if (available != null) { DispatchableDrugStockDTO dispatchableDrug = new DispatchableDrugStockDTO() { Id = drug.DrugId, Name = drug.DrugName, ExpiryDate = drug.ExpiryDate, AvailableStock = available.Quantity, CostPerUnit = drug.CostPerPackage / drug.UnitsInPackage }; return(dispatchableDrug); } return(null); } return(null); }