Пример #1
0
        public async Task VerifiesCoverage()
        {
            var session = TestServerSession.Start("VerifiesCoverage", TestServerVersion.V1, allowUnmatched: false, "string_empty");

            await session.Server.Client.PutAsync("/string/null", new ByteArrayContent(Array.Empty <byte>()));

            Assert.ThrowsAsync <InvalidOperationException>(async() => await session.DisposeAsync());
        }
Пример #2
0
        public async Task NormalUsage()
        {
            await using var session = TestServerSession.Start("NormalUsage", TestServerVersion.V1, allowUnmatched: false, "putStringNull");

            var response = await session.Server.Client.PutAsync("/string/null", new ByteArrayContent(Array.Empty <byte>()));

            response.EnsureSuccessStatusCode();
        }
        public async Task VerifiesUnmatched()
        {
            var session = TestServerSession.Start("VerifiesUnmatched", TestServerVersion.V2);

            await(session.Server).Client.PutAsync("/string/nullaa", new ByteArrayContent(Array.Empty <byte>()));

            Assert.ThrowsAsync <InvalidOperationException>(async() => await session.DisposeAsync());
        }
        public static TestServerSession Start(string scenario, TestServerVersion version, bool allowUnmatched = false, params string[] expectedCoverage)
        {
            if (version == TestServerVersion.V2)
            {
                // we only use v1 for coverage
                expectedCoverage = Array.Empty <string>();
            }
            var server = new TestServerSession(scenario, version, allowUnmatched, expectedCoverage);

            return(server);
        }
Пример #5
0
        public async Task StartsAndReportsCoverage()
        {
            await using var session = TestServerSession.Start("StartsAndReportsCoverage", TestServerVersion.V1);

            var response = await session.Server.Client.PutAsync("/string/null", new ByteArrayContent(Array.Empty <byte>()));

            response.EnsureSuccessStatusCode();

            var matched = await session.Server.GetMatchedStubs("StartsAndReportsCoverage");

            CollectionAssert.Contains(matched, "putStringNull");
        }
        public async Task StartsAndReportsCoverage()
        {
            await using var session = TestServerSession.Start("StartsAndReportsCoverage", TestServerVersion.V2);

            var response = await(session.Server).Client.PutAsync("/string/null", new ByteArrayContent(Array.Empty <byte>()));

            response.EnsureSuccessStatusCode();

            var unmatchedRequests = await session.Server.GetRequests();

            Assert.IsEmpty(unmatchedRequests);

            var matched = await session.Server.GetMatchedStubs("StartsAndReportsCoverage");

            CollectionAssert.AreEqual(new string[]
            {
                "string_null"
            }, matched);
        }
Пример #7
0
        private async Task Test(string scenario, Func <Uri, HttpPipeline, Task> test, bool ignoreScenario = false, bool useSimplePipeline = false)
        {
            var scenarioParameter = ignoreScenario ? new string[0] : new[] { scenario };
            var server            = TestServerSession.Start(scenario, _version, false, scenarioParameter);

            try
            {
                var testClientOptions = new TestClientOptions
                {
                    Transport = new HttpClientTransport(server.Server.Client),
                    Retry     = { Delay = TimeSpan.FromMilliseconds(50) },
                };
                testClientOptions.AddPolicy(new CustomClientRequestIdPolicy(), HttpPipelinePosition.PerCall);

                var pipeline = useSimplePipeline
                    ? new HttpPipeline(new HttpClientTransport(server.Server.Client))
                    : HttpPipelineBuilder.Build(testClientOptions);

                await test(server.Host, pipeline);
            }
            catch (Exception ex)
            {
                try
                {
                    await server.DisposeAsync();
                }
                catch (Exception disposeException)
                {
                    throw new AggregateException(ex, disposeException);
                }

                throw;
            }

            await server.DisposeAsync();
        }