Пример #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 GetModulesFail()
        {
            //Arrange
            var moduleRepository = new ModuleRepository(_container);
            var dbContext        = _serviceProvider.GetRequiredService <DeviserDbContext>();

            dbContext.Module.RemoveRange(dbContext.Module);

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

            //Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 0);
        }
Пример #3
0
        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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }