public async Task GetResponse_MockCommunications_Verify()
        {
            // ARRANGE
            var ipAddress = "http://192.168.1.5";
            // Acquire the soap/Xml data that we wish to supply within our mock'd HttpWebRequest and HttpWebResponse
            // Read Text directly instead of Bytes - so that our Xml comparison is easier (aka, BOM)
            var responseBytes = Encoding.UTF8.GetBytes(File.ReadAllText("TestData\\GetHomeInfoResponse.xml"));

            // Mock the HttpWebRequest and HttpWebResponse (which is within the request)
            var mockRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", responseBytes);

            var wemo = new Wemo
            {
                // Minimal inversion of control: Set the WebRequest property to provide out own Mock'd HttpWebRequest/Response
                GetResponseWebRequest = mockRequest
            };

            // ACT
            var result = await wemo.GetWemoPlugResponseAsync(Soap.WemoGetCommands.GetHomeInfo, ipAddress);

            var resultBodyXml = XDocument.Parse(result.ResponseBody);

            // ASSERT
            Assert.IsTrue(result.StatusCode == HttpStatusCode.NotModified.ToString(), "Expected Http StatusCode not returned");

            var expectedXml = XDocument.Parse(Encoding.UTF8.GetString(responseBytes));
            var xmlCompares = XNode.DeepEquals(expectedXml, resultBodyXml);

            Assert.IsTrue(xmlCompares, "Expected ResponseBody not returned");
        }
Esempio n. 2
0
        public void GetResponse_Verify()
        {
            // ARRANGE
            var ipAddress = "http://192.168.1.5";
            var wemo      = new Wemo();

            // ACT
            var result = wemo.GetWemoPlugResponseAsync(Soap.WemoGetCommands.GetHomeId, ipAddress).GetAwaiter().GetResult();

            // ASSERT
            Assert.IsTrue(result.StatusCode == "OK", "Expected Http StatusCode not returned");
        }