Exemplo n.º 1
0
        public void GetTab_Should_Return_A_Tab_from_cache_when_it_is_already_cached()
        {
            var            cache          = new Mock <ICache>();
            var            database       = new Mock <IDatabase>();
            ITabRepository pageRepository = new TabRepository(database.Object, cache.Object);

            const int pageId    = 1;
            var       page      = default(Tab);
            var       sampleTab = new Tab()
            {
                ID       = pageId, Title = "Test Tab", ColumnCount = 3, LayoutType = 3, VersionNo = 1,
                PageType = (int)Enumerations.PageType.PersonalTab, CreatedDate = DateTime.Now
            };

            "Given TabRepository and the requested page in cache".Context(() =>
            {
                cache.Expect(c => c.Get(CacheKeys.TabKeys.TabId(sampleTab.ID)))
                .Returns(sampleTab).AtMostOnce();
            });

            "when GetTabById is called".Do(() =>
                                           page = pageRepository.GetTabById(1));

            "it checks in the cache first and finds the object is in cache".Assert(() =>
            {
                cache.VerifyAll();
            });

            "it returns the page as expected".Assert(() =>
            {
                Assert.Equal <int>(pageId, page.ID);
            });
        }
Exemplo n.º 2
0
 public UnitOfWork(XdContext context)
 {
     _context            = context;
     AddressInformations = new AddressInformationRepository(_context);
     AppUsers            = new AppUserRepository(_context);
     AppUserRoles        = new AppUserRoleRepository(_context);
     Contacts            = new ContactRepository(_context);
     Credentials         = new CredentialsRepository(_context);
     DbTypes             = new DbTypeRepository(_context);
     Entities            = new EntityRepository(_context);
     EntityTypes         = new EntityTypeRepository(_context);
     Fields = new FieldRepository(_context);
     FieldRequirementLevels = new FieldRequirementLevelRepository(_context);
     FieldTypes             = new FieldTypeRepository(_context);
     Forms           = new FormRepository(_context);
     FormTypes       = new FormTypeRepository(_context);
     Genders         = new GenderRepository(_context);
     MaritalStatuses = new MaritalStatusRepository(_context);
     MenuItems       = new MenuItemRepository(_context);
     Roles           = new RoleRepository(_context);
     Tabs            = new TabRepository(_context);
     Titles          = new TitleRepository(_context);
     Views           = new ViewRepository(_context);
     ViewTypes       = new ViewTypeRepository(_context);
 }
Exemplo n.º 3
0
        public void InsertTab_should_insert_a_page_in_database_and_cache_it()
        {
            var            cache          = new Mock <ICache>();
            var            database       = new Mock <IDatabase>();
            ITabRepository pageRepository = new TabRepository(database.Object, cache.Object);

            const int pageId    = 1;
            Guid      userId    = Guid.NewGuid();
            var       page      = default(Tab);
            var       sampleTab = new Tab()
            {
                Title      = "Test Tab", ColumnCount = 3,
                LayoutType = 3, AspNetUser = new AspNetUser {
                    UserId = userId
                }, VersionNo = 1,
                PageType = (int)Enumerations.PageType.PersonalTab, CreatedDate = DateTime.Now
            };

            database.Expect <Tab>(d => d.Insert <AspNetUser, Tab>(
                                      It.Is <AspNetUser>(u => u.UserId == userId),
                                      It.IsAny <Action <AspNetUser, Tab> >(),
                                      It.Is <Tab>(p => p.ID == default(int))))
            .Callback(() => sampleTab.ID = pageId)
            .Returns(sampleTab)
            .AtMostOnce()
            .Verifiable();

            "Given TabRepository".Context(() =>
            {
                // It will clear items from cache
                cache.Expect(c => c.Remove(CacheKeys.UserKeys.TabsOfUser(sampleTab.AspNetUser.UserId)));
            });

            "when Insert is called".Do(() =>
                                       page = pageRepository.Insert(new Tab
            {
                Title       = sampleTab.Title,
                ColumnCount = sampleTab.ColumnCount,
                LayoutType  = sampleTab.LayoutType,
                AspNetUser  = new AspNetUser {
                    UserId = userId
                },
                VersionNo = sampleTab.VersionNo,
                PageType  = sampleTab.PageType
            }));

            ("then it should insert the page in database" +
             "and clear any cached collection of pages for the user who gets the new page" +
             "and it returns the newly inserted page").Assert(() =>
            {
                database.VerifyAll();
                cache.VerifyAll();

                Assert.Equal <int>(pageId, page.ID);
            });
        }
