public void MappingTest() { //Arrange var dataStorage = new Mock<IDataStorage>(); var entity = new HappinessFormData() { Id = 1, HappinessLevel = new Question {Id = 2, Value = "2"} }; var updatedEntity = new HappinessFormData() { Id = 1, HappinessLevel = new Question {Id = 3, Value = "3"} }; var repository = new HappinessFormDataRepository(dataStorage.Object); dataStorage.Setup(ds => ds.GetData<HappinessFormData>()).Returns(new List<HappinessFormData> {entity}); //Act repository.Edit(updatedEntity); //Assert //Values are equal Assert.That(entity.HappinessLevel.Value, Is.EqualTo(updatedEntity.HappinessLevel.Value)); //Objects are not equal Assert.That(entity.HappinessLevel, Is.Not.EqualTo(updatedEntity.HappinessLevel)); }
public void HappinessFormDataToViewModel_FullData() { //Arrange var hFormData = new HappinessFormData { Id = 3, Form = new Form { Id = 13, Caption = "Form13", FormState = FormState.Completed, Visit = new Visit {Caption = "Visit13", Patient = new Patient {PatientNumber = 130}} }, HappinessLevel = new Question {Id = 12, DataType = QuestionDataType.Integer, Value = "60"} }; //Act var happiness = formController.MapHappinessFormDataToViewModel(hFormData); //Assert Assert.That(happiness.FormId, Is.EqualTo(13)); Assert.That(happiness.FormCaption, Is.EqualTo("Form13")); Assert.That(happiness.IsCompleted, Is.True); Assert.That(happiness.VisitName, Is.EqualTo("Visit13")); Assert.That(happiness.PatientNumber, Is.EqualTo(130)); Assert.That(happiness.Id, Is.EqualTo(3)); Assert.That(happiness.HappinessLevel, Is.EqualTo(60)); Assert.That(happiness.HappinessLevelQuestionId, Is.EqualTo(hFormData.HappinessLevel.Id)); }
private void ArrangeHappinessTestData(List<HappinessChangeDto> dtos, Dictionary<int, int> races, Dictionary<int, int> genders, Dictionary<int, decimal> happinessChanges, out AnalyticsController controller, out Mock<IPatientRepository> pRepository, out Mock<IDemographicFormDataRepository> dfdRepository, out Mock<IHappinessFormDataRepository> hfdRepository) { pRepository = new Mock<IPatientRepository>(); dfdRepository = new Mock<IDemographicFormDataRepository>(); hfdRepository = new Mock<IHappinessFormDataRepository>(); controller = new AnalyticsController(pRepository.Object, null, dfdRepository.Object, hfdRepository.Object, null, null); pRepository.Setup(r => r.GetHappinessChangeData()).Returns(dtos); foreach (var dto in dtos) { var demog = new DemographicFormData { Race = new Question {Value = races[dto.PatientId].ToString()}, Sex = new Question {Value = genders[dto.PatientId].ToString()} }; dfdRepository.Setup(r => r.GetFormDataByFormId(dto.DemographicFormId)).Returns(demog); var hap1 = new HappinessFormData { HappinessLevel = new Question {Value = "25"} }; var hap10 = new HappinessFormData { HappinessLevel = new Question {Value = (25 + (100*happinessChanges[dto.PatientId])).ToString()} }; hfdRepository.Setup(r => r.GetFormDataByFormId(dto.HappinessDay1FormId)).Returns(hap1); hfdRepository.Setup(r => r.GetFormDataByFormId(dto.HappinessDay10FormId)).Returns(hap10); } }
public void PostEditHappinessFormData_ChangedValues_IncompleteForm_Test() { //Arrange EmulateControllerContext(formController, false); var form = new Form { Id = 13, FormState = FormState.Incomplete, Caption = "TestForm", Visit = new Visit { Caption = "TestVisit", Patient = new Patient { PatientNumber = 123 } } }; var formData = new HappinessFormData { Id = 12, Form = form, HappinessLevel = new Question() { Id = 75, Value = "75" } }; var model = new HappinessFormViewModel { Id = 12, FormId = 13, HappinessLevel = 91 }; fRep.Setup(r => r.GetByKey(model.FormId)).Returns(form); //here we return "formdata before editing" - this data should be overwritten from model hfdRep.Setup(r => r.GetByKey(model.Id)).Returns(formData); //as checking of saved formdata is quite complicated, we will save the passed object and inspect it later HappinessFormData savedFormData = null; hfdRep.Setup(r => r.Edit(It.IsAny<HappinessFormData>())).Callback<HappinessFormData>(fd => savedFormData = fd); Form savedForm = null; fRep.Setup(r => r.Edit(It.IsAny<Form>())).Callback<Form>(f => savedForm = f); //Act var result = formController.EditHappinessForm(model); //Assert CheckEditFormDataRedirectRouteValues(result, form); hfdRep.Verify(r => r.GetByKey(model.Id), Times.Once()); hfdRep.Verify(r => r.Edit(It.IsAny<HappinessFormData>()), Times.Once()); hfdRep.Verify(r => r.Save(), Times.Once()); fRep.Verify(r => r.GetByKey(model.FormId), Times.Once()); fRep.Verify(r => r.Edit(It.IsAny<Form>()), Times.Once()); fRep.Verify(r => r.Save(), Times.Once()); Assert.That(savedFormData, Is.Not.Null); Assert.That(savedFormData.Id, Is.EqualTo(model.Id)); Assert.That(savedFormData.HappinessLevel.Value, Is.EqualTo("91")); Assert.That(savedForm, Is.Not.Null); Assert.That(savedForm.Id, Is.EqualTo(model.FormId)); Assert.That(savedForm.FormState, Is.EqualTo(FormState.Completed)); }
public void PostEditHappinessFormData_ChangedUnconfirmedValues_Test() { //Arrange EmulateControllerContext(formController, false); var form = new Form { Id = 13, FormState = FormState.Completed, Caption = "TestForm", Visit = new Visit { Caption = "TestVisit", Patient = new Patient { PatientNumber = 123 } } }; var formData = new HappinessFormData { Id = 12, Form = form, HappinessLevel = new Question() { Id = 75, Value = "75" } }; var incomingModel = new HappinessFormViewModel { Id = 12, FormId = 13, HappinessLevel = 50 }; fRep.Setup(r => r.GetByKey(incomingModel.FormId)).Returns(form); //here we return "formdata before editing" - this data should be overwritten from model hfdRep.Setup(r => r.GetByKey(incomingModel.Id)).Returns(formData); //Act var result = formController.EditHappinessForm(incomingModel); //Assert hfdRep.Verify(r => r.GetByKey(incomingModel.Id), Times.Once()); hfdRep.Verify(r => r.Edit(It.IsAny<HappinessFormData>()), Times.Never()); hfdRep.Verify(r => r.Save(), Times.Never()); fRep.Verify(r => r.GetByKey(incomingModel.FormId), Times.Once()); fRep.Verify(r => r.Edit(It.IsAny<Form>()), Times.Never()); fRep.Verify(r => r.Save(), Times.Never()); Assert.That(result, Is.Not.Null); Assert.That(result is ViewResultBase); var viewResultBase = result as ViewResultBase; Assert.That(viewResultBase.Model, Is.Not.Null); HappinessFormViewModel model = viewResultBase.Model as HappinessFormViewModel; Assert.That(model, Is.Not.Null); Assert.That(model.DataChangeReasonRequired); Assert.That(model.ChangeInfos, Is.Not.Null); Assert.That(model.ChangeInfos.Count, Is.EqualTo(1)); AssertChangeInfo(formData.HappinessLevel, "Pretty Happy", "Happy", model); }
private HappinessFormData AddHappinessFormData(Form form) { var formData = new HappinessFormData() { Form = form, HappinessLevel = new Question { Caption = "Happiness", DataType = QuestionDataType.Integer, Form = form } }; HappinessFormDataRepository.Add(formData); QuestionRepository.Add(formData.HappinessLevel); return formData; }