Exemplo n.º 1
0
        public async Task When_UserAddsMovieToResearchQueue_Then_Success()
        {
            // arrange
            var client = Fixture.Server.CreateClient();

            client.CreateSession();
            var response       = ResponseFactory.FromBodyOnlyFile($"{Fixture.StubsFolder}/OmdbApi/Fake_Responses/Happy/200_AddToQueue.json", HttpStatusCode.OK);
            var matrixMovieUrl = $"{MovieUrl}";

            client.AppendHttpCallStub(HttpMethod.Post, new System.Uri(matrixMovieUrl), response);

            // act
            var httpResponse = await client.PostAsJsonAsync("/api/movie?imdb=tt000001   ", new { });

            using (new AssertionScope())
            {
                // assert logs
                client.GetSessionLogs().Should().BeEmpty();

                // assert outgoing
                var outgoingRequests = client.GetSessionOutgoingRequests();
                outgoingRequests.Count.Should().Be(1);
                outgoingRequests[0].GetEndpoint().Should().Be($"POST {matrixMovieUrl}");
                outgoingRequests[0].GetHeaderValue("Referer").Should().Be(MovieProject.Logic.Constants.Website);
                var request = await outgoingRequests[0].ReadJsonBody <MovieProject.Logic.DTO.Media>();
                request.Should().NotBeNull();
                request.Id.Should().Be("tt000001");
                request.Name.Should().Be("TO BE RESEARCHED"); // check if outgoing post body is correctly formatted

                // assert return
                httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            }
        }
Exemplo n.º 2
0
        public async Task FromBodyOnlyFile()
        {
            var fullFileName = FilesFolder + @"happy/OnlyBody.txt";

            var sut = ResponseFactory.FromBodyOnlyFile(fullFileName, HttpStatusCode.OK);

            sut.StatusCode.Should().Be(HttpStatusCode.OK);

            var body = await sut.GetResponseString();

            body.Should().Be(@"{""Content"":""Only the raw body found here!""}");

            sut.Headers.Should().BeEmpty();
        }
Exemplo n.º 3
0
        public async Task When_UserAsksForMovie_30times_WithSameStub_Works()
        {
            // arrange
            var client = Fixture.Server.CreateClient();

            client.CreateSession();
            // FromBodyOnlyFile work well, but if possible it's nicer to read from a more comprehensive file format (the one that FromFiddlerLikeResponseFile uses)
            var response       = ResponseFactory.FromBodyOnlyFile($"{Fixture.StubsFolder}/OmdbApi/Real_Responses/Happy/200_ContainsMostFields_TheMatrix.json", HttpStatusCode.OK);
            var matrixMovieUrl = $"{MovieUrl}&t=matrix";

            client.AppendHttpCallStub(HttpMethod.Get, new System.Uri(matrixMovieUrl), response, counter: 30);

            // act
            for (int i = 0; i < 30; i++)
            {
                await client.GetAsync("/api/movie/matrix");
            }

            using (new AssertionScope())
            {
                // assert logs
                client.GetSessionLogs().Should().BeEmpty();

                // assert outgoing
                var outgoingRequests = client.GetSessionOutgoingRequests();
                outgoingRequests.Count.Should().Be(30);
                outgoingRequests[0].GetEndpoint().Should().Be($"GET {matrixMovieUrl}");
                outgoingRequests[0].GetHeaderValue("Referer").Should().Be(MovieProject.Logic.Constants.Website);
            }

            // one more time should cause an error
            var httpResponse = await client.GetAsync("/api/movie/matrix");

            // assert logs
            var logs = client.GetSessionLogs();

            logs.Should().HaveCount(1);
            logs[0].Message.Should().Contain("No stubs found for");

            httpResponse.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }
Exemplo n.º 4
0
        public async Task When_UserAsksForMovieWithMostFields_With_ResponseBodyOnly_Then_ReturnMovieProperly()
        {
            // arrange
            var client = Fixture.Server.CreateClient();

            client.CreateSession();
            // FromBodyOnlyFile work well, but if possible it's nicer to read from a more comprehensive file format (the one that FromFiddlerLikeResponseFile uses)
            var response       = ResponseFactory.FromBodyOnlyFile($"{Fixture.StubsFolder}/OmdbApi/Real_Responses/Happy/200_ContainsMostFields_TheMatrix.json", HttpStatusCode.OK);
            var matrixMovieUrl = $"{MovieUrl}&t=matrix";

            client.AppendHttpCallStub(HttpMethod.Get, new System.Uri(matrixMovieUrl), response);

            // act
            var httpResponse = await client.GetAsync("/api/movie/matrix");

            using (new AssertionScope())
            {
                // assert logs
                client.GetSessionLogs().Should().BeEmpty();

                // assert outgoing
                var outgoingRequests = client.GetSessionOutgoingRequests();
                outgoingRequests.Count.Should().Be(1);
                outgoingRequests[0].GetEndpoint().Should().Be($"GET {matrixMovieUrl}");
                outgoingRequests[0].GetHeaderValue("Referer").Should().Be(MovieProject.Logic.Constants.Website);

                // assert return
                httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);

                var movie = await httpResponse.ReadJsonBody <MovieProject.Logic.DTO.Media>();

                movie.Id.Should().Be("tt0133093");
                movie.Name.Should().Be("The Matrix");
                movie.Year.Should().Be("1999");
                movie.Runtime.Should().Be("2.3h");
                movie.Plot.Should().Be("A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against its controllers.");
                movie.Language.Should().Be(MovieProject.Logic.DTO.Media.Languages.English);
            }
        }