public async Task GetDoorbotsHistory_Verify() { // ARRANGE // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- AUTH var mockHttpWebRequestAuth = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- Devices var mockHttpWebRequestDoorbotHistory = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedDoorbotsHistoryResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequestAuth, DoorbotHistoryRequest = mockHttpWebRequestDoorbotHistory }; // Authenticate var actualSessionAuthObject = await comm.Authenticate(); // Acquire Doorbot History var actualDoorbotsHistoryList = await comm.GetDoorbotsHistory(); Assert.AreEqual(ExpectedDoorbotsHistoryList.Count, actualDoorbotsHistoryList.Count, "The DoorbotsHistoryList doesn't contain the same number of items as expected"); // Compare all itesm within the ExpectedList and the actual var cnt = 0; foreach (var expected in ExpectedDoorbotsHistoryList) { ObjectCompare(expected, actualDoorbotsHistoryList[cnt]); cnt++; } }
public async Task AuthenticateSuccessTest() { var session = new RingCommunications(Username, Password); var authResult = await session.Authenticate(); Assert.IsFalse(string.IsNullOrEmpty(authResult.Profile.AuthenticationToken), "Failed to authenticate"); }
public async Task GetDoorbotsHistoryTest() { var session = new RingCommunications(Username, Password); await session.Authenticate(); var doorbotHistory = await session.GetDoorbotsHistory(); Assert.IsTrue(doorbotHistory.Count > 0, "No doorbot history items returned"); }
public async Task GetDevicesTest() { var session = new RingCommunications(Username, Password); await session.Authenticate(); var devices = await session.GetRingDevices(); Assert.IsTrue(devices.Chimes.Count > 0 && devices.Doorbots.Count > 0, "No doorbots and/or chimes returned"); }
public async Task GetDoorbotsHistoryRecordingByInstanceTest() { var session = new RingCommunications(Username, Password); await session.Authenticate(); var doorbotHistory = await session.GetDoorbotsHistory(); Assert.IsTrue(doorbotHistory.Count > 0, "No doorbot history events were found"); var tempFilePath = Path.GetTempFileName(); await session.GetDoorbotHistoryRecording(doorbotHistory[0], tempFilePath); File.Delete(tempFilePath); }
public async Task Authenticate_ExpectSuccess() { // ARRANGE // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var mockHttpWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequest }; var actualAuthenticationSession = await comm.Authenticate(); //ASSERT ObjectCompare(ExpectedAuthenticationSession, actualAuthenticationSession); }
public async Task Authenticate_VerifyToken() { // ARRANGE // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var mockHttpWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequest }; var actualAuthenticationSession = await comm.Authenticate(); // ASSERT Assert.IsTrue(!string.IsNullOrEmpty(actualAuthenticationSession.Profile.AuthenticationToken), "Failed to authenticate"); }
public async Task Authenticate_VerifyCredentialsEncoded() { // ARRANGE // Mock the HttpWebRequest and HttpWebResponse (which is within the request) var mockHttpWebRequest = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequest }; var actualSessionObject = await comm.Authenticate(); var base64DecodedCredentials = Encoding.UTF8.GetString(Convert.FromBase64String(comm.CredentialsEncoded)); Assert.AreEqual(base64DecodedCredentials, $"{Username}:{Password}", "Base64 Credential Decoding failed"); }
public async Task GetDoorbotHistoryRecording_Verify() { // ARRANGE // Set the path to the acquired 'downlaoaded' file (no file is actually downloaded, thanks to MOQ :) ) var tempFilePath = Path.GetTempFileName(); // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- AUTH var mockHttpWebRequestAuth = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- Devices var mockHttpWebRequestDoorbotDownloadFile = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedDoorbotsDownloadFileResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequestAuth, DoorbotFileRequest = mockHttpWebRequestDoorbotDownloadFile }; // Authenticate var actualSessionAuthObject = await comm.Authenticate(); // Acquire a Doorbot file await comm.GetDoorbotHistoryRecordingAndCreateFile("1", tempFilePath); // ASSERT // Read-in the 'expected' download-file bytes var acquiredFileBytes = File.ReadAllBytes(tempFilePath); // Let's cleanup the temp file, regardless of pass-or-fail File.Delete(tempFilePath); CollectionAssert.AreEqual(ExpectedDoorbotsDownloadFileResponseBytes, acquiredFileBytes, "Expected file bytes are not matching with the acquired"); }
public async Task GetRingDevices_Verify() { // ARRANGE // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- AUTH var mockHttpWebRequestAuth = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedAuthenticationResponseBytes); // Mock the HttpWebRequest and HttpWebResponse (which is within the request)- Devices var mockHttpWebRequestDevices = CreateMockHttpWebRequest(HttpStatusCode.NotModified, "A-OK", ExpectedDevicesResponseBytes); // ACT var comm = new RingCommunications(Username, Password) { AuthRequest = mockHttpWebRequestAuth, DevicesRequest = mockHttpWebRequestDevices }; // Authenticate var actualSessionAuthObject = await comm.Authenticate(); var actualDevices = await comm.GetRingDevices(); Assert.IsTrue(actualDevices.Chimes.Count > 0 && actualDevices.Doorbots.Count > 0, "No doorbots and/or chimes returned"); }
public async Task AuthenticateFailTest() { var session = new RingCommunications("*****@*****.**", "someinvalidpassword"); await session.Authenticate(); }