Esempio n. 1
0
        public void IndexShould_ReturnPartialViewWithCorrectModel_WhenUserIsManager()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var factoryMock      = new Mock <IViewModelFactory>();

            authProviderMock.Setup(p => p.IsAuthenticated).Returns(true);
            var userId   = Guid.NewGuid().ToString();
            var username = "******";

            authProviderMock.Setup(p => p.CurrentUserId).Returns(userId);
            authProviderMock.Setup(p => p.CurrentUserUsername).Returns(username);
            authProviderMock.Setup(p => p.IsInRole(userId, "Admin")).Returns(false);
            authProviderMock.Setup(p => p.IsInRole(userId, "Manager")).Returns(true);

            var model = new NavigationViewModel(true, true, false, username, userId);

            factoryMock.Setup(f => f.CreateNavigationViewModel(true, true, false, username, userId))
            .Returns(model);

            var controller = new Web.Controllers.NavigationController(authProviderMock.Object, factoryMock.Object);

            controller
            .WithCallTo(c => c.Index())
            .ShouldRenderPartialView("Navigation")
            .WithModel(model);
        }
Esempio n. 2
0
        public void ConstructorShould_SetPassedDataCorrectly_WhenDataIsNotNull()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var factoryMock      = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.NavigationController(authProviderMock.Object, factoryMock.Object);

            Assert.IsNotNull(controller);
        }
Esempio n. 3
0
        public void IndexShould_CallFactoryMethodCreateNavigationViewModel()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var factoryMock      = new Mock <IViewModelFactory>();

            var model = new NavigationViewModel(false, false, false, "", "");

            authProviderMock.Setup(p => p.IsAuthenticated).Returns(false);
            factoryMock.Setup(f => f.CreateNavigationViewModel(false, false, false, "", "")).Returns(model);

            var controller = new Web.Controllers.NavigationController(authProviderMock.Object, factoryMock.Object);

            controller.Index();

            factoryMock.Verify(f => f.CreateNavigationViewModel(false, false, false, "", ""), Times.Once);
        }
Esempio n. 4
0
        public void IndexShould_ReturnPartialViewWithCorrectModel()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var factoryMock      = new Mock <IViewModelFactory>();

            var model = new NavigationViewModel(false, false, false, "", "");

            authProviderMock.Setup(p => p.IsAuthenticated).Returns(false);
            factoryMock.Setup(f => f.CreateNavigationViewModel(false, false, false, "", "")).Returns(model);

            var controller = new Web.Controllers.NavigationController(authProviderMock.Object, factoryMock.Object);

            controller
            .WithCallTo(c => c.Index())
            .ShouldRenderPartialView("Navigation")
            .WithModel(model);
        }
Esempio n. 5
0
        public void IndexShould_CallAuthProviderPropertyCurrentUsername_WhenUserIsAdmin()
        {
            var authProviderMock = new Mock <IAuthenticationProvider>();
            var factoryMock      = new Mock <IViewModelFactory>();

            var model = new NavigationViewModel(true, false, true, "", "");

            authProviderMock.Setup(p => p.IsAuthenticated).Returns(true);
            var userId   = Guid.NewGuid().ToString();
            var username = "******";

            authProviderMock.Setup(p => p.CurrentUserId).Returns(userId);
            authProviderMock.Setup(p => p.CurrentUserUsername).Returns(username);
            factoryMock.Setup(f => f.CreateNavigationViewModel(true, false, true, username, userId)).Returns(model);

            var controller = new Web.Controllers.NavigationController(authProviderMock.Object, factoryMock.Object);

            controller.Index();

            authProviderMock.Verify(ap => ap.CurrentUserUsername, Times.Once);
        }