public async Task <IActionResult> Survey(SendSurveyModel survey) { if (ModelState.IsValid) { var tunnel = await _ngrok.GetTunnelsAsync(); var actionUrl = tunnel.Where(i => i.Proto == "https").Select(i => i.PublicUrl).FirstOrDefault(); string cardJsonPath = Path.Combine(_env.ContentRootPath, "assets", "adaptive-card.json"); string cardJson = await System.IO.File.ReadAllTextAsync(cardJsonPath, Encoding.UTF8); var parsedAdaptiveCard = AdaptiveCard.FromJson(cardJson); var cardActionSets = parsedAdaptiveCard.Card.Body.Where(i => i.Type == "ActionSet").Cast <AdaptiveActionSet>(); foreach (var cardActionSet in cardActionSets) { var actionFeedback = cardActionSet.Actions.Where(i => i.Title == "Submit Feedback" && i.Type == "Action.Http").FirstOrDefault(); if (actionFeedback != null) { actionFeedback.AdditionalProperties["url"] = $"{actionUrl}/api/card"; } } string htmlTemplatePath = Path.Combine(_env.ContentRootPath, "assets", "email-body.html"); string htmlTemplate = await System.IO.File.ReadAllTextAsync(htmlTemplatePath, Encoding.UTF8); await _email.SendActionCardAsync(htmlTemplate, parsedAdaptiveCard.Card.ToJson(), survey.UserName, survey.UserPassword, survey.Recipients); } return(View()); }
public async Task <ActionResult> SendSurvey([FromBody] SendSurveyModel model) { var survey = await _repository.GetSurvey(model.SurveyId).ConfigureAwait(false); _logger.LogInformation($"Survey retrieved with Id={survey.SurveyId }"); var sentResult = await _sender.SendSurvey(model, model.SurveyRecepientId); _logger.LogInformation($"Survey sent with Id={survey.SurveyId } to sender ={model.SurveyRecepientId}"); return(Ok(sentResult)); }
public async Task TestSendSurvey(int surveyId, SendSurveyModel survey) { var mockSender = new Mock <ISurveySender>(MockBehavior.Default); var mockLogger = new Mock <ILogger <SurveyController> >(MockBehavior.Default); var mockRepo = new Mock <ISurveyRepository>(MockBehavior.Default); mockRepo.Setup(repo => repo.GetSurvey(surveyId)); //var fixture = new Fixture().Customize(new AutoMoqCustomization()); //var fistresurvey = fixture.Freeze<Mock<SurveyModel>>(); //fistresurvey.SetReturnsDefault(fixture.Create<SurveyModel>()); var controller = new SurveyController(mockRepo.Object, mockLogger.Object, mockSender.Object); var actual = await controller.SendSurvey(survey).ConfigureAwait(false); Assert.NotNull(actual); }
public async Task <int> SendSurvey(SendSurveyModel survey, int surveyRecepient) { _logger.LogInformation($"Survey [SurveyId={survey.SurveyId}] sent to {surveyRecepient}"); return(1); }