Example #1
0
        public int AddCourse(Course course)
        {
            course.Created = DateTime.Now;
            course.Updated = DateTime.Now;

            using (var db = new CourseManagementDbConext())
            {
                db.Courses.Add(course);
                db.SaveChanges();

                var path = GetCoursePath(course.Id);
                @Directory.CreateDirectory(path);

                var templatePath = GetTemplatesPath();

                foreach (var templateFile in _TemplateFiles)
                {
                    File.Copy(Path.Combine(templatePath, templateFile), Path.Combine(path, templateFile), true);
                }

                _LmsService.Inform(CourseNotifications.CourseCreate, course);

                return(course.Id);
            }
        }
Example #2
0
        public void LmsGetLogged()
        {
            IWindsorContainer container = new WindsorContainer();

            InitializeWindsor(ref container);
            Common.Log4NetLoggerService.InitLogger();
            Assembly a        = Assembly.GetExecutingAssembly();
            string   fullPath = a.CodeBase;

            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.Combine(fullPath, "IUDICO.LMS", "log.xml");
            ILmsService service = container.Resolve <ILmsService>();

            fullPath = fullPath.Remove(0, 6);
            Common.Log4NetLoggerService.InitLogger();
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(fullPath));
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(ILmsService));
            service.Inform(LMSNotifications.ApplicationStop);
            fullPath = Path.GetDirectoryName(fullPath);
            fullPath = Path.Combine(fullPath, "Data", "Logs", "log4net.log");
            StreamReader reader = new StreamReader(fullPath);
            string       toRead = reader.ReadToEnd();

            Assert.That(toRead.IndexOf("Notification:application/stop") != -1);
        }
Example #3
0
        public int AddCourse(Course course)
        {
            course.Created = DateTime.Now;
            course.Updated = DateTime.Now;
            var db = GetDbContext();

            db.Courses.InsertOnSubmit(course);
            db.SubmitChanges();

            var path = GetCoursePath(course.Id);

            @Directory.CreateDirectory(path);

            var templatePath = GetTemplatesPath();

            foreach (var templateFile in _TemplateFiles)
            {
                File.Copy(Path.Combine(templatePath, templateFile), Path.Combine(path, templateFile), true);
            }

            _LmsService.Inform(CourseNotifications.CourseCreate, course);

            return(course.Id);
        }
Example #4
0
        public void CreateUser(User user)
        {
            var db = GetDbContext();

            user.Id           = Guid.NewGuid();
            user.Password     = EncryptPassword(user.Password);
            user.OpenId       = user.OpenId ?? string.Empty;
            user.Deleted      = false;
            user.IsApproved   = true;
            user.CreationDate = DateTime.Now;
            user.ApprovedBy   = GetCurrentUser().Id;

            db.Users.InsertOnSubmit(user);
            db.SubmitChanges();

            _LmsService.Inform(UserNotifications.UserCreate, user);
        }
        public int AddDiscipline(Discipline discipline)
        {
            var db = GetDbContext();

            discipline.Created   = DateTime.Now;
            discipline.Updated   = DateTime.Now;
            discipline.IsDeleted = false;
            discipline.IsValid   = true;
            discipline.Owner     = GetCurrentUser().Username;

            db.Disciplines.InsertOnSubmit(discipline);
            db.SubmitChanges();

            _LmsService.Inform(DisciplineNotifications.DisciplineCreate, discipline);

            return(discipline.Id);
        }
Example #6
0
        public void CreateUser(User user)
        {
            using (var db = new UserManagementDBContext())
            {
                user.Password     = EncryptPassword(user.Password);
                user.OpenId       = user.OpenId ?? string.Empty;
                user.Deleted      = false;
                user.IsApproved   = true;
                user.CreationDate = DateTime.Now;
                user.ApprovedBy   = GetCurrentUser().Id;

                db.Users.Add(user);
                db.SaveChanges();
            }

            _LmsService.Inform(UserNotifications.UserCreate, user);
        }
Example #7
0
        public int AddCurriculum(Curriculum curriculum)
        {
            var db = GetDbContext();

            curriculum.Created   = DateTime.Now;
            curriculum.Updated   = DateTime.Now;
            curriculum.IsDeleted = false;
            curriculum.IsValid   = true;
            curriculum.Owner     = GetCurrentUser().Username;

            db.Curriculums.InsertOnSubmit(curriculum);
            db.SubmitChanges();

            _LmsService.Inform(CurriculumNotifications.CurriculumCreate, curriculum);

            return(curriculum.Id);
        }
Example #8
0
        public void GenerateMenuUsingRoleNone()
        {
            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>();
            Dictionary <IPlugin, IEnumerable <IUDICO.Common.Models.Action> > actions =
                new Dictionary <IPlugin, IEnumerable <Common.Models.Action> >();
            Dictionary <IPlugin, IEnumerable <IUDICO.Common.Models.Action> > actions1;
            List <Role> roles = new List <Role>();

            roles.Add(Role.None);

            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)
            {
                IEnumerable <MenuItem> menu11 = plugin.BuildMenuItems();
                foreach (var menu2 in menu.Items)
                {
                    if (menu11.Count(item => item == menu2) == 0)
                    {
                        Assert.Fail("Iterms mismatch");
                    }
                }
            }
        }
Example #9
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");
                    }
                }
            }
        }
Example #10
0
        public void GenerateMenuUsingRoleNone()
        {
            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 actions = new Dictionary<IPlugin, IEnumerable<Action>>();
            var roles = new List<Role> { Role.None };

            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 = plugin.BuildMenuItems();

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