public async Task Build_WithJustOrganizationId_ReturnsTheAuthorizableOrganizationFromTheDatabase()
        {
            var sut = new AuthorizableOrganizationBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>());

            var result = await sut.Build(20);

            result.OrganizationId.ShouldBe(20);
        }
        public async Task Build_WithBothIds_ReturnsTheAuthorizableOrganization()
        {
            var sut = new AuthorizableOrganizationBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>());

            var result = await sut.Build(1);

            result.OrganizationId.ShouldBe(1);
        }
Пример #3
0
        private static async Task <IAuthorizableOrganization> AuthorizableOrganizationWhenNoAssociatedUser()
        {
            var userAuthService = new Mock <IUserAuthorizationService>();

            userAuthService.Setup(x => x.HasAssociatedUser).Returns(false);

            var authEventBuilder = new AuthorizableOrganizationBuilder(null, new MemoryCache(new MemoryCacheOptions()), userAuthService.Object);

            return(await authEventBuilder.Build(1));
        }
        public async Task Build_WithJustOrganizationId_ReturnsFromTheCacheWhenAvailable()
        {
            var cache = new MemoryCache(new MemoryCacheOptions());

            cache.Set("AuthorizableOrganization_1", new FakeAuthorizableOrganizationIdContainer(), TimeSpan.FromMinutes(5));

            var sut = new AuthorizableOrganizationBuilder(Context, cache, Mock.Of <IUserAuthorizationService>());

            var result = await sut.Build(1);

            result.OrganizationId.ShouldBe(1);
        }
Пример #5
0
        private static async Task <IAuthorizableOrganization> AuthorizableOrganizationWhenUserAssociatedIsNotAdminOrManager()
        {
            var userAuthService = new Mock <IUserAuthorizationService>();

            userAuthService.Setup(x => x.HasAssociatedUser).Returns(true);
            userAuthService.Setup(x => x.IsSiteAdmin).Returns(false);
            userAuthService.Setup(x => x.IsOrganizationAdmin(It.IsAny <int>())).Returns(false);
            userAuthService.Setup(x => x.GetManagedEventIds()).ReturnsAsync(new List <int>());

            var authEventBuilder = new AuthorizableOrganizationBuilder(null, new MemoryCache(new MemoryCacheOptions()), userAuthService.Object);

            return(await authEventBuilder.Build(1));
        }
        public async Task Build_SetsCaches_WithTheAuthorizableOrganization()
        {
            var cache = new MemoryCache(new MemoryCacheOptions());

            var sut = new AuthorizableOrganizationBuilder(Context, cache, Mock.Of <IUserAuthorizationService>());

            var result = await sut.Build(20);

            var foundInCache = cache.TryGetValue("AuthorizableOrganization_20", out IAuthorizableOrganizationIdContainer AuthorizableOrganization);

            foundInCache.ShouldBeTrue();

            AuthorizableOrganization.OrganizationId.ShouldBe(20);
        }