Example #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var     requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic sportMessage = JsonConvert.DeserializeObject <CoachTextDto>(requestBody);


            try
            {
                var                 accountSid         = System.Environment.GetEnvironmentVariable("AccountSid");
                var                 authToken          = System.Environment.GetEnvironmentVariable("AuthToken");
                var                 fromPhone          = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository      smsRepository      = new SmsRepository(accountSid, authToken, fromPhone);
                var                 connectionString   = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                 options            = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString ?? throw new InvalidOperationException()).Options;
                var                 context            = new PwsodbContext(options);
                ITrainingRepository trainingRepository = new TrainingRepository(context);
                var                 worker             = new TextWorker(trainingRepository, smsRepository);
                var                 numOfSms           = await worker.SendSmsForSport(sportMessage);

                return((ActionResult) new OkObjectResult(numOfSms));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic teams       = JsonConvert.DeserializeObject <TournamentDto>(requestBody);


            try
            {
                var apiKey = System.Environment.GetEnvironmentVariable("ApiKey");
                IEmailRepository emailRepository         = new EmailRepository(apiKey);
                var                  connectionString    = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                  options             = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;
                PwsodbContext        context             = new PwsodbContext(options);
                ITrainingRepository  trainingRepository  = new TrainingRepository(context);
                IReferenceRepository referenceRepository = new ReferenceRepository(context);
                ReferenceWorker      refWorker           = new ReferenceWorker(referenceRepository);
                EmailWorker          emailWorker         = new EmailWorker(trainingRepository, emailRepository);
                var                  accountSid          = System.Environment.GetEnvironmentVariable("AccountSid");
                var                  authToken           = System.Environment.GetEnvironmentVariable("AuthToken");
                var                  fromPhone           = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository       smsRepository       = new SmsRepository(accountSid, authToken, fromPhone);
                var                  textWorker          = new TextWorker(trainingRepository, smsRepository);

                foreach (var team in teams.Teams)
                {
                    var emailMessage = refWorker.ChampionshipEmailPreparation(team);
                    var textMessage  = refWorker.ChampionshipTextPreparation(team);
                    var numOfEmails  = await emailWorker.SendEmailsForSport(emailMessage);

                    var numOfSms = await textWorker.SendSmsForSport(textMessage);
                }

                return((ActionResult) new OkObjectResult(1));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
Example #3
0
        public void SendSmsForSport_When_executed_x_text_sent(int sportId, int?locationId, int?categoryId, int?teamId, bool?selected, bool?volunteerOnly, int expected)

        {
            LoadPhones();
            _mockTrainingRepository.Setup(repository => repository.GetPhonesBySport(sportId)).ReturnsAsync(_phoneList[sportId - 1]);

            const string text    = "and easy to do anywhere, even with C#";
            CoachTextDto message = new CoachTextDto
            {
                SportId     = sportId,
                Message     = text,
                IsVolunteer = volunteerOnly,
                Selected    = selected,
                ProgramId   = locationId,
                SportTypeId = categoryId,
                TeamId      = teamId
            };

            var actual = _worker.SendSmsForSport(message);

            _mockSmsRepository.Verify(mock => mock.SendSms(It.IsAny <string>(), text), Times.Exactly(expected));
            Assert.Equal(expected, actual.Result);
        }