Esempio n. 1
0
        public async Task GetResponseObject_MockCommunications_Verify()
        {
            // ARRANGE
            var ipAddress = "http://192.168.1.5";

            XNamespace ns = "http://schemas.xmlsoap.org/soap/envelope/";

            // Acquire the soap/Xml data that we wish to supply within our mock'd HttpWebRequest and HttpWebResponse
            var soapXml = XDocument.Load("TestData\\GetHomeInfoResponse.xml");

            var homeInfoXml = soapXml
                              .Descendants()
                              .Descendants(ns + "Body").FirstOrDefault()
                              .Descendants().FirstOrDefault();

            // Set the contents of the Xml to a byte array
            var responseBytes = Encoding.UTF8.GetBytes(soapXml.ToString());

            // Set the expected HomeInfo value
            var expectedHomeInfo = Deserialize <GetHomeInfoResponse>(homeInfoXml).HomeInfo;

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

            var wemo = new Wemo(mockRequest, null);

            // ACT
            var returnedHomeInfo = await wemo.GetWemoResponseObjectAsync <GetHomeInfoResponse>(ipAddress);

            // ASSERT
            Assert.AreEqual(expectedHomeInfo, returnedHomeInfo.HomeInfo);
        }
Esempio n. 2
0
        public void GetResponseObject_Verify()
        {
            // ARRANGE
            var ipAddress = "http://192.168.1.5";
            var wemo      = new Wemo();

            // ACT
            var result = wemo.GetWemoResponseObjectAsync <GetFriendlyNameResponse>(ipAddress).GetAwaiter().GetResult();

            // ASSERT
            Assert.IsNotNull(result.FriendlyName, "The expected type was not returned");
        }
Esempio n. 3
0
        public async Task VerifyWemoDeviceExists()
        {
            // ARRANGE
            var ipAddress = "http://192.168.1.5";
            var wemo      = new Wemo();

            // ACT
            var result = await wemo.GetWemoResponseObjectAsync <GetBinaryStateResponse>(ipAddress);

            // ASSERT
            Assert.IsTrue((result.BinaryState == "0" || result.BinaryState == "1"), "Expected Http StatusCode not returned");
        }