Exemple #1
0
        public async Task CreateRoleAsync_Should_Return_CreatedAtRouteResult_With_GetRoleResponse()
        {
            var createRoleRequest = new CreateRoleRequest {
                Name = DefaultRoleEnumeration.Administrator.DisplayName
            };
            var createRoleCommand = new CreateRoleCommand(Guid.NewGuid(), createRoleRequest.Name);
            var roleOutputQuery   = new RoleOutputQuery(createRoleCommand.RoleId, Array.Empty <byte>(), createRoleCommand.Name);
            var getRoleResponse   = new GetRoleResponse(roleOutputQuery.Id, roleOutputQuery.RowVersion, roleOutputQuery.Name);

            _mapperMock.Setup(x => x.Map <CreateRoleRequest, CreateRoleCommand>(It.IsAny <CreateRoleRequest>())).Returns(createRoleCommand);
            _communicationBusMock.Setup(x => x.SendCommandAsync(It.IsAny <CreateRoleCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getRoleQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoleInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roleOutputQuery);
            _mapperMock.Setup(x => x.Map <RoleOutputQuery, GetRoleResponse>(It.IsAny <RoleOutputQuery>())).Returns(getRoleResponse);

            var result = await _controller.CreateRoleAsync(createRoleRequest);

            var createdAtRouteResult = result.As <CreatedAtRouteResult>();

            createdAtRouteResult.Value.Should().BeEquivalentTo(getRoleResponse);
            createdAtRouteResult.RouteName.Should().BeEquivalentTo("GetRole");
            createdAtRouteResult.RouteValues.Should().BeEquivalentTo(new Microsoft.AspNetCore.Routing.RouteValueDictionary(new { id = roleOutputQuery.Id }));
        }
Exemple #2
0
        public async Task UpdateRoleAsync_Should_Return_OkObjectResult_With_GetRoleResponse()
        {
            var rowVersion        = new byte[] { 1, 2, 4, 8, 16, 32 };
            var roleId            = Guid.NewGuid();
            var updateRoleRequest = new UpdateRoleRequest
            {
                Id   = roleId,
                Name = DefaultRoleEnumeration.Administrator.DisplayName
            };
            var updateRoleCommand = new UpdateRoleCommand(updateRoleRequest.Id, rowVersion, updateRoleRequest.Name);
            var roleOutputQuery   = new RoleOutputQuery(updateRoleRequest.Id, new byte[] { 1, 2, 4, 8, 16, 64 }, updateRoleRequest.Name);
            var getRoleResponse   = new GetRoleResponse(roleOutputQuery.Id, roleOutputQuery.RowVersion, roleOutputQuery.Name);

            _mapperMock.Setup(x => x.Map <UpdateRoleRequest, UpdateRoleCommand>(It.IsAny <UpdateRoleRequest>())).Returns(updateRoleCommand);
            _communicationBusMock.Setup(x => x.SendCommandAsync(It.IsAny <UpdateRoleCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _getRoleQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoleInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roleOutputQuery);
            _mapperMock.Setup(x => x.Map <RoleOutputQuery, GetRoleResponse>(It.IsAny <RoleOutputQuery>())).Returns(getRoleResponse);

            var result = await _controller.UpdateRoleAsync(roleId, updateRoleRequest, rowVersion);

            var okObjectResult = result.As <OkObjectResult>();

            okObjectResult.Value.Should().BeEquivalentTo(getRoleResponse);
        }
Exemple #3
0
        public async Task HandleAsync_Should_Return_RoleOutputQuery()
        {
            var role          = new Role(Guid.NewGuid(), Array.Empty <byte>(), DefaultRoleEnumeration.Administrator.DisplayName);
            var getRoleResult = GetResult <Role> .Ok(role);

            var roleOutputQuery = new RoleOutputQuery(role.Id, role.RowVersion, role.Name);

            _roleGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getRoleResult);
            _mapperMock.Setup(x => x.Map <Role, RoleOutputQuery>(It.IsAny <Role>())).Returns(roleOutputQuery);

            var result = await _queryHandler.HandleAsync(new GetRoleInputQuery(role.Id));

            result.Should().BeEquivalentTo(roleOutputQuery);
        }
Exemple #4
0
        public async Task GetRoleAsync_Should_Return_OkObjectResult_With_GetRoleResponse()
        {
            var roleOutputQuery = new RoleOutputQuery(Guid.NewGuid(), Array.Empty <byte>(),
                                                      DefaultRoleEnumeration.Administrator.DisplayName);
            var getRoleResponse = new GetRoleResponse(roleOutputQuery.Id, roleOutputQuery.RowVersion, roleOutputQuery.Name);

            _getRoleQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetRoleInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(roleOutputQuery);
            _mapperMock.Setup(x => x.Map <RoleOutputQuery, GetRoleResponse>(It.IsAny <RoleOutputQuery>())).Returns(getRoleResponse);

            var result = await _controller.GetRoleAsync(roleOutputQuery.Id);

            var okResult = result.As <OkObjectResult>();

            okResult.Value.Should().BeEquivalentTo(getRoleResponse);
        }