public async Task ValidateHandleAsync_Failed() { // Arrange this.authContext = FakeHttpContext.GetAuthorizationHandlerContextForTeamMember(); var mockMemoryCache = new Mock <IMemoryCache>(); mockMemoryCache .Setup(x => x.CreateEntry(It.IsAny <object>())) .Returns(Mock.Of <ICacheEntry>); this.policyHandler = new MustBeTeamMemberUserPolicyHandler( mockMemoryCache.Object, this.botSettings, this.memberValidationService.Object); this.memberValidationService .Setup(svc => svc.ValidateMemberAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(() => false); // Act await this.policyHandler.HandleAsync(this.authContext); // Assert Assert.IsFalse(this.authContext.HasSucceeded); }
public async Task ValidateHandleAsync_Succeed() { // Arrange this.authContext = FakeHttpContext.GetAuthorizationHandlerContextForTeamMember(); this.memoryCache = new FakeMemoryCache(); this.policyHandler = new MustBeTeamMemberUserPolicyHandler( this.memoryCache, this.botSettings, this.memberValidationService.Object); // Act await this.policyHandler.HandleAsync(this.authContext); // Assert Assert.IsTrue(this.authContext.HasSucceeded); }
public async Task ValidateHandleAsync_Failed() { // Arrange this.memoryCache .Setup(x => x.CreateEntry(It.IsAny <string>())) .Returns(Mock.Of <ICacheEntry>); this.groupMemberService .Setup(svc => svc.GetGroupMembersAsync(It.IsAny <string>())) .ReturnsAsync(() => null); this.authContext = FakeHttpContext.GetAuthorizationHandlerContextForTeamMember(); // Act await this.policyHandler.HandleAsync(this.authContext); // Assert Assert.IsFalse(this.authContext.HasSucceeded); }
public async Task ValidateHandleAsync_Succeed() { // Arrange this.memoryCache .Setup(x => x.CreateEntry(It.IsAny <string>())) .Returns(Mock.Of <ICacheEntry>); this.groupMemberService .Setup(svc => svc.GetGroupMembersAsync(It.IsAny <string>())) .Returns(Task.FromResult(AuthenticationTestData.users)); this.authContext = FakeHttpContext.GetAuthorizationHandlerContextForTeamMember(); // Act await this.policyHandler.HandleAsync(this.authContext); // Assert Assert.IsTrue(this.authContext.HasSucceeded); }