Example #1
0
 public SiteRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context           = context;
     _sites             = context.Set <SiteDbEntity>();
     _siteLocalisations = context.Set <SiteLocalisationDbEntity>();
     _mapper            = mapper;
 }
Example #2
0
 public MenuRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context               = context;
     _menus                 = context.Set <MenuDbEntity>();
     _menuItems             = context.Set <MenuItemDbEntity>();
     _menuItemLocalisations = context.Set <MenuItemLocalisationDbEntity>();
     _mapper                = mapper;
 }
Example #3
0
        private void UpdateMenuItemPermissions(WeapsyDbContext context, Guid menuItemId, IEnumerable <MenuItemPermissionDbEntity> menuItemPermissions)
        {
            var currentMenuItemPermissions = context.Set <MenuItemPermissionDbEntity>()
                                             .AsNoTracking()
                                             .Where(x => x.MenuItemId == menuItemId)
                                             .ToList();

            foreach (var currentMenuItemPermission in currentMenuItemPermissions)
            {
                var menuItemPermission = menuItemPermissions
                                         .FirstOrDefault(x => x.MenuItemId == currentMenuItemPermission.MenuItemId &&
                                                         x.RoleId == currentMenuItemPermission.RoleId);

                if (menuItemPermission == null)
                {
                    context.Remove(currentMenuItemPermission);
                }
            }

            foreach (var menuItemPermission in menuItemPermissions)
            {
                var currentPageModulePermission = currentMenuItemPermissions
                                                  .FirstOrDefault(x => x.MenuItemId == menuItemPermission.MenuItemId &&
                                                                  x.RoleId == menuItemPermission.RoleId);

                if (currentPageModulePermission == null)
                {
                    context.Add(menuItemPermission);
                }
            }
        }
Example #4
0
        private void UpdatePagePermissions(WeapsyDbContext context, Guid pageId, IEnumerable <PagePermissionDbEntity> pagePermissions)
        {
            var currentPagePermissions = context.Set <PagePermissionDbEntity>()
                                         .AsNoTracking()
                                         .Where(x => x.PageId == pageId)
                                         .ToList();

            foreach (var currentPagePermission in currentPagePermissions)
            {
                var pagePermission = pagePermissions
                                     .FirstOrDefault(x => x.PageId == currentPagePermission.PageId &&
                                                     x.RoleId == currentPagePermission.RoleId &&
                                                     x.Type == currentPagePermission.Type);

                if (pagePermission == null)
                {
                    context.Remove(currentPagePermission);
                }
            }

            foreach (var pagePermission in pagePermissions)
            {
                var existingPagePermissionDbEntity = currentPagePermissions
                                                     .FirstOrDefault(x => x.PageId == pagePermission.PageId &&
                                                                     x.RoleId == pagePermission.RoleId &&
                                                                     x.Type == pagePermission.Type);

                if (existingPagePermissionDbEntity == null)
                {
                    context.Add(pagePermission);
                }
            }
        }
Example #5
0
        private void LoadMenuItems(WeapsyDbContext context, MenuDbEntity menu)
        {
            if (menu == null)
            {
                return;
            }

            menu.MenuItems = context.Set <MenuItemDbEntity>()
                             .Include(x => x.MenuItemLocalisations)
                             .Include(x => x.MenuItemPermissions)
                             .Where(x => x.MenuId == menu.Id && x.Status != MenuItemStatus.Deleted)
                             .ToList();
        }
Example #6
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();
        }
Example #7
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);
        }
        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);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
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;
 }
Example #12
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);
        }
Example #13
0
        private void UpdateSiteLocalisations(WeapsyDbContext context, IEnumerable <SiteLocalisationDbEntity> siteLocalisations)
        {
            foreach (var siteLocalisation in siteLocalisations)
            {
                var currentSiteLocalisation = context.Set <SiteLocalisationDbEntity>()
                                              .AsNoTracking()
                                              .FirstOrDefault(x =>
                                                              x.SiteId == siteLocalisation.SiteId &&
                                                              x.LanguageId == siteLocalisation.LanguageId);

                if (currentSiteLocalisation == null)
                {
                    context.Add(siteLocalisation);
                }
                else
                {
                    context.Entry(siteLocalisation).State = EntityState.Modified;
                }
            }
        }
