Exemplo n.º 1
0
        public void Should_return_all_moduleTypes()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository  = new ModuleTypeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var moduleTypes = repository.GetAll();

                Assert.AreEqual(2, moduleTypes.Count);
            }
        }
Exemplo n.º 2
0
        public void Should_return_module_type_by_id()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleTypeRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var moduleType = repository.GetById(_moduleTypeId1);

                Assert.NotNull(moduleType);
            }
        }
Exemplo n.º 3
0
        public void Should_return_null_if_module_type_is_deleted()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleTypeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var moduleType = repository.GetById(_deletedModuleTypeId);

                Assert.Null(moduleType);
            }
        }
Exemplo n.º 4
0
 public void Should_return_model()
 {
     using (var context = new WeapsyDbContext(_contextOptions))
     {
         var handler = new GetEmailAccountHandler(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
         var model   = handler.RetrieveAsync(new GetEmailAccount {
             SiteId = _siteId, Id = _emailAccountId
         });
         Assert.NotNull(model);
     }
 }
Exemplo n.º 5
0
 public PageRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context                 = context;
     _pages                   = context.Set <PageDbEntity>();
     _pageLocalisations       = context.Set <PageLocalisationDbEntity>();
     _pageModules             = context.Set <PageModuleDbEntity>();
     _pageModuleLocalisations = context.Set <PageModuleLocalisationDbEntity>();
     _pagePermissions         = context.Set <PagePermissionDbEntity>();
     _pageModulePermissions   = context.Set <PageModulePermissionDbEntity>();
     _mapper                  = mapper;
 }
Exemplo n.º 6
0
        public static Guid GetUserId(this IHttpContextAccessor httpContextAccessor, WeapsyDbContext dbContext)
        {
            if (httpContextAccessor.HttpContext != null && httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            {
                return(dbContext.Users
                       .Where(x => x.UserName == httpContextAccessor.HttpContext.User.Identity.Name)
                       .Select(x => x.Id)
                       .FirstOrDefault());
            }

            return(Guid.Empty);
        }
Exemplo n.º 7
0
        public void Should_return_languages_id_list()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var list       = repository.GetLanguagesIdList(_siteId);

                Assert.AreEqual(new List <Guid> {
                    _languageId1, _languageId2
                }, list);
            }
        }
Exemplo n.º 8
0
        public void Should_return_all_pages_with_no_deleted_page_modules()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new PageRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var pages      = repository.GetAll(_siteId);

                foreach (var page in pages)
                {
                    Assert.AreEqual(0, page.PageModules.Count(x => x.Status == PageModuleStatus.Deleted));
                }
            }
        }
Exemplo n.º 9
0
        private void LoadActivePageModules(WeapsyDbContext context, PageDbEntity pageDbEntity)
        {
            if (pageDbEntity == null)
            {
                return;
            }

            pageDbEntity.PageModules = context.Set <PageModuleDbEntity>()
                                       .Include(y => y.PageModuleLocalisations)
                                       .Include(y => y.PageModulePermissions)
                                       .Where(x => x.PageId == pageDbEntity.Id && x.Status != PageModuleStatus.Deleted)
                                       .ToList();
        }
Exemplo n.º 10
0
        private void LoadMenuItems(WeapsyDbContext context, MenuDbEntity menu)
        {
            if (menu == null)
            {
                return;
            }

            menu.MenuItems = context.MenuItems
                             .Include(x => x.MenuItemLocalisations)
                             .Include(x => x.MenuItemPermissions)
                             .Where(x => x.MenuId == menu.Id && x.Status != MenuItemStatus.Deleted)
                             .ToList();
        }
Exemplo n.º 11
0
        public void Should_return_all_menus_with_no_deleted_menu_items()
        {
            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new MenuRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var menus      = repository.GetAll(_siteId);

                foreach (var menu in menus)
                {
                    Assert.AreEqual(0, menu.MenuItems.Where(x => x.Status == MenuItemStatus.Deleted).Count());
                }
            }
        }
Exemplo n.º 12
0
        private async Task <ICollection <ZoneModel> > CreateZones(WeapsyDbContext context, Page page, Dictionary <PermissionType, IEnumerable <string> > roles, Guid languageId)
        {
            var result = new List <ZoneModel>();

            var zones = page.PageModules.Where(x => x.Status == PageModuleStatus.Active).GroupBy(x => x.Zone);

            foreach (var zone in zones)
            {
                var zoneModel = CreateZone(context, zone, roles, languageId);
                result.Add(await zoneModel);
            }

            return(result);
        }
