Пример #1
0
        public void GenerateMenuUsingRoleAdmin()
        {
            HttpRequest  httpRequest  = new HttpRequest("", "http://mySomething/", "");
            StringWriter stringWriter = new StringWriter();
            HttpResponse httpResponce = new HttpResponse(stringWriter);
            //httpResponce.Filter = new FileStream("asd.pdo",FileMode.CreateNew);
            HttpContext httpConextMock = new HttpContext(httpRequest, httpResponce);

            HttpContext.Current = httpConextMock;
            Menu menu  = new Menu();
            Menu menu1 = new Menu();

            container = new WindsorContainer();
            //HttpContext.Current = new HttpContext(new HttpRequest("", "http://iudico.com", null), new HttpResponse(new StreamWriter("mayBeDeleted.txt")));
            InitializeWindsor(ref container);

            service = container.Resolve <ILmsService>();
            PluginController.LmsService = service;
            var         plugins = container.ResolveAll <IPlugin>();
            List <Role> roles   = new List <Role>();

            roles.Add(Role.Admin);

            IEnumerable <Role> currentRole = from rol in roles
                                             select rol;
            Mock <IUserService> userServiceMock = new Mock <IUserService>();

            userServiceMock.Setup(item => item.GetCurrentUserRoles()).Returns(currentRole);
            IUserService userServiceVar = service.FindService <IUserService>();

            userServiceVar = userServiceMock.Object;
            Mock <ILmsService> lmsservice = new Mock <ILmsService>();

            lmsservice.Setup(item => item.FindService <IUserService>()).Returns(userServiceMock.Object);
            AccountController acct = new AccountController(new DatabaseUserStorage(service));

            lmsservice.Setup(item => item.GetMenu()).Returns(menu);

            try
            {
                service = lmsservice.Object;
                service.Inform(LMSNotifications.ApplicationRequestStart);
            }
            catch (Exception e)
            {
            }

            foreach (var plugin in plugins)
            {
                menu.Add(plugin.BuildMenuItems().Where(m => IsAllowed(m.Controller, m.Action, roles)));
            }

            foreach (var plugin in plugins)
            {
                Menu menu11 = service.GetMenu();

                foreach (var menu2 in menu.Items)
                {
                    if (menu11.Items.Count(item => item == menu2) == 0)
                    {
                        Assert.Fail("Iterms mismatch");
                    }
                }
            }
        }
Пример #2
0
        public void GenerateMenuUsingRoleAdmin()
        {
            var httpRequest = new HttpRequest(string.Empty, "http://mySomething/", string.Empty);
            var stringWriter = new StringWriter();
            var httpResponce = new HttpResponse(stringWriter);

            // httpResponce.Filter = new FileStream("asd.pdo",FileMode.CreateNew);
            var httpConextMock = new HttpContext(httpRequest, httpResponce);

            HttpContext.Current = httpConextMock;
            var menu = new Menu();
            var menu1 = new Menu();
            container = new WindsorContainer();

            // HttpContext.Current = new HttpContext(new HttpRequest("", "http://iudico.com", null), new HttpResponse(new StreamWriter("mayBeDeleted.txt")));
            InitializeWindsor(ref container);

            service = container.Resolve<ILmsService>();
            PluginController.LmsService = service;
            var plugins = container.ResolveAll<IPlugin>();
            var roles = new List<Role> { Role.Admin };

            var currentRole = from rol in roles select rol;
            var userServiceMock = new Mock<IUserService>();
            userServiceMock.Setup(item => item.GetCurrentUserRoles()).Returns(currentRole);
            var userServiceVar = service.FindService<IUserService>();
            userServiceVar = userServiceMock.Object;
            var lmsservice = new Mock<ILmsService>();
            lmsservice.Setup(item => item.FindService<IUserService>()).Returns(userServiceMock.Object);
            var acct = new AccountController(new DatabaseUserStorage(service));
            lmsservice.Setup(item => item.GetMenu()).Returns(menu);

            try
            {
                service = lmsservice.Object;
                service.Inform(LMSNotifications.ApplicationRequestStart);
            }
            catch (Exception)
            {
            }

            foreach (var plugin in plugins)
            {
                menu.Add(plugin.BuildMenuItems().Where(m => this.IsAllowed(m.Controller, m.Action, roles)));
            }

            foreach (var plugin in plugins)
            {
                var menu11 = service.GetMenu();

                foreach (var menu2 in menu.Items)
                {
                    if (menu11.Items.Count(item => item == menu2) == 0)
                    {
                        Assert.Fail("Iterms mismatch");
                    }
                }
            }
        }