public async Task GetCities_Should_Return_All_CitiesAsync()
        {
            var cities = new[]
            {
                new CityDto()
                {
                    CityId = 1,
                    Name   = "Stockholm",
                    Sights = new List <SightDto>()
                },
                new CityDto()
                {
                    CityId = 1,
                    Name   = "Lund",
                    Sights = new List <SightDto>()
                }
            };

            var mockedService = new Mock <ICitiesService>();

            mockedService.Setup(x => x.GetAllCitiesAsync())
            .Returns(Task.FromResult((IEnumerable <CityDto>)cities));

            var mockedLogger = new Mock <ILogger <CitiesController> >();
            var controller   = new CitiesController(mockedLogger.Object, mockedService.Object);

            var result = await controller.GetCitiesAsync() as OkObjectResult;

            var data = result.Value as IEnumerable <CityDto>;

            Assert.Collection(data, x => Assert.Contains("Stockholm", x.Name),
                              x => Assert.Contains("Lund", x.Name));
        }
Example #2
0
        public async Task Get_Cities_Test()
        {
            //Arrange
            var controller = new CitiesController(context.Object);
            //Act
            var result = await controller.GetCitiesAsync();

            //Assert
            Assert.IsTrue(result.Count() > 0);
        }
Example #3
0
        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);
        }