示例#1
0
        public void GenerateActionsUsingRoleAdmin()
        {
            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;

            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 actions = new Dictionary <IPlugin, IEnumerable <Action> >();

            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.GetActions()).Returns(actions);

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

            foreach (var plugin in plugins)
            {
                actions.Add(
                    plugin,
                    plugin.BuildActions().Where(
                        a => this.IsAllowed(a.Link.Split('/').First(), a.Link.Split('/').Skip(1).First(), roles)));
            }

            foreach (var plugin in plugins)
            {
                var action1 =
                    service.GetActions()[plugin].Where(
                        a => this.IsAllowed(a.Link.Split('/').First(), a.Link.Split('/').Skip(1).First(), roles));

                var action =
                    actions[plugin].Where(
                        a => this.IsAllowed(a.Link.Split('/').First(), a.Link.Split('/').Skip(1).First(), roles));

                foreach (var action2 in action)
                {
                    if (action1.Count(item => item == action2) == 0)
                    {
                        Assert.Fail("Iterms mismatch");
                    }
                }
            }
        }