public void Index_GET()
        {
            var controller = new RegistrationController(mapper, mockUserService.Object);
            var result     = controller.Index() as ViewResult;

            Assert.Equal("/Registration/ConfirmRegistration/", result.ViewData["ReturnUrl"]);
        }
        public void Index_CanVisit()
        {
            var result     = _controller.Index();
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.NotNull(viewResult.ViewName);
            Assert.NotNull(viewResult.ViewData);
            Assert.IsType <BasePageViewModel>(viewResult.ViewData.Model);
        }
        public void Index_ModelStateIsInvalid_POST()
        {
            var model      = GetData();
            var controller = new RegistrationController(mapper, mockUserService.Object);

            controller.ModelState.AddModelError("Password", "Password is required");
            var result      = controller.Index(model, "/Registration/Confirm/") as ViewResult;
            var resultModel = result.Model as RegistrationViewModel;

            Assert.Equal("pearl19", resultModel.Password);
            Assert.Equal("pearl19", resultModel.ConfirmPassword);
            Assert.True(resultModel.AcceptTerms);
        }
Exemplo n.º 4
0
        public void Index_Get_ReturnsView()
        {
            // arrange
            var auth         = new Mock <IAuthenticationService>();
            var notification = new Mock <INotificationService>();
            var redirect     = new RedirectService();
            var controller   = new RegistrationController(auth.Object, notification.Object, redirect);

            //act
            var result = controller.Index();

            //post
            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 5
0
        public async Task Index_success()
        {
            //arrange
            appUserParserMock
            .Setup(aup => aup.Parse(It.IsAny <ClaimsPrincipal>()))
            .Returns(new ApplicationUser
            {
                District          = "bbb",
                ZipCode           = "ccc",
                AdditionalAddress = "ccc",
                Email             = "eee",
                Address           = "eee",
                City  = "mmm",
                Name  = "nnn",
                Phone = "ttt",
                State = "uuu"
            })
            .Verifiable();

            //act
            var registrationController =
                new RegistrationController(appUserParserMock.Object, loggerMock.Object, userRedisRepositoryMock.Object);

            registrationController.ControllerContext.HttpContext = contextMock.Object;
            var result = await registrationController.Index();

            //assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <RegistrationViewModel>(viewResult.ViewData.Model);

            Assert.Equal <RegistrationViewModel>(model,
                                                 new RegistrationViewModel
            {
                District          = "bbb",
                ZipCode           = "ccc",
                AdditionalAddress = "ccc",
                Email             = "eee",
                Address           = "eee",
                City  = "mmm",
                Name  = "nnn",
                Phone = "ttt",
                State = "uuu"
            });
            appUserParserMock.Verify();
        }
Exemplo n.º 6
0
        public async Task Index_No_User()
        {
            //arrange
            appUserParserMock
            .Setup(a => a.Parse(It.IsAny <IPrincipal>()))
            .Returns((ApplicationUser)null)
            .Verifiable();

            var controller =
                new RegistrationController(appUserParserMock.Object, loggerMock.Object, userRedisRepositoryMock.Object);

            SetControllerUser("001", controller);

            //act
            IActionResult result = await controller.Index();

            //assert
            Assert.IsType <ViewResult>(result);
            loggerMock.Verify(l => l.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once);
            appUserParserMock.Verify();
        }
        public void Index_ModelStateIsValid_POST()
        {
            var model = GetData();

            mockUserService.Setup(m => m.CreateVerificationToken(It.IsAny <long>(),
                                                                 It.IsAny <string>())).Returns(true);
            mockUserService.Setup(m => m.SendEmailAsync(It.IsAny <string>(),
                                                        It.IsAny <string>(), It.IsAny <string>())).Returns(Task.CompletedTask);
            mockUserService.Setup(m => m.Create(It.IsAny <User>()))
            .Returns(mapper.Map <User>(model.User));


            var controller = new RegistrationController(mapper, mockUserService.Object);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.Url = new Mock <IUrlHelper>().Object;

            var result = controller.Index(model, "/Registration/ConfirmRegistration/") as RedirectResult;

            Assert.Equal("/Registration/ConfirmRegistration/", result.Url);
        }