public void SendAllWarningsTest() { // Arrange var mockILoggerFillDatabaseController = new Mock <ILogger <WarningSenderController> >(); var mockILoggerEducationRepository = new Mock <ILogger <EducationRepository> >(); var mockILoggerModuleContext = new Mock <ILogger <WEBAPIContext> >(); var mockILoggerSenderController = new Mock <ILogger <WarningSenderController> >(); var mockILoggerGetDataForWarning = new Mock <ILogger <GetDataForWarning> >(); var mockILoggerFD = new Mock <ILogger <FillDatabaseController> >(); var mockILoggerISendWarning = new Mock <ILogger <ISendWarning> >(); var mockISendWarning = new Mock <ISendWarning>(); Mapper mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Student, StudentBL>())); DbContextOptionsBuilder <WEBAPIContext> optionsBuilder = new DbContextOptionsBuilder <WEBAPIContext>(); optionsBuilder.UseInMemoryDatabase("CreateReportSendAllWarningsTestDb"); WEBAPIContext context = new WEBAPIContext(optionsBuilder.Options, mockILoggerModuleContext.Object); var educationRepository = new EducationRepository(context, mockILoggerEducationRepository.Object); GetDataForWarning getDataForWarning = new GetDataForWarning(educationRepository, mockILoggerGetDataForWarning.Object, mapper); WarningSenderController warningSenderController = new WarningSenderController(educationRepository, mockILoggerSenderController.Object, getDataForWarning, mockISendWarning.Object); FillDatabaseController controllerFD = new FillDatabaseController(educationRepository, mockILoggerFD.Object); // Act controllerFD.FillDatabase(); warningSenderController.SendAllWarnings(); // Assert mockISendWarning.Verify(sw => sw.SendWarningToStudents(It.Is <ICollection <StudentBL> >(s => s.Count == 3))); }
public void CreateReportTest() { // Arrange var mockILoggerReportController = new Mock <ILogger <ReportController> >(); var mockILoggerEducationRepository = new Mock <ILogger <EducationRepository> >(); var mockILoggerModuleContext = new Mock <ILogger <WEBAPIContext> >(); var mockILoggerFD = new Mock <ILogger <FillDatabaseController> >(); DbContextOptionsBuilder <WEBAPIContext> optionsBuilder = new DbContextOptionsBuilder <WEBAPIContext>(); optionsBuilder.UseInMemoryDatabase("CreateReportTestDb"); WEBAPIContext context = new WEBAPIContext(optionsBuilder.Options, mockILoggerModuleContext.Object); var educationRepository = new EducationRepository(context, mockILoggerEducationRepository.Object); var mockIReportSaver = new Mock <IReportSaver>(); List <LineOfReport> linesOfReportExpect = new List <LineOfReport>(); List <LineOfReport> linesOfReportAcnual = new List <LineOfReport>(); mockIReportSaver.Setup(d => d.Type).Returns("xml"); FillDatabaseController controllerFD = new FillDatabaseController(educationRepository, mockILoggerFD.Object); // Act controllerFD.FillDatabase(); ReportController controller = new ReportController(educationRepository, mockILoggerReportController.Object, new List <IReportSaver> { mockIReportSaver.Object }); controller.CreateReport("Ivan Ivanov", "student", "xml"); // Assert mockIReportSaver.Verify(rs => rs.SendReport(It.Is <ICollection <LineOfReport> >(lr => lr.Count == 4))); }
public void FillDatabaseTest() { // Arrange var mockILoggerFillDatabaseController = new Mock <ILogger <FillDatabaseController> >(); var mockILoggerEducationRepository = new Mock <ILogger <EducationRepository> >(); var mockILoggerModuleContext = new Mock <ILogger <WEBAPIContext> >(); DbContextOptionsBuilder <WEBAPIContext> optionsBuilder = new DbContextOptionsBuilder <WEBAPIContext>(); optionsBuilder.UseInMemoryDatabase("FillDatabaseTestDb"); WEBAPIContext context = new WEBAPIContext(optionsBuilder.Options, mockILoggerModuleContext.Object); var educationRepository = new EducationRepository(context, mockILoggerEducationRepository.Object); FillDatabaseController controller = new FillDatabaseController(educationRepository, mockILoggerFillDatabaseController.Object); List <Student> studentsExp = new List <Student>() { new Student() { FullName = "Ivan Ivanov", EMail = "*****@*****.**", Phone = "123456" }, new Student() { FullName = "Nikolai Ivanov", EMail = "*****@*****.**", Phone = "123456" }, new Student() { FullName = "Serdei Ivanov", EMail = "*****@*****.**", Phone = "123456" }, new Student() { FullName = "Petr Ivanov", EMail = "*****@*****.**", Phone = "123456" } }; // Act controller.FillDatabase(); var studentsActual = context.Students.ToList(); // Assert Assert.Equal(studentsExp.Count, studentsActual.Count); foreach (var studentActual in studentsActual) { var studentExpect = studentsExp.Find(s => s.FullName == studentActual.FullName); Assert.NotNull(studentExpect); Assert.Equal(studentExpect.EMail, studentActual.EMail); Assert.Equal(studentExpect.Phone, studentActual.Phone); } }