Beispiel #1
0
        public void SendEmailsForSport_WithoutMock(int sportId, int?locationId, int?categoryId, int?teamId, bool?selected, bool?volunteerOnly, int expected)

        {
            IConfiguration config           = new ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
            var            connectionString = config["TrainingDatabase"];
            var            options          = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;

            PwsodbContext context = new PwsodbContext(options);

            var           fromEmail        = config["FromEmail"];
            const string  subject          = "Sending with SendGrid is Fun";
            const string  plainTextContent = "and easy to do anywhere, even with C#";
            const string  htmlContent      = "<br>Hi {{deacon}}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Just a reminder you are the Deacon on Duty for {{month}},<br><br>&nbsp;&nbsp;&nbsp;&nbsp;You will responsible to lock up the church on Sundays after worship. If you are not going to be there then it is your responsibility to get another Deacon to close up for you. You are responsible for taking out the trash. Also make sure the offering baskets are out for the next week.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;If you are going to miss more than one Sunday in {{month}} please change with another deacon";
            CoachEmailDto message          = new CoachEmailDto
            {
                SportId          = sportId,
                From             = fromEmail,
                HtmlContent      = htmlContent,
                PlainTextContent = plainTextContent,
                Subject          = subject,
                IsVolunteer      = volunteerOnly,
                Selected         = selected,
                ProgramId        = locationId,
                SportTypeId      = categoryId,
                TeamId           = teamId
            };
            ITrainingRepository trainingRepository = new TrainingRepository(context);
            var apiKey = config["ApiKey"];
            IEmailRepository emailRepository = new EmailRepository(apiKey);
            EmailWorker      worker          = new EmailWorker(trainingRepository, emailRepository);


            //var actual = worker.SendEmailsForSport(message);
            //Assert.Equal(expected, actual.Result);
        }
Beispiel #2
0
        public void SendEmailsForSport_When_executed_x_emails_sent(int sportId, int?locationId, int?categoryId, int?teamId, bool?selected, bool?volunteerOnly, int expected)

        {
            LoadEmails();
            _mockTrainingRepository.Setup(repository => repository.GetEmailsBySport(sportId)).ReturnsAsync(_emailList[sportId - 1]);

            const string  fromEmail        = "*****@*****.**";
            const string  subject          = "Sending with SendGrid is Fun";
            const string  plainTextContent = "and easy to do anywhere, even with C#";
            const string  htmlContent      = "<br>Hi {{deacon}}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Just a reminder you are the Deacon on Duty for {{month}},<br><br>&nbsp;&nbsp;&nbsp;&nbsp;You will responsible to lock up the church on Sundays after worship. If you are not going to be there then it is your responsibility to get another Deacon to close up for you. You are responsible for taking out the trash. Also make sure the offering baskets are out for the next week.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;If you are going to miss more than one Sunday in {{month}} please change with another deacon";
            CoachEmailDto message          = new CoachEmailDto {
                SportId          = sportId,
                From             = fromEmail,
                HtmlContent      = htmlContent,
                PlainTextContent = plainTextContent,
                Subject          = subject,
                IsVolunteer      = volunteerOnly,
                Selected         = selected,
                ProgramId        = locationId,
                SportTypeId      = categoryId,
                TeamId           = teamId
            };

            var actual = _worker.SendEmailsForSport(message);

            _mockEmailRepository.Verify(mock => mock.SendEmailString(fromEmail, It.IsAny <string>(), subject, plainTextContent, htmlContent), Times.Exactly(expected));
            Assert.Equal(expected, actual.Result);
        }
Beispiel #3
0
        public async Task <int> SendEmailsForSport(CoachEmailDto message)
        {
            var sportEmailList = await GetEmailsForSport(Convert.ToInt32(message.SportId));

            var volEmailList = GetAddresses(message, sportEmailList);
            var emailList    = RemoveDuplicateEmails(volEmailList);

            emailList.Add(message.From);
            await SendEmailsAsync(emailList, message.From, message.Subject, message.PlainTextContent, message.HtmlContent);

            return(emailList.Count);
        }
Beispiel #4
0
        public CoachEmailDto ChampionshipEmailPreparation(TournamentTeamDto dto)
        {
            var details = PrepareChampionshipDetails(dto);

            CoachEmailDto emailDto = new CoachEmailDto
            {
                SportId     = 4,
                TeamId      = dto.TeamId,
                Selected    = true,
                From        = "*****@*****.**",
                Subject     = "Basketball Tournament Information",
                HtmlContent = PrepareChampionshipEmail(details)
            };

            return(emailDto);
        }
