public async Task SHOULD_extract_claims_principal_and_get_user() { //Arrange MockResolverContext.With_ContextData("ClaimsPrincipal", new ClaimsPrincipalBuilder() .With_NameIdentifier("Fred").Build()); //Act await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None); //Assert MockAuthenticatedUserFactory.Mock.Verify(x => x.ExtractFromClaimsPrincipal(It.Is <ClaimsPrincipal>(y => y.HasClaim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "Fred")))); }
public async Task IF_ClaimsPrincipal_is_bogus_return_error() { //Arrange MockResolverContext.With_ContextData("ClaimsPrincipal", null); //Act var result = await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None); //Assert Assert.IsFalse(result); MockResolverContext.Mock.Verify(x => x.ReportError(It.Is <IError>(y => y.Message == AuthErrors.NotAuthenticated.ToString()))); MockAnalyticsService.VerifyTrace(AuthErrors.NotAuthenticated.ToString(), LogSeverity.Error); }
public async Task SHOULD_extract_headers_and_start_request_operation() { //Arrange MockResolverContext.With_ContextData("HttpContext", new HttpContextMockBuilder() .WithHeaders(new HeaderDictionary(new Dictionary <string, StringValues> { { "HeaderOne", "HeaderOneValue" }, { "HeaderTwo", "HeaderTwoValue" }, })).Object); //Act await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None); //Assert MockAnalyticsService.VerifyStartRequestOperation("TestCommand"); MockAnalyticsService.VerifyStartRequestOperationProperty(x => x["HeaderOne"] == "HeaderOneValue"); MockAnalyticsService.VerifyStartRequestOperationProperty(x => x["HeaderTwo"] == "HeaderTwoValue"); }