public WarningSenderController(IEducationRepository educationRepository, ILogger <WarningSenderController> logger, GetDataForWarning getDataForWarning, ISendWarning sendWarning)//
 {
     _educationRepository = educationRepository;
     _logger            = logger;
     _getDataForWarning = getDataForWarning;
     _sendWarning       = sendWarning;
 }
Exemplo n.º 2
0
        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 GetStudentsPassesTest()
        {
            // Arrange
            var mockIEducationRepository = new Mock <IEducationRepository>();
            var mockIStudentRepository   = new Mock <IStudentRepository>();

            mockIEducationRepository.Setup(er => er.GetStudentRepository()).Returns(mockIStudentRepository.Object);
            var mockILoggerStudentsService = new Mock <ILogger <GetDataForWarning> >();
            AttendingLecture al1           = new AttendingLecture()
            {
                Atended = false
            };
            AttendingLecture al12 = new AttendingLecture()
            {
                Atended = false
            };
            AttendingLecture al13 = new AttendingLecture()
            {
                Atended = false
            };
            AttendingLecture al2 = new AttendingLecture()
            {
                Atended = true,
            };
            AttendingLecture al3 = new AttendingLecture()
            {
                Atended = true,
            };
            Student st1 = new Student()
            {
                FullName = "s1", AttendingLectures = new HashSet <AttendingLecture>()
                {
                    al1, al12, al13
                }
            };
            Student st2 = new Student()
            {
                FullName = "s2", AttendingLectures = new HashSet <AttendingLecture>()
                {
                    al2
                }
            };
            Student st3 = new Student()
            {
                FullName = "s3", AttendingLectures = new HashSet <AttendingLecture>()
                {
                    al3
                }
            };
            Student st4 = new Student()
            {
                FullName = "s4"
            };

            mockIStudentRepository.Setup(sr => sr.GetStudentsIncludeAttendingLecturesAndHomeWork()).Returns(new List <Student>()
            {
                st1, st2, st3, st4,
            });
            Mapper            mapper            = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Student, StudentBL>()));
            GetDataForWarning getDataForWarning = new GetDataForWarning(mockIEducationRepository.Object, mockILoggerStudentsService.Object, mapper);
            List <string>     expected          = new List <string>()
            {
                "s1"
            };

            //act
            List <string> actual = getDataForWarning.GetStudentsPasses(3).ToList().ConvertAll(s => s.FullName);

            //assert
            Assert.Equal(expected, actual);
        }