Exemplo n.º 13
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            var dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _siteId        = Guid.NewGuid();
            _moduleId1     = Guid.NewGuid();
            _moduleId2     = Guid.NewGuid();
            _moduleTypeId1 = Guid.NewGuid();
            _moduleTypeId2 = Guid.NewGuid();

            dbContext.Set <ModuleDbEntity>().AddRange(
                new ModuleDbEntity
            {
                SiteId       = _siteId,
                Id           = _moduleId1,
                ModuleTypeId = _moduleTypeId1,
                Title        = "Title 1",
                Status       = ModuleStatus.Active
            },
                new ModuleDbEntity
            {
                SiteId       = _siteId,
                Id           = _moduleId2,
                ModuleTypeId = _moduleTypeId2,
                Title        = "Title 2",
                Status       = ModuleStatus.Active
            },
                new ModuleDbEntity
            {
                Status = ModuleStatus.Deleted
            }
                );

            dbContext.SaveChanges();

            var mapperMock = new Mock <AutoMapper.IMapper>();

            mapperMock.Setup(x => x.Map <ModuleDbEntity>(It.IsAny <Module>())).Returns(new ModuleDbEntity());
            mapperMock.Setup(x => x.Map <Module>(It.IsAny <ModuleDbEntity>())).Returns(new Module());
            mapperMock.Setup(x => x.Map <ICollection <Module> >(It.IsAny <ICollection <ModuleDbEntity> >())).Returns(new List <Module>
            {
                ModuleFactory.Module(_siteId, _moduleTypeId1, _moduleId1, "Title"),
                ModuleFactory.Module(_siteId, _moduleTypeId2, _moduleId2, "Title")
            });

            _sut = new ModuleRepository(dbContext, mapperMock.Object);
        }
Exemplo n.º 14
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            _dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _siteId      = Guid.NewGuid();
            _languageId1 = Guid.NewGuid();
            _languageId2 = Guid.NewGuid();

            _dbContext.Set <LanguageDbEntity>().AddRange(
                new LanguageDbEntity
            {
                SiteId      = _siteId,
                Id          = _languageId1,
                Name        = "Language Name 1",
                CultureName = "ab1",
                Url         = "ab1",
                Status      = LanguageStatus.Active
            },
                new LanguageDbEntity
            {
                SiteId      = _siteId,
                Id          = _languageId2,
                Name        = "Language Name 2",
                CultureName = "ab2",
                Url         = "ab2",
                Status      = LanguageStatus.Hidden
            },
                new LanguageDbEntity
            {
                Status = LanguageStatus.Deleted
            }
                );

            _dbContext.SaveChanges();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <LanguageDbEntity>(It.IsAny <Language>())).Returns(new LanguageDbEntity());
            mapperMock.Setup(x => x.Map <Language>(It.IsAny <LanguageDbEntity>())).Returns(new Language());
            mapperMock.Setup(x => x.Map <ICollection <Language> >(It.IsAny <ICollection <LanguageDbEntity> >())).Returns(new List <Language>
            {
                LanguageFactory.Language(_siteId, _languageId1, "Name", "CultureName", "Url"),
                LanguageFactory.Language(_siteId, _languageId2, "Name", "CultureName", "Url")
            });

            _sut = new LanguageRepository(_dbContext, mapperMock.Object);
        }
Exemplo n.º 15
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            _dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _themeId1 = Guid.NewGuid();
            _themeId2 = Guid.NewGuid();

            _dbContext.Set <ThemeDbEntity>().AddRange
            (
                new ThemeDbEntity
            {
                Id          = _themeId1,
                Name        = "Name 1",
                Description = "Description 1",
                Folder      = "Folder 1",
                Status      = ThemeStatus.Active
            },
                new ThemeDbEntity
            {
                Id          = _themeId2,
                Name        = "Name 2",
                Description = "Description 2",
                Folder      = "Folder 2",
                Status      = ThemeStatus.Active
            },
                new ThemeDbEntity
            {
                Status = ThemeStatus.Deleted
            }
            );

            _dbContext.SaveChanges();

            var mapperMock = new Mock <AutoMapper.IMapper>();

            mapperMock.Setup(x => x.Map <ThemeDbEntity>(It.IsAny <Theme>())).Returns(new ThemeDbEntity());
            mapperMock.Setup(x => x.Map <Theme>(It.IsAny <ThemeDbEntity>())).Returns(new Theme());
            mapperMock.Setup(x => x.Map <ICollection <Theme> >(It.IsAny <ICollection <ThemeDbEntity> >())).Returns(new List <Theme>
            {
                ThemeFactory.Theme(_themeId1, "Name", "Description", "Folder"),
                ThemeFactory.Theme(_themeId2, "Name", "Description", "Folder")
            });

            _sut = new ThemeRepository(_dbContext, mapperMock.Object);
        }
