public void Test_Dynamic_Module_Filter()
        {
            // Arrange
            var request = new Mock<HttpRequestBase>();
            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test=module-0"));

            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData(); //
            routeData.Values.Add("moduleid", "0");

            var fakeRepo = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership();
            var controller = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock<ActionExecutingContext>();
            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary<string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute();

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsNotNull(filterContext.Object.ActionParameters["module"]);
            Assert.IsInstanceOfType(filterContext.Object.ActionParameters["module"], typeof(Module));
        }
        public void Test_Dynamic_Module_Filter_Admin_User()
        {
            // Arrange
            var request = new Mock<HttpRequestBase>();
            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test-module-0"));

            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData(); //
            routeData.Values.Add("moduleid", "0");

            var fakeRepo = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership("Fake Admin", "*****@*****.**");
            FakeModuleMembership.FakeUserId = Guid.NewGuid();   // change the user id for one that is not authorized
            var controller = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock<ActionExecutingContext>();
            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary<string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute() { CheckLogin = true };

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsNotNull(filterContext.Object.ActionParameters["module"]);
            Assert.IsInstanceOfType(filterContext.Object.ActionParameters["module"], typeof(Module));
        }
Пример #3
0
        public void Test_Dynamic_Module_List()
        {
            // Arrange
            var fakeRepo       = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership();

            DynamicModuleController controller = new DynamicModuleController(fakeRepo, fakeMembership);

            // Act
            var fakeModule = fakeRepo.GetModuleById(0);
            var result     = controller.List(fakeModule);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            var viewResult = result as ViewResult;
            var model      = viewResult.ViewData.Model;

            Assert.IsNotNull(model);
            Assert.IsInstanceOfType(model, typeof(IEnumerable <DynamicModuleViewModel>));

            var viewModel = model as IEnumerable <DynamicModuleViewModel>;

            Assert.AreEqual(fakeModule.ModuleName, viewResult.ViewData["ModuleName"]);
            Assert.AreEqual(fakeModule.DisplayName, viewResult.ViewData["DisplayName"]);
        }
Пример #4
0
        public void Test_Dynamic_Module_Filter_Unauthorized_User()
        {
            // Arrange
            var request = new Mock <HttpRequestBase>();

            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test-module-0"));

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData(); //

            routeData.Values.Add("moduleid", "0");

            var fakeRepo       = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership("Fulano de Tal", "*****@*****.**");

            FakeModuleMembership.FakeUserId = Guid.NewGuid();   // change the user id for one that is not authorized
            var controller = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock <ActionExecutingContext>();

            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary <string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute()
            {
                CheckLogin = true
            };

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsInstanceOfType(filterContext.Object.Result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Usuário não autorizado.", filterContext.Object.Controller.TempData["Message"]);
            Assert.AreEqual((filterContext.Object.Result as RedirectToRouteResult).RouteValues["Controller"], "Home");
        }
Пример #5
0
        public void Test_Dynamic_Module_Filter_Admin_User()
        {
            // Arrange
            var request = new Mock <HttpRequestBase>();

            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test-module-0"));

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData();             //

            routeData.Values.Add("moduleid", "0");

            var fakeRepo       = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership("Fake Admin", "*****@*****.**");

            FakeModuleMembership.FakeUserId = Guid.NewGuid();               // change the user id for one that is not authorized
            var controller = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock <ActionExecutingContext>();

            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary <string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute()
            {
                CheckLogin = true
            };

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsNotNull(filterContext.Object.ActionParameters["module"]);
            Assert.IsInstanceOfType(filterContext.Object.ActionParameters["module"], typeof(Module));
        }
Пример #6
0
        public void Test_Dynamic_Module_Filter()
        {
            // Arrange
            var request = new Mock <HttpRequestBase>();

            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test=module-0"));

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData(); //

            routeData.Values.Add("moduleid", "0");

            var fakeRepo       = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership();
            var controller     = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock <ActionExecutingContext>();

            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary <string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute();

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsNotNull(filterContext.Object.ActionParameters["module"]);
            Assert.IsInstanceOfType(filterContext.Object.ActionParameters["module"], typeof(Module));
        }
        public void Test_Dynamic_Module_Filter_Unauthorized_User()
        {
            // Arrange
            var request = new Mock<HttpRequestBase>();
            request.Setup(r => r.HttpMethod).Returns("GET");
            request.SetupGet(r => r.Url).Returns(new Uri("http://localhost/uac/dyn/0/The-test-module-0"));

            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(c => c.Request).Returns(request.Object);

            var routeData = new RouteData(); //
            routeData.Values.Add("moduleid", "0");

            var fakeRepo = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership("Fulano de Tal", "*****@*****.**");
            FakeModuleMembership.FakeUserId = Guid.NewGuid();   // change the user id for one that is not authorized
            var controller = new DynamicModuleController(fakeRepo, fakeMembership);

            var filterContext = new Mock<ActionExecutingContext>();
            filterContext.SetupGet(c => c.HttpContext).Returns(httpContext.Object);
            filterContext.SetupGet(c => c.RouteData).Returns(routeData);
            filterContext.SetupGet(c => c.ActionParameters).Returns(new Dictionary<string, object>());
            filterContext.Setup(c => c.Controller).Returns(controller);

            var attrib = new DynamicModuleActionAttribute() { CheckLogin = true };

            // Act
            attrib.OnActionExecuting(filterContext.Object);

            // Assert
            Assert.IsInstanceOfType(filterContext.Object.Result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Usuário não autorizado.", filterContext.Object.Controller.TempData["Message"]);
            Assert.AreEqual((filterContext.Object.Result as RedirectToRouteResult).RouteValues["Controller"], "Home");
        }
        public void Test_Dynamic_Module_List()
        {
            // Arrange
            var fakeRepo = new FakeModuleRepository();
            var fakeMembership = new FakeModuleMembership();

            DynamicModuleController controller = new DynamicModuleController(fakeRepo, fakeMembership);

            // Act
            var fakeModule = fakeRepo.GetModuleById(0);
            var result = controller.List(fakeModule);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            var viewResult = result as ViewResult;
            var model = viewResult.ViewData.Model;

            Assert.IsNotNull(model);
            Assert.IsInstanceOfType(model, typeof(IEnumerable<DynamicModuleViewModel>));

            var viewModel = model as IEnumerable<DynamicModuleViewModel>;

            Assert.AreEqual(fakeModule.ModuleName, viewResult.ViewData["ModuleName"]);
            Assert.AreEqual(fakeModule.DisplayName, viewResult.ViewData["DisplayName"]);
        }