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

            var result = await sut.Build(10);

            result.EventId.ShouldBe(10);
            result.CampaignId.ShouldBe(20);
            result.OrganizationId.ShouldBe(30);
        }
        public async Task Build_WithAllThreeIds_ReturnsTheAuthorizableEvent()
        {
            var sut = new AuthorizableEventEventBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>());

            var result = await sut.Build(1, 2, 3);

            result.EventId.ShouldBe(1);
            result.CampaignId.ShouldBe(2);
            result.OrganizationId.ShouldBe(3);
        }
Ejemplo n.º 3
0
        private static async Task <IAuthorizableEvent> AuthorizableEventWhenNoAssociatedUser()
        {
            var userAuthService = new Mock <IUserAuthorizationService>();

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

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

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

            cache.Set("AuthorizableEvent_1", new FakeAuthorizableEventIdContainer(), TimeSpan.FromMinutes(5));

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

            var result = await sut.Build(1, 2, 3);

            result.EventId.ShouldBe(1);
            result.CampaignId.ShouldBe(200);
            result.OrganizationId.ShouldBe(300);
        }
Ejemplo n.º 5
0
        private static async Task <IAuthorizableEvent> AuthorizableEventWhenUserAssociatedIsNotAdminOrManager()
        {
            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>());
            userAuthService.Setup(x => x.GetManagedCampaignIds()).ReturnsAsync(new List <int>());

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

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

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

            var result = await sut.Build(10);

            IAuthorizableEventIdContainer authorizableEvent;
            var foundInCache = cache.TryGetValue("AuthorizableEvent_10", out authorizableEvent);

            foundInCache.ShouldBeTrue();
            authorizableEvent.EventId.ShouldBe(10);
            authorizableEvent.CampaignId.ShouldBe(20);
            authorizableEvent.OrganizationId.ShouldBe(30);
        }