Exemplo n.º 16
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            var dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _siteId1 = Guid.NewGuid();
            _siteId2 = Guid.NewGuid();

            dbContext.Set <SiteDbEntity>().AddRange(
                new SiteDbEntity
            {
                Id     = _siteId1,
                Name   = "Name 1",
                Title  = "Title 1",
                Url    = "Url 1",
                Status = SiteStatus.Active
            },
                new SiteDbEntity
            {
                Id     = _siteId2,
                Name   = "Name 2",
                Title  = "Title 2",
                Url    = "Url 2",
                Status = SiteStatus.Active
            },
                new SiteDbEntity
            {
                Status = SiteStatus.Deleted
            }
                );

            dbContext.SaveChanges();

            var mapperMock = new Mock <AutoMapper.IMapper>();

            mapperMock.Setup(x => x.Map <SiteDbEntity>(It.IsAny <Site>())).Returns(new SiteDbEntity());
            mapperMock.Setup(x => x.Map <Site>(It.IsAny <SiteDbEntity>())).Returns(new Site());
            mapperMock.Setup(x => x.Map <IList <Site> >(It.IsAny <IList <SiteDbEntity> >())).Returns(new List <Site>
            {
                SiteFactory.Site(_siteId1, "Name"),
                SiteFactory.Site(_siteId2, "Name")
            });

            _sut = new SiteRepository(dbContext, mapperMock.Object);
        }
Exemplo n.º 17
0
        private void UpdateMenuItems(WeapsyDbContext context, IEnumerable <MenuItemDbEntity> menuItemDbEntities)
        {
            foreach (var menuItemDbEntity in menuItemDbEntities)
            {
                var currentMenuItem = context.MenuItems.AsNoTracking().FirstOrDefault(x => x.Id == menuItemDbEntity.Id);

                if (currentMenuItem == null)
                {
                    context.Add(menuItemDbEntity);
                }
                else
                {
                    context.Entry(menuItemDbEntity).State = EntityState.Modified;
                    UpdateMenuItemLocalisations(context, currentMenuItem.Id, menuItemDbEntity.MenuItemLocalisations);
                    UpdateMenuItemPermissions(context, currentMenuItem.Id, menuItemDbEntity.MenuItemPermissions);
                }
            }
        }
Exemplo n.º 18
0
        public void Should_save_new_menu()
        {
            var newMenu = MenuFactory.Menu(_siteId, Guid.NewGuid(), "Menu 3", "Item", "");

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

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new MenuRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var menu       = repository.GetById(_siteId, newMenu.Id);

                Assert.NotNull(menu);
            }
        }
Exemplo n.º 19
0
        public void Should_save_new_language()
        {
            var newLanguage = LanguageFactory.Language(_siteId, Guid.NewGuid(), "Name", "CultureName", "Url");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newLanguage);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new LanguageRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var language   = repository.GetById(_siteId, newLanguage.Id);

                Assert.NotNull(language);
            }
        }
Exemplo n.º 20
0
        private void UpdateMenuItemLocalisations(WeapsyDbContext context, IEnumerable <MenuItemLocalisationDbEntity> menuItemLocalisationDbEntities)
        {
            foreach (var menuItemLocalisationDbEntity in menuItemLocalisationDbEntities)
            {
                var currentMenuItemLocalisation = context.MenuItemLocalisations.AsNoTracking()
                                                  .FirstOrDefault(x => x.MenuItemId == menuItemLocalisationDbEntity.MenuItemId &&
                                                                  x.LanguageId == menuItemLocalisationDbEntity.LanguageId);

                if (currentMenuItemLocalisation == null)
                {
                    context.Add(menuItemLocalisationDbEntity);
                }
                else
                {
                    context.Entry(menuItemLocalisationDbEntity).State = EntityState.Modified;
                }
            }
        }
Exemplo n.º 21
0
        public void Should_save_new_site()
        {
            var newSite = SiteFactory.CreateNew(Guid.NewGuid(), "Name 3");

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

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var language   = repository.GetById(newSite.Id);

                Assert.NotNull(language);
            }
        }
Exemplo n.º 22
0
        public void Should_save_new_theme()
        {
            var newTheme = ThemeFactory.Theme(Guid.NewGuid(), "Name 3", "Description 3", "Folder 3");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newTheme);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ThemeRepository(Shared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var theme      = repository.GetById(newTheme.Id);

                Assert.NotNull(theme);
            }
        }
Exemplo n.º 23
0
        public void Should_save_new_page()
        {
            var newPage = PageFactory.Page(_siteId, Guid.NewGuid(), "Name 3");

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

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var page       = repository.GetById(_siteId, newPage.Id);

                Assert.NotNull(page);
            }
        }
