Exemple #1
0
            public async void WhenNoResultsAreFound_ThenReturnEmptyList()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var theMovieDbGatewayMock = new Mock <ITheMovieDbGateway>();

                var searchMoviesEmptyResponse = _fixture.Build <SearchMovieResponse>()
                                                .With(a => a.Results, Enumerable.Empty <Models.Movie>())
                                                .With(a => a.TotalResults, 0)
                                                .Create();

                theMovieDbGatewayMock.Setup(g => g.MakeSearchMovieRequestAsync(It.IsAny <string>(), It.IsAny <int>()))
                .ReturnsAsync(searchMoviesEmptyResponse);

                var mapperMock = new Mock <IMapper>();

                var sut = new TheMovieDbAdapter(loggerMock.Object, theMovieDbGatewayMock.Object, mapperMock.Object);

                // Act
                var result = await sut.GetMovieExternalProviderKeywordIdsAsync(_fixture.Create <string>(), _fixture.Create <int>());

                // Assert
                theMovieDbGatewayMock.Verify(m => m.MakeMovieKeywordsRequestAsync(It.IsAny <int>()), Times.Never);
                result.Count().Should().Be(0);
            }
Exemple #2
0
            public async void WhenMakeMovieKeywordsRequestAsyncThrowsException_ThenReturnEmptyList()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var theMovieDbGatewayMock = new Mock <ITheMovieDbGateway>();
                var searchMoviesResponse  = _fixture.Create <SearchMovieResponse>();

                theMovieDbGatewayMock.Setup(g => g.MakeSearchMovieRequestAsync(It.IsAny <string>(), It.IsAny <int>()))
                .ReturnsAsync(searchMoviesResponse);

                theMovieDbGatewayMock.Setup(g => g.MakeMovieKeywordsRequestAsync(It.IsAny <int>()))
                .ThrowsAsync(new Exception());

                var mapperMock = new Mock <IMapper>();

                var sut = new TheMovieDbAdapter(loggerMock.Object, theMovieDbGatewayMock.Object, mapperMock.Object);

                // Act
                var result = await sut.GetMovieExternalProviderKeywordIdsAsync(_fixture.Create <string>(), _fixture.Create <int>());

                // Assert
                theMovieDbGatewayMock.Verify(m => m.MakeSearchMovieRequestAsync(It.IsAny <string>(), It.IsAny <int>()), Times.Once);
                result.Count().Should().Be(0);
            }
Exemple #3
0
            public async void WhenMultipleMoviesAreRetrieved_ThenTheKeywordIdsOfTheFirstOneAreRequested()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var theMovieDbGatewayMock = new Mock <ITheMovieDbGateway>();
                var moviesReturned        = _fixture.CreateMany <Models.Movie>(3);
                var searchMoviesResponse  = _fixture.Build <SearchMovieResponse>()
                                            .With(a => a.Results, moviesReturned)
                                            .Create();

                theMovieDbGatewayMock.Setup(g => g.MakeSearchMovieRequestAsync(It.IsAny <string>(), It.IsAny <int>()))
                .ReturnsAsync(searchMoviesResponse);

                int requestedMovieId = 0;

                theMovieDbGatewayMock.Setup(g => g.MakeMovieKeywordsRequestAsync(It.IsAny <int>()))
                .Callback <int>(id =>
                {
                    requestedMovieId = id;
                })
                .ReturnsAsync(_fixture.Create <GetMovieKeywordsResponse>());

                var mapperMock = new Mock <IMapper>();

                var sut = new TheMovieDbAdapter(loggerMock.Object, theMovieDbGatewayMock.Object, mapperMock.Object);

                // Act
                await sut.GetMovieExternalProviderKeywordIdsAsync(_fixture.Create <string>(), _fixture.Create <int>());

                // Assert
                requestedMovieId.Should().Be(moviesReturned.ToList()[0].Id);
            }