Beispiel #5
0
        public async Task <CoachEmailDto> ProcessEventCancelation(CancelEventDto cancelEvent)
        {
            var practice = await _calendarRepository.GetPracticeEvent(cancelEvent.PracticeId);

            var location = await _referenceRepository.GetLocationByProgramId(practice.ProgramId);

            _calendarRepository.CancelEvent(practice.CalendarItem.Id, cancelEvent.CancelReason,
                                            cancelEvent.CancelNote);
            SportLocationDto sport = new SportLocationDto
            {
                SportName   = location.SportNavigation.Name,
                ProgramName = location.Name,
            };
            var dto = new CoachEmailDto
            {
                From        = location.SportNavigation.Email,
                SportId     = location.SportNavigation.Id,
                ProgramId   = location.Id,
                HtmlContent = cancelEvent.CancelNote,
                Subject     = BuildCancelEmailSubject(sport, cancelEvent, practice),
            };

            return(dto);
        }
Beispiel #6
0
        public void ChampionshipEmailPreparation_When_executed_return_dto()
        {
            TournamentTeamDto dto = new TournamentTeamDto
            {
                TeamId      = 25,
                Game1TimeId = 7,
                Game2TimeId = 15,
                LocationId  = 50
            };

            Teams team = new Teams {
                Id = 25, Name = "Bulls"
            };
            CalendarTimes startTime = new CalendarTimes {
                Id = 6, TimeHour = "8:30 AM"
            };
            CalendarTimes firstTime = new CalendarTimes {
                Id = 7, TimeHour = "9:00 AM"
            };
            CalendarTimes secondTime = new CalendarTimes {
                Id = 15, TimeHour = "1:00 PM"
            };
            Locations location = new Locations
            {
                Id     = 50,
                Name   = "H. H. Poole Middle School",
                Street = "800 Eustace Road",
                City   = "Stafford",
                State  = "VA",
                Zip    = "22554"
            };

            ReferenceWorker.TournamentDetails expected = new ReferenceWorker.TournamentDetails
            {
                TeamName        = "Bulls",
                FirstGameTime   = "9:00 AM",
                SecondGameTime  = "1:00 PM",
                StartTime       = "8:30 AM",
                LocationName    = "H. H. Poole Middle School",
                LocationAddress = "800 Eustace Road",
                LocationCity    = "Stafford",
                LocationState   = "VA",
                LocationZip     = "22554"
            };

            _mockReferenceRepository.Setup(repository => repository.GetTeamByTeamId(25)).ReturnsAsync(team);
            _mockReferenceRepository.Setup(repository => repository.GetTimeByTimeId(6)).ReturnsAsync(startTime);
            _mockReferenceRepository.Setup(repository => repository.GetTimeByTimeId(7)).ReturnsAsync(firstTime);
            _mockReferenceRepository.Setup(repository => repository.GetTimeByTimeId(15)).ReturnsAsync(secondTime);
            _mockReferenceRepository.Setup(repository => repository.GetLocationByLocationId(50)).ReturnsAsync(location);

            var message =
                "<p>Hi Bulls Athletes, Athletes family, Coaches and Volunteers:<br /></p><p style=\"margin-left:30px;\"><strong>Everyone should be there at 8:30 AM.</strong><br /><br />The first game is at 9:00 AM.<br /><br />The second game is at 1:00 PM.<br /><br /><br />The competition will be at  H. H. Poole Middle School (800 Eustace Road, Stafford, VA 22554 )<br /><br /><br /><p style=\"margin-left:30px;\">You must return your uniform to your coach RIGHT AFTER SATURDAY’S COMPETITION. Remember bring a change of clothes. Failure to return your uniform may reflect on your athlete being selected for future Basketball Championships. There will also be a charge of $30 for jersey and $20 for shorts for all uniforms not returned at that time.<br /><br /><em>Remember no food or drinks are allowed in the Gymnasiums, only water.</em><br /><br /><br />Let me know if you have any questions.<br /><br /><br /></p><p>Van&nbsp;<br /><br /><br />L. A. Van Lowe&nbsp;<br /><br />Basketball Coordinator&nbsp;<br /><br /><br />P. O. 1073&nbsp;<br /><br />Woodbridge, VA 22195-1073&nbsp;<br /><br />Fax: (866) 558-8780&nbsp;<br /></p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";


            CoachEmailDto actual = _worker.ChampionshipEmailPreparation(dto);

            Assert.Equal(4, actual.SportId);
            Assert.Equal(dto.TeamId, actual.TeamId);
            Assert.Equal("*****@*****.**", actual.From);
            Assert.Equal("Basketball Tournament Information", actual.Subject);
            Assert.True(actual.Selected);
            Assert.Equal(message, actual.HtmlContent);
        }