Beispiel #1
0
        public async Task ContactModelStateInvalid()
        {
            //Arrange
            var contactDto          = new ContactDto();
            var mockRiotService     = new Mock <IRiotApiService>();
            var mockSendgridService = new Mock <ISendgridService>();
            var controller          = new WebPageController(mockRiotService.Object, mockSendgridService.Object);

            controller.ModelState.AddModelError("Testing Error", "Error");

            //Act
            var result = await controller.Contact(contactDto);

            //Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            viewResult.ViewData.ModelState.TryGetValue("Testing Error", out var error);
            Assert.Equal("Error", error.Errors[0].ErrorMessage);
        }
Beispiel #2
0
        public async Task ContactSucces()
        {
            //Arrange
            var contactDto = new ContactDto
            {
                Email   = "*****@*****.**",
                Message = "Test Message",
                Name    = "Test Name"
            };
            var mockRiotService     = new Mock <IRiotApiService>();
            var mockSendgridService = new Mock <ISendgridService>();

            mockSendgridService.Setup(s => s.SendMail(contactDto)).Verifiable();
            var controller = new WebPageController(mockRiotService.Object, mockSendgridService.Object);

            //Act
            var result = await controller.Contact(contactDto);

            //Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            mockSendgridService.Verify();
            Assert.Equal("EmailSend", redirectToActionResult.ActionName);
        }