Exemplo n.º 1
0
        public void ShouldOverrideProperties()
        {
            var options1 = new Yawat.YawatOptions(typeof(XmlResponseData))
            {
                Host           = "localhost",
                Protocol       = "http",
                Port           = "5000",
                Authenticator  = new Authenticator1(),
                IncludeHeaders = true,
            };
            var options2 = new Yawat.YawatOptions(typeof(JsonResponseData))
            {
                Host           = "remote",
                Protocol       = "http",
                Port           = "5000",
                Authenticator  = new Authenticator2(),
                IncludeHeaders = false,
            };

            var options3 = options1.OverwrittenBy(options2);

            Assert.AreEqual(options3.Host, options2.Host);
            Assert.IsTrue(options3.Authenticator is Authenticator2);
            Assert.AreEqual(options3.ResponseType, typeof(JsonResponseData));

            Assert.True(options3.IncludeHeaders);
        }
Exemplo n.º 2
0
        public async Task ShouldUseMockJsonData()
        {
            var definition = new { test = string.Empty };
            var jsonText   = Newtonsoft.Json.JsonConvert.SerializeObject(new { test = "Test" });

            var options = new Yawat.YawatOptions(typeof(JsonResponseData))
            {
                Host           = "localhost",
                Protocol       = "http",
                Port           = "5000",
                MockHttpClient = new YawatMockHttpClient()
                {
                    EndpointHandlersDictionary = new Dictionary <string, YawatMockEndpoint>()
                    {
                        {
                            "/test",
                            new YawatMockEndpoint()
                            {
                                StatusCode = HttpStatusCode.OK,
                                Data       = jsonText
                            }
                        }
                    }
                }
            };
            var httpClient = new YawatHttpClient(options);

            var response = await httpClient.GetAsync("/test");

            var typedResponse = response.AsAnonymous(definition);

            Assert.AreEqual(typedResponse.test, "Test");
        }
Exemplo n.º 3
0
        public void ShouldCreateOptions()
        {
            var options = new Yawat.YawatOptions(null)
            {
                Host     = "localhost",
                Protocol = "http",
                Port     = "5000",
            };

            Assert.AreEqual(options.Host, "localhost");
            Assert.AreEqual(options.Protocol, "http");
            Assert.AreEqual(options.Port, "5000");
        }