public void AuditScan_WithNonExistingBarcode_ShouldBeRegistered() { string username = doctor.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; bool updated = false; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(doctor); medicationTypeDAO.Setup(x => x.GetMedicationTypeById(It.IsAny <int>())).Returns(type1); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns((MedicationPackage)null); medicationPackageDAO.Setup(x => x.InsertPackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationTypeDAO = medicationTypeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act updated = bll.CheckAndUpdatePackage(type1.ID, barcode); // Assert AssertPackageMatchesExpected(barcode, PackageStatus.InStock, dc2.ID, null, null, username, result); Assert.AreEqual(true, updated); }
public void MedicationPackageDAO_InsertPackage_Succeeds() { string barcode = "10001001"; // Preconditions MedicationPackage packageBeforeInsert = dao.FindPackageByBarcode(barcode); Assert.IsNull(packageBeforeInsert); // Insert package MedicationPackage package = new MedicationPackage(); package.Barcode = barcode; package.TypeId = 1; package.Status = PackageStatus.InStock; package.ExpireDate = new DateTime(2015, 12, 31); package.StockDCId = 1; package.Operator = "blizzard"; package.UpdateTime = TimeProvider.Current.Now; dao.InsertPackage(package); // Assert MedicationPackage packageAfterInsert = dao.FindPackageByBarcode(barcode); Assert.IsNotNull(packageAfterInsert); }
public void AuditScan_WithNonMatchedPackageType_ShouldFail() { string username = doctor.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; bool updated = false; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(doctor); medicationTypeDAO.Setup(x => x.GetMedicationTypeById(It.IsAny <int>())).Returns(type1); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns( new MedicationPackage { Barcode = barcode, TypeId = type2.ID, Status = PackageStatus.Lost, StockDCId = dc1.ID, SourceDCId = null, DestinationDCId = null, Operator = username }); medicationPackageDAO.Setup(x => x.InsertPackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationTypeDAO = medicationTypeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act updated = bll.CheckAndUpdatePackage(type1.ID, barcode); // Assert Assert.Fail("Medication type not matched"); }
public void SendPackage_ToCurrentDistributionCentre_ShouldFail() { string username = agent.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange distributionCentreDAO.Setup(x => x.GetDistributionCentreById(It.IsAny <int>())).Returns(dc1); employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(agent); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns( new MedicationPackage { Barcode = barcode, Status = PackageStatus.InStock, StockDCId = dc1.ID, SourceDCId = null, DestinationDCId = null, Operator = username }); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.DistributionCentreDAO = distributionCentreDAO.Object; bll.EmployeeDAO = employeeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.SendPackage(barcode, dc1.ID); // Assert Assert.Fail("Cannot send package to current distribution centre"); }
public void SendPackage_WithValidData_ShouldBeSent() { string username = agent.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange distributionCentreDAO.Setup(x => x.GetDistributionCentreById(It.IsAny <int>())).Returns(dc2); employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(agent); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns( new MedicationPackage { Barcode = barcode, Status = PackageStatus.InStock, StockDCId = dc1.ID, SourceDCId = null, DestinationDCId = null, Operator = username }); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.DistributionCentreDAO = distributionCentreDAO.Object; bll.EmployeeDAO = employeeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.SendPackage(barcode, dc2.ID); // Assert AssertPackageMatchesExpected(barcode, PackageStatus.InTransit, null, dc1.ID, dc2.ID, username, result); }
public void MedicationPackageDAO_FindPackageByBarcode_ReturnsCorrespondingPackage() { MedicationPackage medicationPackage = dao.FindPackageByBarcode("10001000"); Assert.IsNotNull(medicationPackage); Assert.AreEqual(1, medicationPackage.TypeId); Assert.AreEqual(PackageStatus.InStock, medicationPackage.Status); Assert.AreEqual(1, medicationPackage.StockDCId); Assert.AreEqual("blizzard", medicationPackage.Operator); medicationPackage = dao.FindPackageByBarcode("10001001"); Assert.IsNull(medicationPackage); }
public void MedicationPackageDAO_DeletePackage_Succeeds() { string barcode = "10001000"; // Preconditions MedicationPackage package = dao.FindPackageByBarcode(barcode); Assert.IsNotNull(package); // Delete package dao.DeletePackage(package); // Assert MedicationPackage after_insert_package = dao.FindPackageByBarcode(barcode); Assert.IsNull(after_insert_package); }
public void Audit_WithPartialPackagesScanned_ShouldIdentifyLostPackages() { string username = doctor.Username; MedicationPackageBLL bll = new MedicationPackageBLL(username); List <string> scannedList = new List <string>() { "100001", "100003", "100005" }; MedicationPackage result = null; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(doctor); medicationPackageDAO.Setup(x => x.FindInStockPackagesInDistributionCentre(It.IsAny <int>(), It.IsAny <int>())).Returns( new List <MedicationPackage>() { new MedicationPackage { Barcode = "100001", Status = PackageStatus.InStock, StockDC = dc2, SourceDC = null, DestinationDC = null, Operator = agent.Username }, new MedicationPackage { Barcode = "100002", Status = PackageStatus.InStock, StockDC = dc2, SourceDC = null, DestinationDC = null, Operator = agent.Username }, new MedicationPackage { Barcode = "100003", Status = PackageStatus.InStock, StockDC = dc2, SourceDC = null, DestinationDC = null, Operator = agent.Username }, new MedicationPackage { Barcode = "100004", Status = PackageStatus.InStock, StockDC = dc2, SourceDC = null, DestinationDC = null, Operator = doctor.Username }, new MedicationPackage { Barcode = "100005", Status = PackageStatus.InStock, StockDC = dc2, SourceDC = null, DestinationDC = null, Operator = doctor.Username } }); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act List <MedicationPackage> lostPackages = bll.AuditPackages(type1.ID, scannedList); // Assert Assert.AreEqual(2, lostPackages.Count); AssertPackageMatchesExpected("100002", PackageStatus.Lost, dc2.ID, null, null, username, lostPackages[0]); AssertPackageMatchesExpected("100004", PackageStatus.Lost, dc2.ID, null, null, username, lostPackages[1]); }
public void RegisterPackage_WithValidData_ShouldBeRegistered() { string username = agent.Username; string barcode = "123456"; string expireDate = "2016-04-30"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(agent); medicationTypeDAO.Setup(x => x.GetMedicationTypeById(It.IsAny <int>())).Returns(type1); medicationPackageDAO.Setup(x => x.InsertPackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationTypeDAO = medicationTypeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.RegisterPackage(type1.ID, expireDate, barcode); // Assert AssertPackageMatchesExpected(barcode, PackageStatus.InStock, dc1.ID, null, null, username, result); }
public void SendPackage_WithNonExistingBarcode_ShouldFail() { string username = agent.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange distributionCentreDAO.Setup(x => x.GetDistributionCentreById(It.IsAny <int>())).Returns(dc2); employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(agent); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns((MedicationPackage)null); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.DistributionCentreDAO = distributionCentreDAO.Object; bll.EmployeeDAO = employeeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.SendPackage(barcode, dc2.ID); // Assert Assert.Fail("Medication package not found"); }
public void RegisterPackage_WithInvalidDate_ShouldFail() { string username = agent.Username; string barcode = "123456"; string expireDate = "2016-13-30"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(agent); medicationTypeDAO.Setup(x => x.GetMedicationTypeById(It.IsAny <int>())).Returns(type1); medicationPackageDAO.Setup(x => x.InsertPackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationTypeDAO = medicationTypeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.RegisterPackage(type1.ID, expireDate, barcode); // Assert Assert.Fail("Invalid date format"); }
public void MedicationPackageDAO_UpdatePackage_Succeeds() { string barcode = "10001000"; // Preconditions MedicationPackage package = dao.FindPackageByBarcode(barcode); Assert.IsNotNull(package); Assert.AreEqual(PackageStatus.InStock, package.Status); Assert.AreEqual("blizzard", package.Operator); // Update package package.Status = PackageStatus.Distributed; package.Operator = "popcap"; dao.UpdatePackage(package); // Assert MedicationPackage packageAfterUpdate = dao.FindPackageByBarcode(barcode); Assert.IsNotNull(packageAfterUpdate); Assert.AreEqual(PackageStatus.Distributed, packageAfterUpdate.Status); Assert.AreEqual("popcap", packageAfterUpdate.Operator); }
public void DiscardPackage_WithDistributedStatus_ShouldBeDiscarded() { string username = doctor.Username; string barcode = "123456"; MedicationPackageBLL bll = new MedicationPackageBLL(username); MedicationPackage result = null; // Arrange employeeDAO.Setup(x => x.GetEmployeeByUserName(It.IsAny <string>())).Returns(doctor); medicationPackageDAO.Setup(x => x.FindPackageByBarcode(It.IsAny <string>())).Returns( new MedicationPackage { Barcode = barcode, Status = PackageStatus.Distributed, StockDCId = dc2.ID, SourceDCId = null, DestinationDCId = null, Operator = agent.Username }); medicationPackageDAO.Setup(x => x.UpdatePackage(It.IsAny <MedicationPackage>())).Callback <MedicationPackage>(r => result = r); bll.EmployeeDAO = employeeDAO.Object; bll.MedicationPackageDAO = medicationPackageDAO.Object; // Act bll.DiscardPackage(barcode); // Assert AssertPackageMatchesExpected(barcode, PackageStatus.Discarded, dc2.ID, null, null, username, result); }
void AssertPackageMatchesExpected(string expectedBarcode, PackageStatus expectedStatus, int?expectedStockDC, int?expectedSourceDC, int?expectedDestinationDC, string expectedUsername, MedicationPackage result) { Assert.AreEqual(expectedBarcode, result.Barcode); Assert.AreEqual(expectedStatus, result.Status); AssertDistributionCentreEqual(expectedStockDC, result.StockDCId); AssertDistributionCentreEqual(expectedSourceDC, result.SourceDCId); AssertDistributionCentreEqual(expectedDestinationDC, result.DestinationDCId); Assert.AreEqual(expectedUsername, result.Operator); }