Example #14
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;
                }
            }
        }
        public void SetUp()
        {
            _contextOptions = Shared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _siteId            = Guid.NewGuid();
                _languageId1       = Guid.NewGuid();
                _languageId2       = Guid.NewGuid();
                _deletedLanguageId = Guid.NewGuid();

                context.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
                {
                    Id     = _deletedLanguageId,
                    Status = LanguageStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #16
0
        public void SetUp()
        {
            _contextOptions = DbContextShared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _siteId          = Guid.NewGuid();
                _moduleId1       = Guid.NewGuid();
                _moduleId2       = Guid.NewGuid();
                _moduleTypeId1   = Guid.NewGuid();
                _moduleTypeId2   = Guid.NewGuid();
                _deletedModuleId = Guid.NewGuid();

                context.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
                {
                    Id     = _deletedModuleId,
                    Status = ModuleStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #17
0
        private void UpdatePageModules(WeapsyDbContext context, IEnumerable <PageModuleDbEntity> pageModules)
        {
            foreach (var pageModule in pageModules)
            {
                var currentPageModule = context.Set <PageModuleDbEntity>()
                                        .AsNoTracking()
                                        .FirstOrDefault(x =>
                                                        x.ModuleId == pageModule.ModuleId &&
                                                        x.PageId == pageModule.PageId);

                if (currentPageModule == null)
                {
                    context.Add(pageModule);
                }
                else
                {
                    context.Entry(pageModule).State = EntityState.Modified;
                    UpdatePageModuleLocalisations(context, pageModule.PageModuleLocalisations);
                    UpdatePageModulePermissions(context, pageModule.Id, pageModule.PageModulePermissions);
                }
            }
        }
Example #18
0
        public void SetUp()
        {
            _contextOptions = Shared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _themeId1       = Guid.NewGuid();
                _themeId2       = Guid.NewGuid();
                _deletedThemeId = Guid.NewGuid();

                context.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
                {
                    Id     = _deletedThemeId,
                    Status = ThemeStatus.Deleted
                }
                );

                context.SaveChanges();
            }
        }
Example #19
0
        public void SetUp()
        {
            _contextOptions = Shared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _siteId1       = Guid.NewGuid();
                _siteId2       = Guid.NewGuid();
                _deletedSiteId = Guid.NewGuid();

                context.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
                {
                    Id     = _deletedSiteId,
                    Status = SiteStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #20
0
        public void SetUp()
        {
            _contextOptions = Shared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _moduleTypeId1       = Guid.NewGuid();
                _moduleTypeId2       = Guid.NewGuid();
                _deletedModuleTypeId = Guid.NewGuid();

                context.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
                {
                    Id     = _deletedModuleTypeId,
                    Status = ModuleTypeStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #21
0
        private void UpdatePageLocalisations(WeapsyDbContext context, Guid pageId, IEnumerable <PageLocalisationDbEntity> pageLocalisations)
        {
            var currentPageLocalisations = context.PageLocalisations
                                           .AsNoTracking()
                                           .Where(x => x.PageId == pageId)
                                           .ToList();

            foreach (var currentPageLocalisation in currentPageLocalisations)
            {
                var pageLocalisation = pageLocalisations
                                       .FirstOrDefault(x => x.LanguageId == currentPageLocalisation.LanguageId);

                if (pageLocalisation == null)
                {
                    context.Remove(currentPageLocalisation);
                }
            }

            foreach (var pageLocalisation in pageLocalisations)
            {
                var currentPageLocalisation = context.Set <PageLocalisationDbEntity>()
                                              .AsNoTracking()
                                              .FirstOrDefault(x =>
                                                              x.PageId == pageLocalisation.PageId &&
                                                              x.LanguageId == pageLocalisation.LanguageId);

                if (currentPageLocalisation == null)
                {
                    context.Add(pageLocalisation);
                }
                else
                {
                    context.Entry(pageLocalisation).State = EntityState.Modified;
                }
            }
        }
Example #22
0
 public LanguageRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context  = context;
     _entities = context.Set <LanguageDbEntity>();
     _mapper   = mapper;
 }
Example #23
0
        public void SetUp()
        {
            _contextOptions = Shared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _siteId        = Guid.NewGuid();
                _pageId1       = Guid.NewGuid();
                _pageId2       = Guid.NewGuid();
                _moduleId1     = Guid.NewGuid();
                _pageModuleId1 = Guid.NewGuid();
                _languageId1   = Guid.NewGuid();
                _deletedPageId = Guid.NewGuid();

                context.Set <PageDbEntity>().AddRange(
                    new PageDbEntity
                {
                    SiteId      = _siteId,
                    Id          = _pageId1,
                    Name        = "Name 1",
                    Url         = "Url 1",
                    Status      = PageStatus.Active,
                    PageModules = new List <PageModuleDbEntity>
                    {
                        new PageModuleDbEntity
                        {
                            PageId   = _pageId1,
                            ModuleId = _moduleId1,
                            Id       = _pageModuleId1,
                            Title    = "Title 1",
                            Status   = PageModuleStatus.Active,
                            PageModuleLocalisations = new List <PageModuleLocalisationDbEntity>
                            {
                                new PageModuleLocalisationDbEntity
                                {
                                    PageModuleId = _pageModuleId1,
                                    LanguageId   = _languageId1
                                },
                                new PageModuleLocalisationDbEntity
                                {
                                    PageModuleId = _pageModuleId1,
                                    LanguageId   = Guid.NewGuid()
                                }
                            }
                        },
                        new PageModuleDbEntity
                        {
                            PageId   = _pageId1,
                            ModuleId = Guid.NewGuid(),
                            Id       = Guid.NewGuid(),
                            Title    = "Title 2",
                            Status   = PageModuleStatus.Deleted
                        }
                    }
                },
                    new PageDbEntity
                {
                    SiteId = _siteId,
                    Id     = _pageId2,
                    Name   = "Name 2",
                    Url    = "Url 2",
                    Status = PageStatus.Active
                },
                    new PageDbEntity
                {
                    Id     = _deletedPageId,
                    Status = PageStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #24
0
 public ModuleRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context  = context;
     _entities = context.Set <ModuleDbEntity>();
     _mapper   = mapper;
 }
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

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

            _siteId      = Guid.NewGuid();
            _menuId1     = Guid.NewGuid();
            _menuId2     = Guid.NewGuid();
            _menuItemId1 = Guid.NewGuid();
            _menuItemId2 = Guid.NewGuid();
            _language1   = Guid.NewGuid();

            dbContext.Set <MenuDbEntity>().AddRange(
                new MenuDbEntity
            {
                SiteId    = _siteId,
                Id        = _menuId1,
                Name      = "Menu 1",
                Status    = MenuStatus.Active,
                MenuItems = new List <MenuItemDbEntity>
                {
                    new MenuItemDbEntity
                    {
                        MenuId = _menuId1,
                        Id     = _menuItemId1,
                        Text   = "Menu Item 1",
                        Status = MenuItemStatus.Active,
                        MenuItemLocalisations = new List <MenuItemLocalisationDbEntity>
                        {
                            new MenuItemLocalisationDbEntity
                            {
                                MenuItemId = _menuItemId1,
                                LanguageId = _language1,
                                Text       = "Menu Item 1 Localisation 1"
                            },
                            new MenuItemLocalisationDbEntity
                            {
                                MenuItemId = _menuItemId1,
                                LanguageId = Guid.NewGuid(),
                                Text       = "Menu Item 1 Localisation 2"
                            }
                        }
                    },
                    new MenuItemDbEntity
                    {
                        MenuId = _menuId1,
                        Id     = _menuItemId2,
                        Text   = "Menu Item 2",
                        Status = MenuItemStatus.Deleted
                    }
                }
            },
                new MenuDbEntity
            {
                SiteId = _siteId,
                Id     = _menuId2,
                Name   = "Menu 2",
                Status = MenuStatus.Active
            },
                new MenuDbEntity
            {
                Status = MenuStatus.Deleted
            }
                );

            dbContext.SaveChanges();

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

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

            _sut = new MenuRepository(dbContext, mapperMock.Object);
        }
Example #26
0
        public void SetUp()
        {
            _contextOptions = DbContextShared.CreateContextOptions();

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                _siteId        = Guid.NewGuid();
                _menuId1       = Guid.NewGuid();
                _menuId2       = Guid.NewGuid();
                _menuItemId1   = Guid.NewGuid();
                _menuItemId2   = Guid.NewGuid();
                _language1     = Guid.NewGuid();
                _deletedMenuId = Guid.NewGuid();

                context.Set <MenuDbEntity>().AddRange(
                    new MenuDbEntity
                {
                    SiteId    = _siteId,
                    Id        = _menuId1,
                    Name      = "Menu 1",
                    Status    = MenuStatus.Active,
                    MenuItems = new List <MenuItemDbEntity>
                    {
                        new MenuItemDbEntity
                        {
                            MenuId = _menuId1,
                            Id     = _menuItemId1,
                            Text   = "Menu Item 1",
                            Status = MenuItemStatus.Active,
                            MenuItemLocalisations = new List <MenuItemLocalisationDbEntity>
                            {
                                new MenuItemLocalisationDbEntity
                                {
                                    MenuItemId = _menuItemId1,
                                    LanguageId = _language1,
                                    Text       = "Menu Item 1 Localisation 1"
                                },
                                new MenuItemLocalisationDbEntity
                                {
                                    MenuItemId = _menuItemId1,
                                    LanguageId = Guid.NewGuid(),
                                    Text       = "Menu Item 1 Localisation 2"
                                }
                            }
                        },
                        new MenuItemDbEntity
                        {
                            MenuId = _menuId1,
                            Id     = _menuItemId2,
                            Text   = "Menu Item 2",
                            Status = MenuItemStatus.Deleted
                        }
                    }
                },
                    new MenuDbEntity
                {
                    SiteId = _siteId,
                    Id     = _menuId2,
                    Name   = "Menu 2",
                    Status = MenuStatus.Active
                },
                    new MenuDbEntity
                {
                    Id     = _deletedMenuId,
                    Status = MenuStatus.Deleted
                }
                    );

                context.SaveChanges();
            }
        }
Example #27
0
 public AppRepository(WeapsyDbContext context, IMapper mapper)
 {
     _context  = context;
     _entities = context.Set <AppDbEntity>();
     _mapper   = mapper;
 }
Example #28
0
        public void SetUp()
        {
            var optionsBuilder = new DbContextOptionsBuilder <WeapsyDbContext>();

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

            _siteId        = Guid.NewGuid();
            _pageId1       = Guid.NewGuid();
            _pageId2       = Guid.NewGuid();
            _moduleId1     = Guid.NewGuid();
            _pageModuleId1 = Guid.NewGuid();
            _languageId1   = Guid.NewGuid();

            dbContext.Set <PageDbEntity>().AddRange(
                new PageDbEntity
            {
                SiteId      = _siteId,
                Id          = _pageId1,
                Name        = "Name 1",
                Url         = "Url 1",
                Status      = PageStatus.Active,
                PageModules = new List <PageModuleDbEntity>
                {
                    new PageModuleDbEntity
                    {
                        PageId   = _pageId1,
                        ModuleId = _moduleId1,
                        Id       = _pageModuleId1,
                        Title    = "Title 1",
                        Status   = PageModuleStatus.Active,
                        PageModuleLocalisations = new List <PageModuleLocalisationDbEntity>
                        {
                            new PageModuleLocalisationDbEntity
                            {
                                PageModuleId = _pageModuleId1,
                                LanguageId   = _languageId1
                            },
                            new PageModuleLocalisationDbEntity
                            {
                                PageModuleId = _pageModuleId1,
                                LanguageId   = Guid.NewGuid()
                            }
                        }
                    },
                    new PageModuleDbEntity
                    {
                        PageId   = _pageId1,
                        ModuleId = Guid.NewGuid(),
                        Id       = Guid.NewGuid(),
                        Title    = "Title 2",
                        Status   = PageModuleStatus.Deleted
                    }
                }
            },
                new PageDbEntity
            {
                SiteId = _siteId,
                Id     = _pageId2,
                Name   = "Name 2",
                Url    = "Url 2",
                Status = PageStatus.Active
            },
                new PageDbEntity
            {
                Status = PageStatus.Deleted
            }
                );

            dbContext.SaveChanges();

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

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

            _sut = new PageRepository(dbContext, mapperMock.Object);
        }