private static async Task <IAuthorizableTask> AuthorizableTaskWhenNoAssociatedUser() { var userAuthService = new Mock <IUserAuthorizationService>(); userAuthService.Setup(x => x.HasAssociatedUser).Returns(false); var authEventBuilder = new AuthorizableTaskBuilder(null, new MemoryCache(new MemoryCacheOptions()), userAuthService.Object); return(await authEventBuilder.Build(1001, 3, 4, 5)); }
public async Task Build_WithJustTaskId_ReturnsTheAuthorizableTaskFromTheDatabase() { var sut = new AuthorizableTaskBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>()); var result = await sut.Build(TaskId); result.TaskId.ShouldBe(TaskId); result.EventId.ShouldBe(10); result.CampaignId.ShouldBe(20); result.OrganizationId.ShouldBe(30); }
public async Task Build_WithAllFivesIds_ReturnsTheAuthorizableTask() { var sut = new AuthorizableTaskBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>()); var result = await sut.Build(TaskId, 3, 4, 5); result.TaskId.ShouldBe(TaskId); result.EventId.ShouldBe(3); result.CampaignId.ShouldBe(4); result.OrganizationId.ShouldBe(5); }
public async Task Build_WithJustTaskId_ReturnsTheAuthorizableTaskFromTheDatabase_WithExpectedIds_WhenPartialLinkedElements() { var sut = new AuthorizableTaskBuilder(Context, new MemoryCache(new MemoryCacheOptions()), Mock.Of <IUserAuthorizationService>()); var result = await sut.Build(TaskIdForTaskWithPartialLinks); result.TaskId.ShouldBe(TaskIdForTaskWithPartialLinks); result.EventId.ShouldBe(-1); result.CampaignId.ShouldBe(-1); result.OrganizationId.ShouldBe(30); }
public async Task Build_WithJustTaskId_ReturnsFromTheCacheWhenAvailable() { var cache = new MemoryCache(new MemoryCacheOptions()); cache.Set("AuthorizableTask_" + TaskId, new FakeAuthorizableTaskIdContainer(), TimeSpan.FromMinutes(5)); var sut = new AuthorizableTaskBuilder(Context, cache, Mock.Of <IUserAuthorizationService>()); var result = await sut.Build(TaskId); result.TaskId.ShouldBe(TaskId); result.EventId.ShouldBe(200); result.CampaignId.ShouldBe(300); result.OrganizationId.ShouldBe(400); }
private static async Task <IAuthorizableTask> AuthorizableTaskWhenUserAssociatedIsNotAdminOrManager() { 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>()); userAuthService.Setup(x => x.GetLedItineraryIds()).ReturnsAsync(new List <int>()); var authEventBuilder = new AuthorizableTaskBuilder(null, new MemoryCache(new MemoryCacheOptions()), userAuthService.Object); return(await authEventBuilder.Build(1001, 3, 4, 5)); }
public async Task Build_SetsCaches_WithTheAuthorizableTask() { var cache = new MemoryCache(new MemoryCacheOptions()); var sut = new AuthorizableTaskBuilder(Context, cache, Mock.Of <IUserAuthorizationService>()); var result = await sut.Build(TaskId); var foundInCache = cache.TryGetValue("AuthorizableTask_" + TaskId, out IAuthorizableTaskIdContainer AuthorizableTask); foundInCache.ShouldBeTrue(); AuthorizableTask.TaskId.ShouldBe(TaskId); AuthorizableTask.EventId.ShouldBe(10); AuthorizableTask.CampaignId.ShouldBe(20); AuthorizableTask.OrganizationId.ShouldBe(30); }