Ejemplo n.º 1
0
        protected IDocumentDbService DbService()
        {
            if (dbService == null)
            {
                ICouchDbSettings config = new CouchDbSettings()
                {
                    DatabaseName = "integration-" + DateTime.UtcNow.Ticks,
                    Username     = "",
                    Password     = "",
                    Server       = "http://127.0.0.1:5984"
                };

                var couchDbServer = Environment.GetEnvironmentVariable(CouchDbServerEnvironmentVariable);
                if (!string.IsNullOrEmpty(couchDbServer))
                {
                    config.Server = couchDbServer;
                }

                var innerDbService = new CouchDbAccessService(config, new Mock <ILogger>().Object);
                innerDbService.Initialize().Wait();
                innerDbService.AddViews("roles", CouchDbRoleStore.GetViews()).Wait();
                innerDbService.AddViews("permissions", CouchDbPermissionStore.GetViews()).Wait();
                var auditingDbService = new AuditingDocumentDbService(new Mock <IEventService>().Object, innerDbService);
                var cachingDbService  = new CachingDocumentDbService(auditingDbService, new MemoryCache(new MemoryCacheOptions()));
                dbService = cachingDbService;
            }
            return(dbService);
        }
Ejemplo n.º 2
0
        public void GetDocument_CachesDocument()
        {
            //Arrange
            var permissions              = SetupPermissions();
            var permission               = permissions.Values.First();
            var mockDbAccessService      = SetupMockDocumentDbService(permissions);
            var cachingDocumentDbService = new CachingDocumentDbService(mockDbAccessService.Object,
                                                                        new MemoryCache(new MemoryCacheOptions()));

            //Act
            this.AssertPermissionRetrievedAsync(permission, cachingDocumentDbService).Wait();
            this.AssertPermissionRetrievedAsync(permission, cachingDocumentDbService).Wait();

            //Assert
            mockDbAccessService.Verify(dbAccessService => dbAccessService.GetDocument <Permission>(It.IsAny <string>()), Times.Once);
        }
Ejemplo n.º 3
0
        public void DeleteDocument_InvalidatesCache()
        {
            //Arrange
            var permissions              = SetupPermissions();
            var permission               = permissions.Values.First();
            var mockDbAccessService      = SetupMockDocumentDbService(permissions);
            var cachingDocumentDbService = new CachingDocumentDbService(mockDbAccessService.Object,
                                                                        new MemoryCache(new MemoryCacheOptions()));

            //Act
            AssertPermissionRetrievedAsync(permission, cachingDocumentDbService).Wait();
            cachingDocumentDbService.DeleteDocument <Permission>(permission.Identifier).Wait();
            AssertPermissionRetrievedAsync(permission, cachingDocumentDbService).Wait();

            //Assert
            mockDbAccessService.Verify(dbAccessService => dbAccessService.GetDocument <Permission>(It.IsAny <string>()), Times.Exactly(2));
        }
Ejemplo n.º 4
0
        private async Task AssertPermissionRetrievedAsync(Permission permission, CachingDocumentDbService cachingDocumentDbService)
        {
            var retrievedPermission = await cachingDocumentDbService.GetDocument <Permission>(permission.Identifier);

            Assert.Equal(permission.Id, retrievedPermission.Id);
        }