public void DosageSchemeTestSuitable() { //Test that a new suggestion is added to the user. PS! E-mail sending can not be currently tested functionally. // Arrange controller = SetupController(); persons.Setup(repo => repo.GetPersonByIDCode(patient.IDCode)).ReturnsAsync(new PersonObject(patient)); personMedicines.Setup(repo => repo.GetObject("123", "abc")) .ReturnsAsync(new PersonMedicineObject(new PersonMedicineDbRecord()) { Medicine = { }, Person = { } }); personMedicines.Setup(repo => repo.AddObject(It.IsAny <PersonMedicineObject>())).Returns <PersonMedicineObject>(fg => AddPerMed(fg)); medicines.Setup(repo => repo.GetObject("123")).ReturnsAsync(new MedicineObject(medicine)); // Act var x = medicines.Object.GetObjectsList(); var result = controller.DosageScheme(suggestionViewModel, "123", ""); var resultPrior = controller.DosageScheme(suggestionViewModel, "123", "prior"); // Assert Assert.IsInstanceOfType(result.Result, typeof(RedirectToActionResult)); Assert.AreEqual(2, personMedObjects.Count); Assert.AreEqual(personMedObjects[0].Person.DbRecord.IDCode, patient.IDCode); Assert.AreEqual(personMedObjects[0].Medicine.DbRecord.ID, medicine.ID); }
public void DosageSchemeTestNotSuitable() { //Test that a new suggestion is added to the user. PS! E-mail sending can not be currently tested functionally. // Arrange controller = SetupController(); medicines.Setup(repo => repo.GetObjectsList()) .ReturnsAsync(new MedicineObjectsList(new List <MedicineDbRecord>(), new RepositoryPage(0))); persons.Setup(repo => repo.GetPersonByIDCode(patient.IDCode)).ReturnsAsync(new PersonObject(patient)); personMedicines.Setup(repo => repo.GetObject("123", "abc")) .ReturnsAsync(new PersonMedicineObject(new PersonMedicineDbRecord() { Suitability = Suitability.Jah }) { Medicine = { }, Person = { } }); personMedicines.Setup(repo => repo.AddObject(It.IsAny <PersonMedicineObject>())).Returns <PersonMedicineObject>(fg => AddPerMed(fg)); medicines.Setup(repo => repo.GetObject("123")).ReturnsAsync(new MedicineObject(medicine)); // Act var x = medicines.Object.GetObjectsList(); var result = controller.DosageScheme(suggestionViewModel, "123", ""); //Change suitability to "no", meaning user will not get a suggestion unless "prior" is passed into the controller. personMedicines.Setup(repo => repo.GetObject("123", "abc")) .ReturnsAsync(new PersonMedicineObject(new PersonMedicineDbRecord() { Suitability = Suitability.Ei }) { Medicine = { }, Person = { } }); var resultPrior = controller.DosageScheme(suggestionViewModel, "123", "prior"); var resultPriorFail = controller.DosageScheme(suggestionViewModel, "123", ""); //Suitability stays the same, "no", but medicine that is suggested, has already been suggested to the user before. //Triggers additional blocks in code. personMedicines.Setup(repo => repo.GetObject("123", "abc")) .ReturnsAsync(new PersonMedicineObject(new PersonMedicineDbRecord() { Suitability = Suitability.Ei, Medicine = medicine })); var resultsFinalPrior = controller.DosageScheme(suggestionViewModel, "123", "prior"); var resultsFinal = controller.DosageScheme(suggestionViewModel, "123", ""); // Assert //Check that only the correct amount of suggestions were added to the suggestions database. Assert.IsInstanceOfType(result.Result, typeof(RedirectToActionResult)); Assert.AreEqual(3, personMedObjects.Count); Assert.AreEqual(personMedObjects[0].Person.DbRecord.IDCode, patient.IDCode); Assert.AreEqual(personMedObjects[0].Medicine.DbRecord.ID, medicine.ID); }