Beispiel #1
0
        public void C110_CreatePostCodes_MockedHttpClient()
        {
            var v = TestSetUp.GetValueFromJsonResource <PostalInfo>("B140_GetPostCodes_MockedHttpClient_Found_Response.json");

            var mcf = MockHttpClientFactory.Create();

            mcf.CreateClient("zippo", new Uri("http://api.zippopotam.us/"))
            .Request(HttpMethod.Post, "US/WA/Bananas").WithJsonResourceBody("C110_CreatePostCodes_MockedHttpClient_Request.json")
            .Respond.WithJsonResource("B140_GetPostCodes_MockedHttpClient_Found.json", HttpStatusCode.Created, r => r.Headers.ETag = new System.Net.Http.Headers.EntityTagHeaderValue("\"MyTestETag\""));

            using var agentTester = Beef.Test.NUnit.AgentTester.CreateWaf <Startup>(sc => mcf.Replace(sc));

            var res = agentTester.Test <PostalInfoAgent, PostalInfo>()
                      .ExpectStatusCode(HttpStatusCode.Created)
                      .ExpectJsonResourceValue("B140_GetPostCodes_MockedHttpClient_Found_Response.json")
                      .ExpectValue(_ => v)
                      .Run(a => a.CreatePostCodesAsync(v, "US", "WA", "Bananas"));

            // Check that the etag flows all the way through.
            Assert.AreEqual("\"MyTestETag\"", res.Response.Headers.ETag.Tag);
        }
Beispiel #2
0
        /// <summary>
        /// Expect a response comparing the deserialized JSON value within the named embedded resource (and optionally any additional <paramref name="membersToIgnore"/> from the comparison).
        /// </summary>
        /// <param name="resourceName">The embedded resource name (matches to the end of the fully qualifed resource name) within the <see cref="Assembly.GetCallingAssembly()"/>.</param>
        /// <param name="membersToIgnore">The members to ignore from the comparison.</param>
        /// <returns>The <see cref="GrpcAgentTest{TStartup, TAgent, TValue}"/> instance to support fluent/chaining usage.</returns>
        public GrpcAgentTest <TStartup, TAgent, TValue> ExpectJsonResourceValue(string resourceName, params string[] membersToIgnore)
        {
            var ass = Assembly.GetCallingAssembly();

            return(ExpectValue(_ => TestSetUp.GetValueFromJsonResource <TValue>(resourceName, ass), membersToIgnore));
        }