예제 #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 }));
        }