Ejemplo n.º 1
0
        public async Task GetAllAsync_GetDestinationsPreviewQuery_Can_Verify()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <GetDestinationsPreviewQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(Destinations);
            var mockMapper          = new Mock <IMapper>();
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut = new DestinationsController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);

            var pagingOptions = new PagingOptions
            {
                PageNumber = 1,
                PageSize   = 10
            };

            var sortOptions = new SortOptions
            {
                OrderBy = "Name"
            };

            var searchOptions = new SearchOptions
            {
                Query = "London"
            };

            // Act
            await sut.GetAllDestinationsAsync(pagingOptions, sortOptions, searchOptions, default(CancellationToken));

            // Assert
            mockMediator.Verify(x => x.Send(It.IsAny <GetDestinationsPreviewQuery>(), It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async Task GetAllAsync_Returns_OK_200_Result_With_Correct_Data()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <GetDestinationsPreviewQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(Destinations);
            var mapper = Mapper;
            var mockResponseFactory = new Mock <IResponseFactory>();

            mockResponseFactory.Setup(x => x.CreatePagedReponse(It.IsAny <IList <Destination> >(), It.IsAny <Type>(), It.IsAny <IPreviewQuery>(), It.IsAny <ResponseStatus>(), It.IsAny <string>())).Returns(PagedDestinations);
            var mockApiSettings = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut = new DestinationsController(mockMediator.Object, mapper, mockResponseFactory.Object, mockApiSettings.Object);

            var pagingOptions = new PagingOptions
            {
                PageNumber = 1,
                PageSize   = 10
            };

            var sortOptions = new SortOptions
            {
                OrderBy = "Name"
            };

            var searchOptions = new SearchOptions
            {
                Query = "London"
            };

            // Act
            var result = await sut.GetAllDestinationsAsync(pagingOptions, sortOptions, searchOptions, default(CancellationToken));

            // Assert
            var response = result.Should().BeOfType <OkObjectResult>().Subject;

            response.StatusCode.Should().Equals(200);

            var destination = response.Value.Should().BeAssignableTo <PagedResponse <Destination> >().Subject;

            destination.Data.Select(x => x.Id == 1).Should().NotBeNull();
            destination.Data.Select(x => x.Name == "London").Should().NotBeNull();
            destination.Data.Count().Should().Equals(3);
        }
Ejemplo n.º 3
0
        public async Task GetAllAsync_Returns_OK_200_Result()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <GetDestinationsPreviewQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(Destinations);
            var mapper = Mapper;
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut = new DestinationsController(mockMediator.Object, mapper, mockResponseFactory.Object, mockApiSettings.Object);

            var pagingOptions = new PagingOptions
            {
                PageNumber = 1,
                PageSize   = 10
            };

            var sortOptions = new SortOptions
            {
                OrderBy = "Name"
            };

            var searchOptions = new SearchOptions
            {
                Query = "London"
            };

            // Act
            var result = await sut.GetAllDestinationsAsync(pagingOptions, sortOptions, searchOptions, default(CancellationToken));

            // Assert
            var response = result.Should().BeOfType <OkObjectResult>().Subject;

            response.StatusCode.Should().Equals(200);
        }