コード例 #1
0
        public async void EmailService_SendMessage_CheckedWithTestMail()
        {
            // Given
            client.BaseAddress = new Uri("https://api.testmail.app/api/json");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            var Query = client.BaseAddress +
                        "?apikey=" + GetKey.TestmailAPIKey() +
                        "&namespace=9h5an";

            TestMailResponse EmailResponse = null;

            // when
            var Return = EmailService.SendMessage(MaiList, report, City);

            HttpResponseMessage response = await client.GetAsync(Query);

            if (response.IsSuccessStatusCode)
            {
                EmailResponse = await response.Content.ReadAsAsync <TestMailResponse>();
            }

            string ExpectedMessage = "A new Report has been created in TestCity. The Three word address of the report is: Test.Email.Service. To view on a map open:\n https://what3words.com/Test.Email.Service\n This report was created at 01/01/0001 00:00:00, and the following was the additional information provided: Test Info\n\n Thank you! \n This message was auto-generated by HelpingHand & sent via MailGun. \nIf you want to stop recieving these messages, please turn off notifications in your account settings.\n";

            bool EmailFound = false;

            for (int i = 0; i < EmailResponse.emails.Length; i++)
            {
                var Email = EmailResponse.emails[i];
                if (Email.text == ExpectedMessage)
                {
                    EmailFound = true;
                }
            }


            // Then
            Assert.IsType <RestResponse>(Return);
            Assert.True(response.IsSuccessStatusCode);
            Assert.True(EmailFound);
        }
コード例 #2
0
        public async void Integration_CreateAReport_Success()
        {
            /* Given */
            _ReportController.TempData =
                new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            // User Accounts Added By Seed
            _Seeder.Seed();

            /* When */
            // Open New Report Page
            var CreatePage = _ReportController.Create();

            Assert.IsType <ViewResult>(CreatePage);

            // Fill ViewModel
            var FilledViewModel = new ReportViewModel()
            {
                Latitude       = 54.717805,
                Longitude      = -6.226443,
                AdditionalInfo = "Report from Antrim Castle Gardens",
            };

            // Submit
            var Result = (RedirectToActionResult)await _ReportController.Create(FilledViewModel);

            // Then
            Assert.Equal("Home", Result.ControllerName);
            Assert.Equal("Index", Result.ActionName);

            // Controller Calls Service, Service Should Get 3 Word Address
            // Should Add To Database, and have Created at time
            var CreatedReport = _db.Reports.FirstOrDefault(r =>
                                                           (r.Latitude == 54.717805) && (r.Longitude == -6.226443));

            Assert.NotNull(CreatedReport);
            Assert.NotNull(CreatedReport.ThreeWordAddress);
            Assert.Equal("cares.sand.pacifist", CreatedReport.ThreeWordAddress);
            Assert.Equal(DateTime.Now, CreatedReport.CreatedAt, TimeSpan.FromSeconds(10.00));

            // Should Call Notify Function
            var client = new HttpClient();

            client.BaseAddress = new Uri("https://api.testmail.app/api/json");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            var Query = client.BaseAddress +
                        "?apikey=" + GetKey.TestmailAPIKey() + "&namespace=9h5an";

            TestMailResponse EmailResponse = null;

            HttpResponseMessage response = await client.GetAsync(Query);

            if (response.IsSuccessStatusCode)
            {
                EmailResponse = await response.Content.ReadAsAsync <TestMailResponse>();
            }

            string ExpectedMessage =
                "A new Report has been created in Non-City Area. The Three word" +
                " address of the report is: cares.sand.pacifist. To view on a map" +
                " open:\n https://what3words.com/cares.sand.pacifist\n This" +
                " report was created at " +
                DateTime.Now.ToString() +
                ", and the following" +
                " was the additional information provided: Report from Antrim" +
                " Castle Gardens\n\n Thank you! \n This message was auto-" +
                "generated by HelpingHand & sent via MailGun. \nIf you want to" +
                " stop recieving these messages, please turn off notifications" +
                " in your account settings.\n";

            // Pattern Below Matches Return Strings using RegEx to ignore the
            // Time as this varies from report being sent to now.
            var    input   = ExpectedMessage;
            string pattern =
                @"\d+[/]\d+[/]\d+\s\d+[:]\d+[:]\d+";

            String[] ExpectedElements =
                System.Text.RegularExpressions.Regex.Split(ExpectedMessage, pattern);

            bool EmailFound = false;


            for (int i = 0; i < EmailResponse.emails.Length && !EmailFound; i++)
            {
                var      Email            = EmailResponse.emails[i];
                String[] ReturnedElements =
                    System.Text.RegularExpressions.Regex.Split(Email.text, pattern);
                if ((ExpectedElements[0] == ReturnedElements[0]) &&
                    (ExpectedElements[1] == ReturnedElements[1]))
                {
                    EmailFound = true;
                }
            }

            // Then
            Assert.True(EmailFound);
        }