Beispiel #1
0
        public async Task IF_command_handler_cannot_be_found_SHOULD_throw()
        {
            //Arrange
            MockResolverContext.With_Service <IVoidAuthenticatedCommandHandler <TestCommand, IAuthenticatedUser> >(null);

            //Act
            Assert.ThrowsAsync <ArgumentException>(async() =>
                                                   await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None));
        }
Beispiel #2
0
        public async Task IF_command_cannot_be_found_SHOULD_throw()
        {
            //Arrange
            MockResolverContext.With_Command_Argument <TestCommand>(null);;

            //Act
            Assert.ThrowsAsync <ArgumentException>(async() =>
                                                   await Sut.HandleAsync <TestCommand>(MockResolverContext.Object, CancellationToken.None));
        }
Beispiel #3
0
        public override void Setup()
        {
            base.Setup();

            _command = new TestCommand {
                Name = "Piet"
            };
            MockCommandHandler.Mock.Setup(x => x.HandleAsync(It.IsAny <TestCommand>(), It.IsAny <IAuthenticatedUser>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Response.Success());
            MockResolverContext.With_Service(MockCommandHandler.Object);
            MockResolverContext.With_Command_Argument(_command);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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 override void Setup()
 {
     base.Setup();
     _command = new TestCommand  {
         Name = "Piet"
     };
     _mockTestCommandHandler = new TestAuthenticatedUserCommandHandlerMockBuilder()
                               .Where_HandleAsync_returns(new TestServerPayload {
         Name = "Freddie"
     });
     MockResolverContext.With_Service(_mockTestCommandHandler.Object);
     MockResolverContext.With_Command_Argument(_command);
     Services.AddSingleton(_mockTestCommandHandler.Object);
 }
Beispiel #7
0
        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");
        }