public async void GetDistinctMovieList_Must_Ignore_Exception_In_CinemaWorldAPI_And_Return_Results_In_FilmWorldAPI()
        {
            //Arrange
            // Create Error client
            var unAuthorisedResponseHttpMessageHandler = new Mock <HttpMessageHandler>();

            unAuthorisedResponseHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.Forbidden
            });
            var httpClient = new HttpClient(unAuthorisedResponseHttpMessageHandler.Object);
            IMovieAPIClient <CinemaWorldClient> cinemaWorldClient = new CinemaWorldClient(configuration.Object, httpClient, cinemaWorldClientlogger.Object);
            // Mock filmWorldClient with data
            Mock <IMovieAPIClient <FilmWorldClient> > filmWorldClient = new Mock <IMovieAPIClient <FilmWorldClient> >();

            filmWorldClient.Setup(c => c.GetMovieList(It.IsAny <CancellationToken>()))
            .ReturnsAsync(testMovieList);

            sut = new MovieFinderService(cinemaWorldClient, filmWorldClient.Object, movieFinderServicelogger.Object);

            //Act
            var result = await sut.GetDistinctMovieList();

            //Assert
            Assert.NotNull(result);
            Assert.IsType <List <Movie> >(result.ToList());
            Assert.Equal(testMovieList.Select(m => m.ID).FirstOrDefault(), result.Select(r => r.ID).FirstOrDefault());
        }
예제 #2
0
        public void Constructor_With_APIURL_AND_APIKey()
        {
            //Arrange
            configuration = new Mock <IConfiguration>();
            configuration.SetupGet(c => c["MovieFinder.APIURL"])
            .Returns("http://testURL.com");
            configuration.SetupGet(c => c["MovieFinder.APIKey"])
            .Returns("API KEY Here");
            Mock <HttpClient> client = new Mock <HttpClient>();


            //Act
            IMovieAPIClient <CinemaWorldClient> sut = new CinemaWorldClient(configuration.Object, client.Object, cinemaWorldClientlogger.Object);

            //Assert
            Assert.NotNull(sut);
        }
        public async void GetCheapestMovieDetailsByTitle_Must_Ignore_Exception_In_CinemaWorldAPI_And_Return_Results_In_FilmWorldAPI()
        {
            //Arrange
            // Create Error client
            var unAuthorisedResponseHttpMessageHandler = new Mock <HttpMessageHandler>();

            unAuthorisedResponseHttpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.Forbidden
            });
            var httpClient = new HttpClient(unAuthorisedResponseHttpMessageHandler.Object);
            IMovieAPIClient <CinemaWorldClient> cinemaWorldClient = new CinemaWorldClient(configuration.Object, httpClient, cinemaWorldClientlogger.Object);

            // Mock filmWorldClient with data
            Mock <IMovieAPIClient <FilmWorldClient> > filmWorldClient = new Mock <IMovieAPIClient <FilmWorldClient> >();

            filmWorldClient.Setup(c => c.GetMovieList(It.IsAny <CancellationToken>()))
            .ReturnsAsync(testMovieListExtra);
            filmWorldClient.Setup(c => c.GetMovieDetails(It.IsAny <CancellationToken>(), It.IsAny <string>()))
            .ReturnsAsync(filmWorldMovieDetail);

            sut = new MovieFinderService(cinemaWorldClient, filmWorldClient.Object, movieFinderServicelogger.Object);

            //Act
            var result = await sut.GetCheapestMovieDetailsByTitle("Test movie");

            //Assert
            Assert.NotNull(result);
            Assert.IsType <MovieDetail>(result);
            Assert.Equal(filmWorldMovieDetail.Title, result.Title);
            Assert.Equal(filmWorldMovieDetail.Price, result.Price); // Should return FilmWorldMovieDetail, Price = 150
        }