public void Cannot_Edit_Nonexists_Absence() { // Arrange (Организация) Mock <IAbsenceRepository> mock = new Mock <IAbsenceRepository>(); mock.Setup(_ => _.Absences).Returns(new List <Absence> { new Absence { Id = 1, DateAbsence = DateTime.Now, StudentId = 1, SubjectId = 1, TeacherId = 1, TypeClassId = 1 }, new Absence { Id = 2, DateAbsence = DateTime.Now, StudentId = 2, SubjectId = 2, TeacherId = 2, TypeClassId = 2 }, new Absence { Id = 3, DateAbsence = DateTime.Now, StudentId = 3, SubjectId = 3, TeacherId = 3, TypeClassId = 3 }, new Absence { Id = 4, DateAbsence = DateTime.Now, StudentId = 4, SubjectId = 4, TeacherId = 4, TypeClassId = 4 }, new Absence { Id = 5, DateAbsence = DateTime.Now, StudentId = 5, SubjectId = 5, TeacherId = 5, TypeClassId = 5 } }); // Act (Действие) AbsenceController controller = new AbsenceController(mock.Object); Absence result = controller.Edit(8).ViewData.Model as Absence; // Assert (Утверждение) Assert.IsNull(result); }
public void Index_Contains_All_Absences() { // Arrange (Организация) Mock <IAbsenceRepository> mock = new Mock <IAbsenceRepository>(); mock.Setup(_ => _.Absences).Returns(new List <Absence> { new Absence { Id = 1, DateAbsence = DateTime.Now, StudentId = 1, SubjectId = 1, TeacherId = 1, TypeClassId = 1 }, new Absence { Id = 2, DateAbsence = DateTime.Now, StudentId = 2, SubjectId = 2, TeacherId = 2, TypeClassId = 2 }, new Absence { Id = 3, DateAbsence = DateTime.Now, StudentId = 3, SubjectId = 3, TeacherId = 3, TypeClassId = 3 }, new Absence { Id = 4, DateAbsence = DateTime.Now, StudentId = 4, SubjectId = 4, TeacherId = 4, TypeClassId = 4 }, new Absence { Id = 5, DateAbsence = DateTime.Now, StudentId = 5, SubjectId = 5, TeacherId = 5, TypeClassId = 5 } }); // Act (Действие) AbsenceController controller = new AbsenceController(mock.Object); List <Absence> result = ((IEnumerable <Absence>)controller.Index().ViewData.Model).ToList(); // Assert (Утверждение) Assert.AreEqual(result.Count, 5); Assert.AreEqual(result[0].Id, 1); Assert.AreEqual(result[2].Id, 3); }
public void GetAbsence_View() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); //Act var result = controller.GetAbsence() as ViewResult; //Assert Assert.AreEqual("", result.ViewName); }
public void GetAbsenceDataBadDates_NoDataView() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); string fromDate = "123.456.789"; string toDate = "45.67.89"; //Act var result = controller.GetAbsenceData(fromDate, toDate) as ViewResult; //Assert Assert.AreEqual("NoData", result.ViewName); }
public void GetAbsenceSearchString_View() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); string searchString = "ABC"; //Act var result = controller.GetAbsence(searchString) as ViewResult; //Assert Assert.AreEqual("", result.ViewName); Assert.AreEqual("ABC", result.ViewBag.SearchString); }
public void GetAbsenceDataCalendarItemsNull_NoDataView() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); string fromDate = "10.11.1000"; string toDate = "10.11.1000"; //Act var result = controller.GetAbsenceData(fromDate, toDate) as ViewResult; var modelResult = result.Model as List <AbsenceViewModel>; //Assert Assert.AreEqual("NoData", result.ViewName); }
public void SearchStringNotEmptyabcdef_View() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); string fromDate = "01.01.2012"; string toDate = "01.01.2015"; string searchString = "abcdef"; //Act var result = controller.GetAbsenceData(fromDate, toDate, searchString) as ViewResult; var modelResult = result.Model as List <AbsenceViewModel>; //Assert Assert.AreEqual("NoData", result.ViewName); }
public void CreatePostAction_SaveModel_Absence() { // Arrange (Организация) var mock = new Mock <IAbsenceRepository>(); Absence absence = new Absence(); absence.Id = 1; AbsenceController controller = new AbsenceController(mock.Object); // Act (Действие) RedirectToRouteResult result = controller.Create(absence) as RedirectToRouteResult; // Assert (Утверждение) mock.Verify(a => a.Create(absence)); }
public void CreatePostAction_RedirectToIndexView_Absence() { // Arrange (Организация) string expected = "Index"; var mock = new Mock <IAbsenceRepository>(); Absence absence = new Absence(); AbsenceController controller = new AbsenceController(mock.Object); // Act (Действие) RedirectToRouteResult result = controller.Create(absence) as RedirectToRouteResult; // Assert (Утверждение) Assert.IsNotNull(result); Assert.AreEqual(expected, result.RouteValues["action"]); }
public void Chief_Absence_controller_getListOfAbsences() { // arrange var mockRepository = new Mock <IAbsenceBusinessLayer>(); mockRepository.Setup(repo => repo.GetListOfAbsences()).Returns(Get5AbsencesOfUserInMonthFromNow()); var controller = new AbsenceController(mockRepository.Object); //TODO: missing context with Identity as a loged in user // act var result = controller.Index(); // assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <List <Absence> >(viewResult.ViewData.Model); Assert.Equal(5, model.Count()); }
public void GetAbsenceDataCorrectDates_View() { //Arrange AbsenceController controller = new AbsenceController(mock.Object); string fromDate = "01.01.2000"; string toDate = "28.07.2017"; string searchString = ""; //Act var result = controller.GetAbsenceData(fromDate, toDate, searchString) as ViewResult; var modelResult = result.Model as List <AbsenceViewModel>; //Assert Assert.AreEqual("", result.ViewName); Assert.AreEqual(9, modelResult.Count); Assert.AreEqual(0, modelResult.ToArray()[0].Journeys.Count); Assert.AreEqual(1, modelResult.ToArray()[0].Overtimes.Count); Assert.AreEqual(1, modelResult.ToArray()[0].Sickness.Count); Assert.AreEqual(2, modelResult.ToArray()[0].Vacations.Count); Assert.AreEqual(1, modelResult.ToArray()[0].EmployeeID); Assert.AreEqual(3, modelResult.ToArray()[0].BusinessTrips.Count); Assert.AreEqual(0, modelResult.ToArray()[8].Journeys.Count); Assert.AreEqual(1, modelResult.ToArray()[8].Overtimes.Count); Assert.AreEqual(0, modelResult.ToArray()[8].Sickness.Count); Assert.AreEqual(0, modelResult.ToArray()[8].Vacations.Count); Assert.AreEqual(13, modelResult.ToArray()[8].EmployeeID); Assert.AreEqual(0, modelResult.ToArray()[8].BusinessTrips.Count); Assert.AreEqual(1, modelResult.ToArray()[2].Journeys.Count); Assert.AreEqual(0, modelResult.ToArray()[2].Overtimes.Count); Assert.AreEqual(0, modelResult.ToArray()[2].Sickness.Count); Assert.AreEqual(0, modelResult.ToArray()[2].Vacations.Count); Assert.AreEqual(3, modelResult.ToArray()[2].EmployeeID); Assert.AreEqual(0, modelResult.ToArray()[2].BusinessTrips.Count); //Assert.AreEqual(5, modelResult.ToArray()[8].BusinessTrips.ToArray()[0].EmployeeID); //Assert.AreEqual(new DateTime(2014, 06, 12), modelResult.ToArray()[8].Vacations.ToArray()[0].From); //Assert.AreEqual(new DateTime(2014, 06, 28), modelResult.ToArray()[8].Vacations.ToArray()[0].To); }
public void Can_Edit_Absence() { // Arrange (Организация) Mock <IAbsenceRepository> mock = new Mock <IAbsenceRepository>(); mock.Setup(_ => _.Absences).Returns(new List <Absence> { new Absence { Id = 1, DateAbsence = DateTime.Now, StudentId = 1, SubjectId = 1, TeacherId = 1, TypeClassId = 1 }, new Absence { Id = 2, DateAbsence = DateTime.Now, StudentId = 2, SubjectId = 2, TeacherId = 2, TypeClassId = 2 }, new Absence { Id = 3, DateAbsence = DateTime.Now, StudentId = 3, SubjectId = 3, TeacherId = 3, TypeClassId = 3 }, new Absence { Id = 4, DateAbsence = DateTime.Now, StudentId = 4, SubjectId = 4, TeacherId = 4, TypeClassId = 4 }, new Absence { Id = 5, DateAbsence = DateTime.Now, StudentId = 5, SubjectId = 5, TeacherId = 5, TypeClassId = 5 } }); // Act (Действие) AbsenceController controller = new AbsenceController(mock.Object); Absence absence1 = controller.Edit(1).ViewData.Model as Absence; Absence absence2 = controller.Edit(2).ViewData.Model as Absence; Absence absence3 = controller.Edit(3).ViewData.Model as Absence; Absence absence4 = controller.Edit(4).ViewData.Model as Absence; Absence absence5 = controller.Edit(5).ViewData.Model as Absence; // Assert (Утверждение) Assert.AreEqual(1, absence1.Id); Assert.AreEqual(2, absence2.Id); Assert.AreEqual(3, absence3.Id); Assert.AreEqual(4, absence4.Id); Assert.AreEqual(5, absence5.Id); }
/** Method initializes a process of saving and absance model to the database */ private void saveButton_Click(object sender, EventArgs e) { if (!this.isDateTimeValid()) { feedbackWindow.setCustomizedMessage(validationMessage); feedbackWindow.ShowDialog(); validationMessage = ""; return; } AbsenceModel absence = this.getAbsenceModelFromPresenterForm(); List <string> invalidFields = new List <string>(); AbsenceController controller = new AbsenceController(); if (allTheDoctors.Enabled) { invalidFields = controller.isDataValid(startDatePicker, endDatePicker, startTimePicker, endTimePicker, invalidFields, allTheDoctors); } else { invalidFields = controller.isDataValid(startDatePicker, endDatePicker, startTimePicker, endTimePicker, invalidFields); } if (invalidFields == null || invalidFields.Count == 0) { if (!controller.save(absence)) { this.feedbackWindow.setMessageForAbsencesProblems(); } else { this.feedbackWindow.setMessageForSuccessfullOperation(); } } else { feedbackWindow.setMessageForInvalidFieldsValues(invalidFields); } feedbackWindow.ShowDialog(); }
public void Can_Delete_Absence() { // Arrange (Организация) Mock <IAbsenceRepository> mock = new Mock <IAbsenceRepository>(); mock.Setup(_ => _.Absences).Returns(new List <Absence> { new Absence { Id = 1, DateAbsence = DateTime.Now, StudentId = 1, SubjectId = 1, TeacherId = 1, TypeClassId = 1 }, new Absence { Id = 2, DateAbsence = DateTime.Now, StudentId = 2, SubjectId = 2, TeacherId = 2, TypeClassId = 2 }, new Absence { Id = 3, DateAbsence = DateTime.Now, StudentId = 3, SubjectId = 3, TeacherId = 3, TypeClassId = 3 }, new Absence { Id = 4, DateAbsence = DateTime.Now, StudentId = 4, SubjectId = 4, TeacherId = 4, TypeClassId = 4 }, new Absence { Id = 5, DateAbsence = DateTime.Now, StudentId = 5, SubjectId = 5, TeacherId = 5, TypeClassId = 5 } }); Absence absence = new Absence(); absence.Id = 1; // Act (Действие) AbsenceController controller = new AbsenceController(mock.Object); Absence result = controller.Delete(absence).ViewData.Model as Absence; // Assert (Утверждение) Assert.AreEqual(absence.Id, result.Id); }
public void SetUp() { mock = Mock_Repository.CreateMock(); xlsExporterMock = new Mock <IXLSExporter>(); controller = new AbsenceController(mock.Object, xlsExporterMock.Object); }