Beispiel #1
0
            public async Task ShouldSucceedAsync(FakeCrudListRequest listRequest)
            {
                Assert.NotNull(listRequest);

                var authorizationService = MockAuthorizationServiceFactory();

                authorizationService.Setup(s =>
                                           s.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), "listPolicyName"))
                .Returns(async() => await Task.FromResult(AuthorizationResult.Success()).ConfigureAwait(false));

                var logger = MockLoggerFactory();

                var mediator = MockMediatorFactory();

                mediator.Setup(s => s.Send(It.IsAny <FakeCrudListQuery>(), It.IsAny <CancellationToken>())).Returns <FakeCrudListQuery, CancellationToken>(MockListMediatorHandlerAsync);

                var auditableCommandFactory = MockCommandFactory();

                var auditableQueryFactory = MockQueryFactory();

                auditableQueryFactory.Setup(s =>
                                            s.GetListQueryAsync(
                                                It.IsAny <FakeCrudListRequest>(),
                                                It.IsAny <ClaimsPrincipal>(),
                                                It.IsAny <CancellationToken>()))
                .Returns <FakeCrudListRequest, ClaimsPrincipal, CancellationToken>(MockListQueryAsync);

                using (var instance = new FakeCrudController(
                           authorizationService.Object,
                           logger.Object,
                           mediator.Object,
                           auditableCommandFactory.Object,
                           auditableQueryFactory.Object)
                {
                    ControllerContext = new ControllerContext
                    {
                        HttpContext = new DefaultHttpContext
                        {
                            User = new ClaimsPrincipal(new HttpListenerBasicIdentity("user", "pass")),
                            Request =
                            {
                                IsHttps = true,
                                Query   = new QueryCollection(),
                            },
                        },
                    },
                })
                {
                    var result = await instance.GetAsync(null, CancellationToken.None).ConfigureAwait(false);

                    Assert.NotNull(result);
                    Assert.IsType <OkObjectResult>(result);
                }
            }
Beispiel #2
0
            public async Task ReturnsBadRequestAsync()
            {
                var authorizationService = MockAuthorizationServiceFactory();

                authorizationService.Setup(s =>
                                           s.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>(), "updatePolicyName"))
                .Returns(async() => await Task.FromResult(AuthorizationResult.Success()).ConfigureAwait(false));

                var logger = MockLoggerFactory();

                var mediator = MockMediatorFactory();

                mediator.Setup(s => s.Send(It.IsAny <FakeCrudUpdateCommand>(), It.IsAny <CancellationToken>())).Returns <FakeCrudUpdateCommand, CancellationToken>(MockUpdateMediatorHandlerAsync);

                var auditableCommandFactory = MockCommandFactory();

                auditableCommandFactory.Setup(s =>
                                              s.GetUpdateCommandAsync(
                                                  It.IsAny <int>(),
                                                  It.IsAny <ClaimsPrincipal>(),
                                                  It.IsAny <CancellationToken>()))
                .Returns <int, ClaimsPrincipal, CancellationToken>(MockUpdateCommandAsync);

                var auditableQueryFactory = MockQueryFactory();

                using (var instance = new FakeCrudController(
                           authorizationService.Object,
                           logger.Object,
                           mediator.Object,
                           auditableCommandFactory.Object,
                           auditableQueryFactory.Object)
                {
                    ControllerContext = new ControllerContext
                    {
                        HttpContext = new DefaultHttpContext
                        {
                            Request = { IsHttps = false },
                            User = new ClaimsPrincipal(new HttpListenerBasicIdentity("user", "pass")),
                        },
                    },
                })
                {
                    var result = await instance.PutAsync(1, 1, CancellationToken.None).ConfigureAwait(false);

                    Assert.NotNull(result);
                    Assert.IsType <BadRequestResult>(result);
                }
            }
Beispiel #3
0
            public void ReturnsInstance()
            {
                var mockAuthorizationService = MockAuthorizationServiceFactory();
                var mockLogger         = MockLoggerFactory();
                var mockMediator       = MockMediatorFactory();
                var mockCommandFactory = MockCommandFactory();
                var mockQueryFactory   = MockQueryFactory();

                using (var instance = new FakeCrudController(
                           mockAuthorizationService.Object,
                           mockLogger.Object,
                           mockMediator.Object,
                           mockCommandFactory.Object,
                           mockQueryFactory.Object))
                {
                    Assert.NotNull(instance);
                }

                mockAuthorizationService.VerifyNoOtherCalls();
                mockLogger.VerifyNoOtherCalls();
                mockMediator.VerifyNoOtherCalls();
                mockCommandFactory.VerifyNoOtherCalls();
                mockQueryFactory.VerifyNoOtherCalls();
            }