Exemplo n.º 4
0
        public void GetTab_Should_Return_A_Tab_from_database_when_cache_is_empty_and_then_caches_it()
        {
            var            cache          = new Mock <ICache>();
            var            database       = new Mock <IDatabase>();
            ITabRepository pageRepository = new TabRepository(database.Object, cache.Object);

            const int pageId    = 1;
            var       page      = default(Tab);
            var       sampleTab = new Tab()
            {
                ID = pageId, Title = "Test Tab", ColumnCount = 3, LayoutType = 3, VersionNo = 1, PageType = (int)Enumerations.PageType.PersonalTab, CreatedDate = DateTime.Now
            };

            database
            .Expect <IQueryable <Tab> >(d => d.Query <int, Tab>(CompiledQueries.TabQueries.GetTabById, 1))
            .Returns(new Tab[] { sampleTab }.AsQueryable()).Verifiable();

            "Given TabRepository and empty cache".Context(() =>
            {
                // cache is empty
                cache.Expect(c => c.Get(It.IsAny <string>())).Returns(default(object));
                // It will cache the Tab object afte loading from database
                cache.Expect(c => c.Add(It.Is <string>(cacheKey => cacheKey == CacheKeys.TabKeys.TabId(pageId)),
                                        It.Is <Tab>(cacheTab => object.ReferenceEquals(cacheTab, sampleTab)))).Verifiable();
            });

            "when GetTabById is called".Do(() =>
                                           page = pageRepository.GetTabById(1));

            "it checks in the cache first and finds nothing and then caches it".Assert(() =>
                                                                                       cache.VerifyAll());


            "it loads the page from database".Assert(() =>
                                                     database.VerifyAll());

            "it returns the page as expected".Assert(() =>
            {
                Assert.Equal <int>(pageId, page.ID);
            });
        }
        public override Response Execute()
        {
            // Initialize application install service -- TODO -- use DI to create kernel and get correct implementation
            if (this.parallelizationInstallationService == null)
            {
                // Build up application installation service
                var logger                         = new TextLogger();
                var connectionFactory              = new HelperConnectionFactory(this.Helper);
                var sqlRepo                        = new SqlServerRepository(connectionFactory);
                var hashConverter                  = new LegacyHashConversionService();
                var tabRepository                  = new TabRepository(connectionFactory);
                var relativityOneService           = new RelativityOneService(sqlRepo.ConfigurationRepository);
                var tabService                     = new TabService(tabRepository, relativityOneService);
                var databaseMigratorFactory        = new DatabaseMigratorFactory(connectionFactory);
                var databaseDeployer               = new DatabaseDeployer(databaseMigratorFactory, new ErrorOnlyMigrationResultHandler(logger));
                var applicationInstallationService = new ApplicationInstallationService(connectionFactory, sqlRepo, hashConverter, tabService, databaseDeployer, logger);

                var toggleProvider         = new PdbSqlToggleProvider(connectionFactory);
                var forceDeparallelization = toggleProvider.IsEnabled <DatabaseDeploymentDeparallelizationToggle>();
                if (forceDeparallelization)
                {
                    // Build up the service that checks for version
                    var versionCheckService = new VersionCheckService(new PdbVersionRepository(connectionFactory), logger);
                    this.parallelizationInstallationService = new SingletonDatabaseInstallationService(applicationInstallationService, versionCheckService, new TimeService(), logger);
                }
                else
                {
                    // Build up the service that actually runs the install process
                    this.parallelizationInstallationService = new DefaultDatabaseInstallationService(applicationInstallationService);
                }
            }

            // Install the application
            var appInstallResponse = this.parallelizationInstallationService.InstallApplication(this.Helper.GetActiveCaseID()).GetAwaiter().GetResult();

            // Return response
            return(new Response {
                Message = appInstallResponse.Message, Success = appInstallResponse.Success
            });
        }
        public void SetUp()
        {
            var connectionFactory = TestUtilities.GetIntegrationConnectionFactory();

            this.tabRepository = new TabRepository(connectionFactory);
        }