public void VerifyOwnership_ThrowsExceptionIfOwnerDoesNotMatch() { IListApplicationService service = new ListApplicationsService(null); Assert.ThrowsAsync <UnauthorizedException>(() => service.VerifyOwnership(new Application { User = "******" }, "user-id")); }
public async Task FindByOwnerIdsConvertsToLookupAndRemovesSecret() { var mockRepo = new Mock <IListApplicationRepository>(); var mockAppList = new List <Application> { new Application { Id = "1", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, new Application { Id = "2", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, new Application { Id = "3", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, new Application { Id = "3", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, }; mockRepo.Setup(x => x.ListApplicationsByOwners(It.IsAny <IEnumerable <string> >())).ReturnsAsync(mockAppList); var service = new ListApplicationsService(mockRepo.Object); var apps = await service.FindByOwnerIds(new[] { "user", "user1" }); foreach (var application in apps["user"].ToList()) { Assert.Null(application.Secret); Assert.AreEqual("user", application.User); } foreach (var application in apps["user1"].ToList()) { Assert.Null(application.Secret); Assert.AreEqual("user1", application.User); } }
public async Task VerifyOwnership_ReturnsOriginalApplicationIfUserMatches() { IListApplicationService service = new ListApplicationsService(null); var mockApp = new Application { User = "******" }; var app = await service.VerifyOwnership(mockApp, "user-id"); Assert.AreSame(mockApp, app); }
public async Task FindByIds_RemovesSecret() { var mockRepo = new Mock <IListApplicationRepository>(); var mockAppList = new List <Application> { new Application { Id = "1", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, new Application { Id = "2", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, new Application { Id = "3", Name = "test-name", Secret = "secret", User = "******", CreatedAt = DateTime.Now }, }; mockRepo.Setup(x => x.FindByIds(It.IsAny <IEnumerable <string> >())).ReturnsAsync(mockAppList); var service = new ListApplicationsService(mockRepo.Object); var apps = await service.FindByIds(new[] { "1", "2", "3" }); foreach (var application in apps.ToList()) { Assert.Null(application.Value.Secret); } }