public async Task CreateCityAsync_Should_Return_CreatedAtRouteResult_With_CityResponse() { var createCityRequest = new CreateCityRequest { Name = "Name", PolishName = "PolishName" }; var createCityCommand = new CreateCityCommand(Guid.NewGuid(), createCityRequest.Name, createCityRequest.PolishName, Guid.NewGuid()); var cityOutputQuery = new CityOutputQuery(createCityCommand.CityId, Array.Empty <byte>(), createCityCommand.Name, createCityCommand.PolishName, createCityCommand.StateId); var cityResponse = new CityResponse(cityOutputQuery.Id, cityOutputQuery.RowVersion, cityOutputQuery.Name, cityOutputQuery.PolishName, cityOutputQuery.StateId); _mapperMock.Setup(x => x.Map <CreateCityRequest, CreateCityCommand>(It.IsAny <CreateCityRequest>())).Returns(createCityCommand); _communicationBusMock.Setup(x => x.SendCommandAsync(It.IsAny <CreateCityCommand>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask); _getCityQueryHandlerMock .Setup(x => x.HandleAsync(It.IsAny <GetCityInputQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cityOutputQuery); _mapperMock.Setup(x => x.Map <CityOutputQuery, CityResponse>(It.IsAny <CityOutputQuery>())).Returns(cityResponse); var result = await _controller.CreateCityAsync(createCityRequest); var createdAtRouteResult = result.As <CreatedAtRouteResult>(); createdAtRouteResult.Value.Should().BeEquivalentTo(cityResponse); createdAtRouteResult.RouteName.Should().BeEquivalentTo("GetCity"); createdAtRouteResult.RouteValues.Should().BeEquivalentTo(new RouteValueDictionary(new { id = cityResponse.Id })); }
public async Task UpdateCityAsync_Should_Return_OkObjectResult_With_CityResponse() { var rowVersion = new byte[] { 1, 2, 4, 8, 16, 32, 64 }; var cityId = Guid.NewGuid(); var updateCityRequest = new UpdateCityRequest { Id = cityId, Name = "Name", PolishName = "PolishName", StateId = Guid.NewGuid() }; var updateCityCommand = new UpdateCityCommand(updateCityRequest.Id, rowVersion, updateCityRequest.Name, updateCityRequest.PolishName, updateCityRequest.StateId); var cityOutputQuery = new CityOutputQuery(updateCityCommand.CityId, new byte[] { 1, 2, 4, 8, 16, 32, 128 }, updateCityCommand.Name, updateCityCommand.PolishName, updateCityCommand.StateId); var cityResponse = new CityResponse(cityOutputQuery.Id, cityOutputQuery.RowVersion, cityOutputQuery.Name, cityOutputQuery.PolishName, cityOutputQuery.StateId); _mapperMock.Setup(x => x.Map <UpdateCityRequest, UpdateCityCommand>(It.IsAny <UpdateCityRequest>())) .Returns(updateCityCommand); _communicationBusMock.Setup(x => x.SendCommandAsync(It.IsAny <UpdateCityCommand>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask); _getCityQueryHandlerMock .Setup(x => x.HandleAsync(It.IsAny <GetCityInputQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cityOutputQuery); _mapperMock.Setup(x => x.Map <CityOutputQuery, CityResponse>(It.IsAny <CityOutputQuery>())).Returns(cityResponse); var result = await _controller.UpdateCityAsync(cityId, updateCityRequest, rowVersion); var okObjectResult = result.As <OkObjectResult>(); okObjectResult.Value.Should().BeEquivalentTo(cityResponse); }
public async Task GetCityAsync_Should_Return_OkObjectResult_With_CityResponse() { var cityOutputQuery = new CityOutputQuery(Guid.NewGuid(), Array.Empty <byte>(), "Name", "PolishName", Guid.NewGuid()); var cityResponse = new CityResponse(cityOutputQuery.Id, cityOutputQuery.RowVersion, cityOutputQuery.Name, cityOutputQuery.PolishName, cityOutputQuery.StateId); _getCityQueryHandlerMock .Setup(x => x.HandleAsync(It.IsAny <GetCityInputQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cityOutputQuery); _mapperMock.Setup(x => x.Map <CityOutputQuery, CityResponse>(It.IsAny <CityOutputQuery>())).Returns(cityResponse); var result = await _controller.GetCityAsync(cityOutputQuery.Id); var okResult = result.As <OkObjectResult>(); okResult.Value.Should().BeEquivalentTo(cityResponse); }
public async Task HandleAsync_Should_Return_CityOutputQuery() { var city = City.Builder() .SetId(Guid.NewGuid()) .SetRowVersion(Array.Empty <byte>()) .SetName("Name") .SetPolishName("PolishName") .SetStateId(Guid.NewGuid()) .Build(); var getCityResult = GetResult <City> .Ok(city); var cityOutputQuery = new CityOutputQuery(city.Id, city.RowVersion, city.Name, city.PolishName, city.StateId); _cityGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getCityResult); _mapperMock.Setup(x => x.Map <City, CityOutputQuery>(It.IsAny <City>())).Returns(cityOutputQuery); var result = await _queryHandler.HandleAsync(new GetCityInputQuery(city.Id)); result.Should().BeEquivalentTo(cityOutputQuery); }
public async Task GetCitiesAsync_Should_Return_OkObjectResult_With_CollectionResponse_With_CityResponses() { var getCitiesRequest = new GetCitiesRequest { Page = 1, PageSize = 100, StateId = Guid.NewGuid(), Name = "Name", PolishName = "PolishName", Sort = "name:asc" }; var getCitiesInputQuery = new GetCitiesInputQuery(getCitiesRequest.Page, getCitiesRequest.PageSize, getCitiesRequest.Sort, getCitiesRequest.StateId, getCitiesRequest.Name, getCitiesRequest.PolishName); var cityOutputQuery = new CityOutputQuery(Guid.NewGuid(), Array.Empty <byte>(), "Name", "PolishName", Guid.NewGuid()); var cityOutputQueries = new Collection <CityOutputQuery> { cityOutputQuery }; var collectionOutputQuery = new CollectionOutputQuery <CityOutputQuery>(cityOutputQueries.Count, cityOutputQueries); var cityResponses = cityOutputQueries.Select(x => new CityResponse(x.Id, x.RowVersion, x.Name, x.PolishName, x.StateId)); var collectionResponse = new CollectionResponse <CityResponse>(cityOutputQueries.Count, cityResponses); _mapperMock.Setup(x => x.Map <GetCitiesRequest, GetCitiesInputQuery>(It.IsAny <GetCitiesRequest>())) .Returns(getCitiesInputQuery); _getCitiesQueryHandlerMock .Setup(x => x.HandleAsync(It.IsAny <GetCitiesInputQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(collectionOutputQuery); _mapperMock .Setup(x => x.Map <CollectionOutputQuery <CityOutputQuery>, CollectionResponse <CityResponse> >(It.IsAny <CollectionOutputQuery <CityOutputQuery> >())) .Returns(collectionResponse); var result = await _controller.GetCitiesAsync(getCitiesRequest); var okResult = result.As <OkObjectResult>(); okResult.Value.Should().BeEquivalentTo(collectionResponse); }