Esempio n. 1
0
        public void RegisterShould_ReturnViewWithModel_WhenModelIsNotValid(string email,
                                                                           string username, string password, string firstName, string lastName, string phoneNumber)
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();

            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            authProviderMock.Setup(
                p =>
                p.RegisterAndLoginUser(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <bool>(),
                                       It.IsAny <bool>()))
            .Returns(IdentityResult.Success);

            var user = new User();

            var mockedFactory = new Mock <IUserService>();

            mockedFactory.Setup(f => f.CreateUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(user);

            var model = new RegisterViewModel
            {
                Email    = email,
                Username = username,
                Password = password
            };

            controller.ModelState.AddModelError("key", "message");

            controller
            .WithCallTo(c => c.Register(model))
            .ShouldRenderDefaultView()
            .WithModel <RegisterViewModel>(m => Assert.AreSame(model, m));
        }
Esempio n. 2
0
        public void RegisterShould_ReturnRedirectToRouteResult_WhenResultSuccess(string email,
                                                                                 string username, string password, string firstName, string lastName, string phoneNumber)
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();

            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            authProviderMock.Setup(
                p =>
                p.RegisterAndLoginUser(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <bool>(),
                                       It.IsAny <bool>()))
            .Returns(IdentityResult.Success);

            var user = new User();


            userServiceMock.Setup(f => f.CreateUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(user);

            var model = new RegisterViewModel
            {
                Email    = email,
                Username = username,
                Password = password
            };

            controller
            .WithCallTo(c => c.Register(model))
            .ShouldRedirectTo((Web.Controllers.HomeController c) => c.Index());
        }
Esempio n. 3
0
        public void ProfileShould_ReturnDefaultView_WhenUserWasFound(string username)
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();
            var user             = new User()
            {
                UserName = username
            };
            var list = new List <User>()
            {
                user
            };

            userServiceMock.Setup(s => s.GetUserByUsername(username)).Returns(list.AsQueryable());
            InitializeMapper();
            authProviderMock.Setup(ap => ap.CurrentUserUsername).Returns(username);
            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);
            var model      = new ProfileViewModel()
            {
                IsCurrentUser = true
            };

            controller
            .WithCallTo(c => c.Profile(username))
            .ShouldRenderDefaultView();
        }
Esempio n. 4
0
        public void RegisterShould_ReturnDefaultView()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();

            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            controller
            .WithCallTo(c => c.Register())
            .ShouldRenderDefaultView();
        }
Esempio n. 5
0
        public void LogoffShould_ReturnRedirectToAction()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();

            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            controller
            .WithCallTo(c => c.LogOff())
            .ShouldRedirectTo((Web.Controllers.HomeController homeController) => homeController.Index());
        }
Esempio n. 6
0
        public void ProfileShould_ReturnErrorView_WhenPassedUsernameIsNull()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();

            InitializeMapper();
            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            controller
            .WithCallTo(c => c.Profile(null))
            .ShouldRenderView("Error");
        }
Esempio n. 7
0
        public void ProfileShould_ReturnErrorView_WhenUserWasNotFound(string username)
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var userServiceMock  = new Mock <IUserService>();
            var emptyList        = new List <User>();

            userServiceMock.Setup(s => s.GetUserByUsername(username)).Returns(emptyList.AsQueryable());
            InitializeMapper();

            var controller = new Web.Controllers.AccountController(authProviderMock.Object, userServiceMock.Object);

            controller
            .WithCallTo(c => c.Profile(username))
            .ShouldRenderView("Error");
        }