Exemplo n.º 24
0
        public void Should_save_new_moduleType()
        {
            var newModuleType = ModuleTypeFactory.ModuleType(Guid.NewGuid(), "Name 3", "Title 3", "Description 3");

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

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleTypeRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var moduleType = repository.GetById(newModuleType.Id);

                Assert.NotNull(moduleType);
            }
        }
Exemplo n.º 25
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

            optionsBuilder.UseInMemoryDatabase();
            var dbContext = new WeapsyDbContext(optionsBuilder.Options);

            _moduleTypeId1 = Guid.NewGuid();
            _moduleTypeId2 = Guid.NewGuid();

            dbContext.Set <ModuleTypeDbEntity>().AddRange(
                new ModuleTypeDbEntity
            {
                Id          = _moduleTypeId1,
                Name        = "Name 1",
                Title       = "Title 1",
                Description = "Description 1",
                Status      = ModuleTypeStatus.Active
            },
                new ModuleTypeDbEntity
            {
                Id          = _moduleTypeId2,
                Name        = "Name 2",
                Title       = "Title 2",
                Description = "Description 2",
                Status      = ModuleTypeStatus.Active
            },
                new ModuleTypeDbEntity
            {
                Status = ModuleTypeStatus.Deleted
            }
                );

            dbContext.SaveChanges();

            var mapperMock = new Moq.Mock <AutoMapper.IMapper>();

            mapperMock.Setup(x => x.Map <ModuleTypeDbEntity>(Moq.It.IsAny <ModuleType>())).Returns(new ModuleTypeDbEntity());
            mapperMock.Setup(x => x.Map <ModuleType>(Moq.It.IsAny <ModuleTypeDbEntity>())).Returns(new ModuleType());

            _sut = new ModuleTypeRepository(dbContext, mapperMock.Object);
        }
Exemplo n.º 26
0
        private void UpdatePageModuleLocalisations(WeapsyDbContext context, IEnumerable <PageModuleLocalisationDbEntity> pageModuleLocalisations)
        {
            foreach (var pageModuleLocalisation in pageModuleLocalisations)
            {
                var currentPageModuleLocalisation = context.Set <PageModuleLocalisationDbEntity>()
                                                    .AsNoTracking()
                                                    .FirstOrDefault(x =>
                                                                    x.PageModuleId == pageModuleLocalisation.PageModuleId &&
                                                                    x.LanguageId == pageModuleLocalisation.LanguageId);

                if (currentPageModuleLocalisation == null)
                {
                    context.Add(pageModuleLocalisation);
                }
                else
                {
                    context.Entry(pageModuleLocalisation).State = EntityState.Modified;
                }
            }
        }
Exemplo n.º 27
0
        public void Should_update_page()
        {
            const string newPageName = "New Name 1";

            var pageToUpdate = PageFactory.Page(_siteId, _pageId1, newPageName);

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(pageToUpdate);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository  = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedPage = repository.GetById(_siteId, _pageId1);

                Assert.AreEqual(newPageName, updatedPage.Name);
            }
        }
Exemplo n.º 28
0
        public void Should_update_moduleType()
        {
            const string newModuleTypeTitle = "New Title 1";

            var moduleTypeToUpdate = ModuleTypeFactory.ModuleType(_moduleTypeId1, "Name 1", newModuleTypeTitle, "Description 1");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new ModuleTypeRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(moduleTypeToUpdate);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository        = new ModuleTypeRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedModuleType = repository.GetById(_moduleTypeId1);

                Assert.AreEqual(newModuleTypeTitle, updatedModuleType.Title);
            }
        }
Exemplo n.º 29
0
        private Page GetPage(WeapsyDbContext context, Guid siteId, Guid pageId)
        {
            var page = context.Pages
                       .Include(x => x.PageLocalisations)
                       .Include(x => x.PagePermissions)
                       .FirstOrDefault(x => x.SiteId == siteId && x.Id == pageId && x.Status == PageStatus.Active);

            if (page == null)
            {
                return(null);
            }

            page.PageModules = context.PageModules
                               .Include(y => y.PageModuleLocalisations)
                               .Include(y => y.PageModulePermissions)
                               .Where(x => x.PageId == pageId && x.Status == PageModuleStatus.Active)
                               .ToList();

            return(page);
        }
Exemplo n.º 30
0
        public void Should_update_site()
        {
            const string newSiteName = "New Title 1";

            var siteToUpdate = SiteFactory.CreateNew(_siteId1, newSiteName);

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Update(siteToUpdate);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository  = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var updatedSite = repository.GetById(_siteId1);

                Assert.AreEqual(newSiteName, updatedSite.Name);
            }
        }