Пример #1
0
        public void GetModulesSuccess()
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                moduleRepository.Create(item);
            }

            //Act
            var result     = moduleRepository.Get();
            var resultItem = result.First();

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count > 0);
            Assert.NotNull(resultItem);
            Assert.NotEqual(resultItem.Id, Guid.Empty);
            Assert.False(resultItem.IsActive);
            Assert.True(!string.IsNullOrEmpty(resultItem.Name));
            Assert.True(!string.IsNullOrEmpty(resultItem.Label));
            Assert.True(!string.IsNullOrEmpty(resultItem.Description));
            Assert.True(!string.IsNullOrEmpty(resultItem.Version));
            Assert.NotNull(resultItem.ModuleAction);
            Assert.True(resultItem.ModuleAction.Count > 0);
            Assert.True(resultItem.CreatedDate > DateTime.MinValue);
            Assert.True(resultItem.LastModifiedDate > DateTime.MinValue);

            //Clean
            dbContext.Module.RemoveRange(dbContext.Module);
        }
Пример #2
0
        public void GetEditModuleActionsSuccess()
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                item.ModuleAction.First().ModuleActionType.ControlType = "edit";
                moduleRepository.Create(item);
            }
            var moduleId = modules.First().Id;

            //Act
            var result     = moduleRepository.GetEditModuleActions(moduleId);
            var resultItem = result.First();

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count > 0);
            Assert.NotNull(resultItem);
            Assert.NotEqual(resultItem.Id, Guid.Empty);
            Assert.True(!string.IsNullOrEmpty(resultItem.ActionName));
            Assert.True(!string.IsNullOrEmpty(resultItem.ControllerName));
            Assert.True(!string.IsNullOrEmpty(resultItem.ControllerNamespace));
            Assert.True(!string.IsNullOrEmpty(resultItem.DisplayName));
            Assert.True(!string.IsNullOrEmpty(resultItem.IconClass));
            Assert.True(resultItem.ModuleActionTypeId != Guid.Empty);

            //Clean
            dbContext.Module.RemoveRange(dbContext.Module);
        }
Пример #3
0
        public void CreateModuleFail()
        {
            //Arrange
            var    moduleRepository = new ModuleRepository(_container);
            Module module           = null;

            //Act
            var result = moduleRepository.Create(module);

            //Assert
            Assert.Null(result);
        }
Пример #4
0
        //[Fact]
        //public void GetModuleEditResultSuccess()
        //{
        //    //Arrange
        //    //var actionContextMock = new Mock<ActionContext>();
        //    var scopeServiceMock = new Mock<IScopeService>();
        //    var pageManager = new PageManager(_container);
        //    var moduleRepository = new ModuleRepository(_container);
        //    var dbContext = _serviceProvider.GetRequiredService<DeviserDbContext>();
        //    var pageId = SetupPageAndModules();
        //    var currentPage = pageManager.GetPageAndDependencies(pageId);
        //    scopeServiceMock.Setup(s => s.PageContext.CurrentPage).Returns(currentPage);


        //    var httpContext = CreateHttpContext("GET");

        //    var router = new Mock<IRouter>(MockBehavior.Strict).Object;
        //    var actionContext = new ActionContext();
        //    actionContext.HttpContext = httpContext;
        //    actionContext.RouteData = new RouteData();
        //    actionContext.RouteData.Routers.Add(router);

        //    //actionContextMock.Setup(ac => ac.RouteData).Returns(new RouteData());
        //    //actionContextMock.Setup(ac => ac.RouteData.Routers).Returns(new List<IRouter>());
        //    var deviserControllerFactory = new DeviserControllerFactory(_container, scopeServiceMock.Object);
        //    var modules = moduleRepository.Get();
        //    var editModule = modules.First(m => m.ModuleAction.Any(ma => ma.ControllerName == "Edit"));
        //    var editModuleAction =
        //        editModule.ModuleAction.First(
        //            ma => ma.ModuleActionTypeId == Guid.Parse("192278B6-7BF2-40C2-A776-B9CA5FB04FBB"));
        //    var pageModule = currentPage.PageModule.First(pm => pm.ModuleId == editModule.Id);

        //    //Act
        //    var result = deviserControllerFactory.GetModuleEditResultAsString(actionContext, pageModule, editModuleAction.Id).Result;

        //    //Assert
        //    Assert.NotNull(result);
        //    Assert.True(!string.IsNullOrEmpty(result));
        //    Assert.True(!result.Contains("Module load exception"));

        //    //Clean
        //    dbContext.PageModule.RemoveRange(dbContext.PageModule);
        //    dbContext.Module.RemoveRange(dbContext.Module);
        //    dbContext.Page.RemoveRange(dbContext.Page);
        //}

        //[Fact]
        //public void GetModuleEditResultFail()
        //{
        //    //Arrange
        //    var actionContextMock = new Mock<ActionContext>();
        //    var scopeServiceMock = new Mock<IScopeService>();
        //    var pageManager = new PageManager(_container);
        //    var dbContext = _serviceProvider.GetRequiredService<DeviserDbContext>();
        //    var pageId = SetupPageAndModules();
        //    dbContext.PageModule.RemoveRange(dbContext.PageModule);
        //    dbContext.SaveChanges();
        //    var currentPage = pageManager.GetPageAndDependencies(pageId);
        //    scopeServiceMock.Setup(s => s.PageContext.CurrentPage).Returns(currentPage);
        //    actionContextMock.Setup(ac => ac.RouteData.Routers).Returns(new List<IRouter>());
        //    var deviserControllerFactory = new DeviserControllerFactory(_container, scopeServiceMock.Object);

        //    //Act
        //    var result = deviserControllerFactory.GetModuleEditResultAsString(actionContextMock.Object, new PageModule(), Guid.NewGuid()).Result;

        //    //Assert
        //    Assert.NotNull(result);
        //    Assert.True(!string.IsNullOrEmpty(result));
        //    Assert.True(result.Contains("Module load exception"));

        //    //Clean
        //    dbContext.PageModule.RemoveRange(dbContext.PageModule);
        //    dbContext.Module.RemoveRange(dbContext.Module);
        //    dbContext.Page.RemoveRange(dbContext.Page);
        //}

        private Guid SetupPageAndModules()
        {
            //Arrange
            var pageRepository   = new PageRepository(_container);
            var moduleRepository = new ModuleRepository(_container);

            var pages = TestDataRepository.GetPages();
            var page  = pages.First();

            //Create a page
            pageRepository.CreatePage(page);

            //Create modules
            var modules = TestDataRepository.GetModules();

            foreach (var module in modules)
            {
                moduleRepository.Create(module);

                if (module != null && module.ModuleAction != null)
                {
                    foreach (var moduleAction in module.ModuleAction)
                    {
                        //Create page modules
                        var pageModule = new PageModule()
                        {
                            Id                     = Guid.NewGuid(),
                            PageId                 = page.Id,
                            ContainerId            = Guid.NewGuid(),
                            InheritViewPermissions = true,
                            InheritEditPermissions = true,
                            ModuleId               = module.Id,
                            ModuleAction           = moduleAction,
                            ModulePermissions      = new List <ModulePermission>()
                            {
                                new ModulePermission
                                {
                                    Id           = Guid.NewGuid(),
                                    PageModuleId = Guid.NewGuid(),
                                    PermissionId = Guid.NewGuid(),
                                    RoleId       = Guid.NewGuid(),
                                }
                            },
                            IsDeleted = false
                        };
                        pageRepository.CreatePageModule(pageModule);
                    }
                }
            }

            return(page.Id);
        }
Пример #5
0
        public Module Create(long userId, Module toAdd)
        {
            using (var tran = new TransactionScope())
            {
                PreSave(userId, ref toAdd, Enumerations.ActionMode.Add);
                var toRet = _repository.Create(toAdd);

                //Force cash refresh for all module entries
                CacheHelper.Clear(Module);

                BlLog.Log(userId, Module, "Create module", "ModuleCreated", new object[] { toAdd.Id });
                tran.Complete();
                return(toRet);
            }
        }
Пример #6
0
        public void Should_save_new_module()
        {
            var newModule = ModuleFactory.Module(_siteId, Guid.NewGuid(), Guid.NewGuid(), "Title 3");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newModule);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var module     = repository.GetById(newModule.Id);

                Assert.NotNull(module);
            }
        }
Пример #7
0
        public void GetModuleFail()
        {//Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                moduleRepository.Create(item);
            }
            var moduleId = Guid.NewGuid();

            //Act
            var result = moduleRepository.Get(moduleId);

            //Assert
            Assert.Null(result);
        }
Пример #8
0
        public void GetContentTypeFail(string typeName)
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                moduleRepository.Create(item);
            }

            //Act
            var result = moduleRepository.Get(typeName);

            //Assert
            Assert.Null(result);

            //Clean
            dbContext.Module.RemoveRange(dbContext.Module);
        }
Пример #9
0
        public void GetEditModuleActionsFail()
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                moduleRepository.Create(item);
            }
            var moduleId = Guid.NewGuid();

            //Act
            var result = moduleRepository.GetEditModuleActions(moduleId);

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 0);

            //Clean
            dbContext.Module.RemoveRange(dbContext.Module);
        }
Пример #10
0
        public void GetModleByNameSuccess(string moduleName)
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();
            var modules          = TestDataRepository.GetModules();

            foreach (var item in modules)
            {
                moduleRepository.Create(item);
            }

            //Act
            var result = moduleRepository.Get(moduleName);

            //Assert
            Assert.NotNull(result);
            Assert.NotEqual(result.Id, Guid.Empty);
            Assert.True(result.CreatedDate > DateTime.MinValue);
            Assert.True(result.LastModifiedDate > DateTime.MinValue);

            //Clean
            dbContext.Module.RemoveRange(dbContext.Module);
        }