public async Task TurnOnWemoPlugAsync_VerifyAsync() { // ARRANGE var ipAddress = "http://192.168.1.44444"; // 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 getBinaryStateResponseBytes = Encoding.UTF8.GetBytes(File.ReadAllText("TestData\\GetBinaryStateResponse.xml")); // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var mockGetResponseWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", getBinaryStateResponseBytes); var setBinaryStateResponseBytes = Encoding.UTF8.GetBytes(File.ReadAllText("TestData\\SetBinaryStateResponse.xml")); // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var setWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", setBinaryStateResponseBytes); var wemo = new Wemo { // Minimal inversion of control: // Set the WebRequest properties to provide our own Mock'd HttpWebRequest/Response GetResponseWebRequest = mockGetResponseWebRequest, SetResponseWebRequest = setWebRequest }; // ACT var result = await wemo.TurnOnWemoPlugAsync(ipAddress); // ASSERT Assert.IsTrue(result, "WemoPlug not turned on"); }
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); }
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"); }
public async Task ToggleWemoPlugAsync_CustomPort_VerifyAsync() { // ARRANGE var ipAddress = "http://192.168.1.44444"; // 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 getBinaryStateResponseBytes = Encoding.UTF8.GetBytes(File.ReadAllText("TestData\\GetBinaryStateResponse.xml")); // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var mockGetResponseWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", getBinaryStateResponseBytes); var setBinaryStateResponseBytes = Encoding.UTF8.GetBytes(File.ReadAllText("TestData\\SetBinaryStateResponse.xml")); // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var setWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", setBinaryStateResponseBytes); var wemo = new Wemo(mockGetResponseWebRequest, setWebRequest) { PortNumber = 12345 }; // ACT var result = await wemo.ToggleWemoPlugAsync(ipAddress); // ASSERT Assert.IsTrue(result, "WemoPlug not toggled"); }
public async Task TurnOnWemoPlug_Verify() { // ARRANGE var ipAddress = "http://192.168.1.5"; var wemo = new Wemo(); // ACT var result = await wemo.TurnOnWemoPlugAsync(ipAddress); // ASSERT Assert.IsTrue(result, "The switch toggle command was not successful as expected"); }
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"); }
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"); }
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"); }
public void ToggleWemoPlugAsync_Verify() { // ARRANGE var ipAddress = "http://192.168.86.36"; var wemo = new Wemo(); // ACT var result = wemo.ToggleWemoPlugAsync(ipAddress).GetAwaiter().GetResult(); // ASSERT Assert.IsTrue(result, "The switch toggle command was not successful as expected"); }
public void GetListOfLocalWemoDevices_Verify() { // ARRANGE var ipAddressSeed = "http://192.168.1"; var wemo = new Wemo(); // ACT var listOfDevicesFound = wemo.GetListOfLocalWemoDevices(ipAddressSeed); // ASSERT Assert.IsTrue(listOfDevicesFound.Count > 0, $"Expected to locate at least one Wemo device - but nothing located with the supplied IpAddress seed of {ipAddressSeed}"); foreach (var device in listOfDevicesFound) { Console.WriteLine($"IpAddress: {device.Key}, Name: {device.Value}"); } }
/// <summary> /// Run the console app and pass-in a valid IP Address. e.g.: "http://192.168.1.5" /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Toggle a swith for a given IP address var ipAddress = args.FirstOrDefault(); // Verify the ipAddress is an actual ip address var uriConvertSuccess = Uri.TryCreate(ipAddress, UriKind.Absolute, out Uri uri); if (!uriConvertSuccess) { Console.WriteLine("Not a valid Ip Address"); return; } var wemo = new Wemo(); // ACT var result = wemo.ToggleWemoPlugAsync(ipAddress).GetAwaiter().GetResult(); }
public async Task GetListOfLocalWemoDevices_Verify() { // ARRANGE var octetOne = 192; var octetTwo = 168; var octetThree = 86; var ipAddressSeed = $"http://{octetOne}.{octetTwo}.{octetThree}"; var wemo = new Wemo(); // ACT var listOfDevicesFound = await wemo.GetListOfLocalWemoDevicesAsync(octetOne, octetTwo, octetThree); // ASSERT Assert.IsTrue(listOfDevicesFound.Count > 0, $"Expected to locate at least one Wemo device - but nothing located with the supplied IpAddress seed of {ipAddressSeed}"); foreach (var device in listOfDevicesFound) { Console.WriteLine($"IpAddress: {device.Key}, Name: {device.Value}"); } }
public MistySmartDevicesApi() { _wemo = new Wemo(); }