Esempio n. 1
0
            public async void WhenMakeDiscoverMoviesRequestAsyncThrowsException_ThenProcessContinues()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var theMovieDbGatewayMock = new Mock <ITheMovieDbGateway>();

                theMovieDbGatewayMock.Setup(g => g.MakeDiscoverMoviesRequestAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <IEnumerable <int> >(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>()))
                .ThrowsAsync(new Exception());

                DiscoverMoviesResponse spy = null;
                var mapperMock             = new Mock <IMapper>();

                mapperMock.Setup(m => m.Map(It.IsAny <DiscoverMoviesResponse>()))
                .Callback <DiscoverMoviesResponse>(r =>
                {
                    spy = r;
                })
                .Returns(_fixture.Create <GetMoviesResponse>());

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

                // Act.
                await sut.GetMoviesAsync(_fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <IEnumerable <Data.Models.Genre> >(), _fixture.Create <IEnumerable <string> >(), _fixture.Create <int>());

                // Assert
                spy.Should().BeNull();
            }
Esempio n. 2
0
            public async void WhenMoviesAreFound_ThenAreProperlyEnriched()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var discoverMoviesResponse = _fixture.Create <DiscoverMoviesResponse>();
                var movieDetailResponse    = _fixture.Create <Models.Movie>();
                var theMovieDbGatewayMock  = new Mock <ITheMovieDbGateway>();

                theMovieDbGatewayMock.Setup(g => g.MakeDiscoverMoviesRequestAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <IEnumerable <int> >(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>()))
                .ReturnsAsync(discoverMoviesResponse);
                theMovieDbGatewayMock.Setup(g => g.MakeMovieDetailRequestAsync(It.IsAny <int>(), It.IsAny <IEnumerable <MovieDetailRequestIncludeTypes> >()))
                .ReturnsAsync(movieDetailResponse);

                DiscoverMoviesResponse spy = null;
                var mapperMock             = new Mock <IMapper>();

                mapperMock.Setup(m => m.Map(It.IsAny <DiscoverMoviesResponse>()))
                .Callback <DiscoverMoviesResponse>(r =>
                {
                    spy = r;
                })
                .Returns(_fixture.Create <GetMoviesResponse>());

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

                // Act.
                await sut.GetMoviesAsync(_fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <IEnumerable <Data.Models.Genre> >(), _fixture.Create <IEnumerable <string> >(), _fixture.Create <int>());

                // Assert
                spy.Results.ToList().Select(r => r.Homepage).Should().BeEquivalentTo(new string[spy.Results.Count()].Select(i => movieDetailResponse.Homepage));
                spy.Results.ToList().Select(r => r.KeywordsEnvelope).Should().BeEquivalentTo(new string[spy.Results.Count()].Select(i => movieDetailResponse.KeywordsEnvelope));
                spy.Results.ToList().Select(r => string.Join(",", r.Genres)).Should().BeEquivalentTo(new string[spy.Results.Count()].Select(i => string.Join(",", movieDetailResponse.Genres)));
            }
Esempio n. 3
0
            public async void WhenMakeMovieDetailRequestAsyncThrowsException_ThenProcessContinues()
            {
                // Arrange
                var loggerMock = new Mock <ILogger <TheMovieDbAdapter> >();

                var discoverMoviesResponse = _fixture.Build <DiscoverMoviesResponse>()
                                             .With(v => v.Results, _fixture
                                                   .CreateMany <Models.Movie>(1))
                                             .Create();

                var theMovieDbGatewayMock = new Mock <ITheMovieDbGateway>();

                theMovieDbGatewayMock.Setup(g => g.MakeDiscoverMoviesRequestAsync(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <IEnumerable <int> >(), It.IsAny <IEnumerable <string> >(), It.IsAny <int>()))
                .ReturnsAsync(discoverMoviesResponse);
                theMovieDbGatewayMock.Setup(g => g.MakeMovieDetailRequestAsync(It.IsAny <int>(), It.IsAny <IEnumerable <MovieDetailRequestIncludeTypes> >()))
                .ThrowsAsync(new Exception());

                DiscoverMoviesResponse spy = null;
                var mapperMock             = new Mock <IMapper>();

                mapperMock.Setup(m => m.Map(It.IsAny <DiscoverMoviesResponse>()))
                .Callback <DiscoverMoviesResponse>(r =>
                {
                    spy = r;
                })
                .Returns(_fixture.Create <GetMoviesResponse>());

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

                // Act.
                await sut.GetMoviesAsync(_fixture.Create <DateTime>(), _fixture.Create <DateTime>(), _fixture.Create <IEnumerable <Data.Models.Genre> >(), _fixture.Create <IEnumerable <string> >(), _fixture.Create <int>());

                var result = spy.Results.ToList()[0];

                // Assert
                result.KeywordsEnvelope.Should().BeEquivalentTo(new GetMovieKeywordsResponse {
                    Keywords = Enumerable.Empty <Keyword>()
                });
                result.Homepage.Should().Be(string.Empty);
                result.Genres.Should().BeEquivalentTo(Enumerable.Empty <Models.Genre>());
            }