public void ShowSummaryMediaFile_FileName_NoContent() { // Arrange MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())) .Returns(new RestResponse { StatusCode = HttpStatusCode.NoContent }); // Act _mediaFilesApi.ShowMediaFileSummary("test"); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void ValidateCredentials_StatusCodeUnauthorized_ReturnFalse() { // Arrange MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.Unauthorized }); // Act var result = _validator.ValidateCredentials(); // Assert Assert.IsFalse(result); MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void DeleteSipUser_IdUser_ReturnsNoContent() { // Arrange var sipUser = BuildSipUsersLists().First(); MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse <SipUser> { StatusCode = HttpStatusCode.NoContent }); // Act _sipUserAPI.DeleteSipUser(sipUser.Id); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void DeleteCall_Guid_DeleteExecutedOnce() { // Arrange var callId = new Guid("d64baf26-b116-4478-97b5-899de580461f"); MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.Accepted, Content = "{\"ok\" : \"\"}" }); // Act _callsApi.DeleteCall(callId); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void DeleteCdrHttpHandler_Id_NoContent() { // Arrange const int id = 123; MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.NoContent }); // Act _cdrHttpHandler.DeleteCdrHttpHandler(id); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void DeleteRecording_FileName_DeleteExecutedOnce() { // Arrange var fileName = "file1.wav"; MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.NoContent }); // Act _recordingsApi.DeleteRecording(fileName); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void UpdateExternalScriptUrl_ErrorApi_InvalidOperationException() { // Arrange var scripts = BuildExternalScriptsLists(); var id = scripts.First().Id; var name = "Very long name................................."; var scriptUrl = scripts.First().Url; MockIRestClient.Setup(rc => rc.Execute <ExternalScript>(It.IsAny <RestRequest>())).Returns( new RestResponse <ExternalScript> { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(scripts.First()) }); // Act + assert Assert.ThrowsException <ArgumentException>(() => _externalScripts.UpdateExternalScript(id, name, scriptUrl)); MockIRestClient.Verify(x => x.Execute <ExternalScript>(It.IsAny <RestRequest>()), Times.Never); }
public void GetApplications_ListOfApplications_ReturnsApplicationsList() { // Arrange var applications = BuildApplicationsList(); MockIRestClient.Setup(rc => rc.Execute <List <Application> >(It.IsAny <RestRequest>())).Returns( new RestResponse <List <Application> > { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(applications) }); // Act var result = _applicationClientApi.GetApplications(); // Assert applications.Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <List <Application> >(It.IsAny <RestRequest>()), Times.Once); }
public void ValidateCredentials_StatusCodeOK_ReturnTrue() { // Arrange var responseBody = "\"status\": { \"global\": \"Authentication succeeded\" }"; MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.OK, Content = responseBody }); // Act var result = _validator.ValidateCredentials(); // Assert Assert.IsTrue(result); MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); }
public void GetCdrHttpHandlers_ListOfCdrHttpHandlers_ReturnsCdrHttpHandlers() { // Arrange var cdrHttpHandlers = BuildCdrHttpHandlers(); MockIRestClient.Setup(rc => rc.Execute <List <CdrHttpHandler> >(It.IsAny <RestRequest>())).Returns( new RestResponse <List <CdrHttpHandler> > { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(cdrHttpHandlers) }); // Act var result = _cdrHttpHandler.GetCdrHttpHandlers(); // Assert cdrHttpHandlers.Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <List <CdrHttpHandler> >(It.IsAny <RestRequest>()), Times.Once); }
public void GetExternalScriptById_NotFound_ReturnsEmpty() { // Arrange var id = 1L; MockIRestClient.Setup(rc => rc.Execute <ExternalScript>(It.IsAny <RestRequest>())).Returns( new RestResponse <ExternalScript> { StatusCode = HttpStatusCode.NotFound }); // Act var result = _externalScripts.GetExternalScript(id); // Assert Assert.IsNull(result); MockIRestClient.Verify(x => x.Execute <ExternalScript>(It.IsAny <RestRequest>()), Times.Once); }
public void GetExternalScripts_ListOfExternalScripts_ReturnsScriptsList() { // Arrange var scripts = BuildExternalScriptsLists(); MockIRestClient.Setup(rc => rc.Execute <List <ExternalScript> >(It.IsAny <RestRequest>())).Returns( new RestResponse <List <ExternalScript> > { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(scripts) }); // Act var result = _externalScripts.GetExternalScripts(); // Assert scripts.Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <List <ExternalScript> >(It.IsAny <RestRequest>()), Times.Once); }
public void DownloadMediaFile_FileExistsOnServer_MemoryStream() { // Arrange var expectedStream = new FileStream(SOURCE_FILE.FullName, FileMode.Create); MockIRestClient.Setup(rc => rc.DownloadData(It.IsAny <RestRequest>())).Returns(expectedStream.ReadAsBytes()); // Act var result = _mediaFilesApi.DownloadMediaFile(SOURCE_FILE_NAME); // Assert Assert.AreSame(expectedStream.ReadAsBytes(), result); MockIRestClient.Verify(x => x.DownloadData(It.IsAny <RestRequest>()), Times.Once); // Clean expectedStream.Close(); }
public void UpdateExternalScriptUrl_NameIsTooLong_ApiNotInvokedArgumentException() { // Arrange var scripts = BuildExternalScriptsLists(); var id = scripts.First().Id; var name = scripts.First().Name; var scriptUrl = scripts.First().Url; MockIRestClient.Setup(rc => rc.Execute <ExternalScript>(It.IsAny <RestRequest>())).Returns( new RestResponse <ExternalScript> { StatusCode = HttpStatusCode.InternalServerError }); // Act + assert Assert.ThrowsException <InvalidOperationException>(() => _externalScripts.UpdateExternalScript(id, name, scriptUrl)); MockIRestClient.Verify(x => x.Execute <ExternalScript>(It.IsAny <RestRequest>()), Times.Once); }
public void GetCallByGuid_StatusCodeNotFound_ReturnsNull() { // Arrange var guid = Guid.NewGuid(); MockIRestClient.Setup(rc => rc.Execute <Call>(It.IsAny <RestRequest>())).Returns( new RestResponse <Call> { StatusCode = HttpStatusCode.NotFound, Content = string.Empty }); // Act var result = _callsApi.GetCall(guid); // Assert Assert.IsNull(result); MockIRestClient.Verify(x => x.Execute <Call>(It.IsAny <RestRequest>()), Times.Once); }
public void DownloadRecording_SourceFile_Stream() { // Arrange var expectedStream = new FileStream(SOURCE_FILE.FullName, FileMode.Create); MockIRestClient.Setup(rc => rc.DownloadData(It.IsAny <RestRequest>())).Returns(expectedStream.ReadAsBytes()); // Act var result = _recordingsApi.DownloadRecording(SOURCE_FILE_NAME); // Assert Assert.AreSame(expectedStream.ReadAsBytes(), result.ReadAsBytes()); MockIRestClient.Verify(x => x.DownloadData(It.IsAny <RestRequest>()), Times.Once); // Clean result.Close(); expectedStream.Close(); }
public void GetSingleSipUser_IdSipUser_ReturnsSingleSipUser() { // Arrange var sipUser = BuildSipUsersLists().First(); MockIRestClient.Setup(rc => rc.Execute <SipUser>(It.IsAny <RestRequest>())).Returns( new RestResponse <SipUser> { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(sipUser) }); // Act var result = _sipUserAPI.GetSingleSipUser(sipUser.Id); // Assert sipUser.Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <SipUser>(It.IsAny <RestRequest>()), Times.Once); }
public void UpdateExternalScriptUrl_IdAndUrl_ScriptUpdated() { // Arrange var scripts = BuildExternalScriptsLists(); var id = scripts.First().Id; var scriptUrl = scripts.First().Url; MockIRestClient.Setup(rc => rc.Execute <ExternalScript>(It.IsAny <RestRequest>())).Returns( new RestResponse <ExternalScript> { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(scripts.First()) }); // Act var result = _externalScripts.UpdateExternalScriptUrl(id, scriptUrl); // Assert scripts.First().Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <ExternalScript>(It.IsAny <RestRequest>()), Times.Once); }
public void CreateCdrHttpHandler_NameAndUri_ReturnsNewCdrHttpHandler() { // Arrange var cdrHttpHandlers = BuildCdrHttpHandlers(); var name = cdrHttpHandlers.First().Name; var uri = cdrHttpHandlers.First().Url; MockIRestClient.Setup(rc => rc.Execute <CdrHttpHandler>(It.IsAny <RestRequest>())).Returns( new RestResponse <CdrHttpHandler> { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(cdrHttpHandlers.First()) }); // Act var result = _cdrHttpHandler.CreateCdrHttpHandler(name, uri); // Assert cdrHttpHandlers.First().Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <CdrHttpHandler>(It.IsAny <RestRequest>()), Times.Once); }
public void UpdateCdrHttpHandlerName_IdAndName_ReturnsUpdatedCdrHttpHandler() { // Arrange var cdrHttpHandlers = BuildCdrHttpHandlers(); var id = cdrHttpHandlers.First().Id; var name = cdrHttpHandlers.First().Name; MockIRestClient.Setup(rc => rc.Execute <CdrHttpHandler>(It.IsAny <RestRequest>())).Returns( new RestResponse <CdrHttpHandler> { StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(cdrHttpHandlers.First()) }); // Act var result = _cdrHttpHandler.UpdateCdrHttpHandlerName(id, name); // Assert cdrHttpHandlers.First().Should().BeEquivalentTo(result); MockIRestClient.Verify(x => x.Execute <CdrHttpHandler>(It.IsAny <RestRequest>()), Times.Once); }
public void GetRecordingsList_ListOfRecordingsAreOnServer_ReturnsListOfRecordings() { // Arrange var recordings = new List <string> { "file1.wav", "file2.wav", "file3.wav" }; MockIRestClient.Setup(rc => rc.Execute <List <string> >(It.IsAny <RestRequest>())).Returns( new RestResponse <List <string> > { StatusCode = HttpStatusCode.OK, Content = JsonConvert.SerializeObject(recordings) }); // Act var result = _recordingsApi.GetRecordings(); // Assert MockIRestClient.Verify(x => x.Execute <List <string> >(It.IsAny <RestRequest>()), Times.Once); recordings.Should().BeEquivalentTo(result); }
public void UploadMediaFile_FileWavFromDisk_StatusOK() { // Arrange var expectedStream = new FileStream(SOURCE_FILE.FullName, FileMode.Create); MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns(new RestResponse { StatusCode = HttpStatusCode.OK, Content = JsonConvert.SerializeObject(new Response()) }); // Act var result = _mediaFilesApi.UploadMediaFile("test", SOURCE_FILE.FullName); // Assert Assert.IsNotNull(result); MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); // Clean expectedStream.Close(); }
public async Task DownloadRecordingAsync_SourceFile_Stream() { // Arrange var expectedStream = new FileStream(SOURCE_FILE.FullName, FileMode.Create); MockIRestClient.Setup(rc => rc.ExecuteTaskAsync(It.IsAny <RestRequest>())).ReturnsAsync( new RestResponse() { StatusCode = HttpStatusCode.OK, RawBytes = expectedStream.ReadAsBytes() }); // Act await _recordingsApi.DownloadRecordingToFileAsync(SOURCE_FILE_NAME, TARGET_DIR); // Assert MockIRestClient.Verify(x => x.ExecuteTaskAsync(It.IsAny <RestRequest>()), Times.Once); Assert.AreEqual(Path.GetFileName(expectedStream.Name), TARGET_FILE.Name); // Clean expectedStream.Close(); }
public void DownloadRecordingToFile_SourceFile_FileWithChangedName() { // Arrange var expectedStream = new FileStream(SOURCE_FILE.FullName, FileMode.Create); MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse() { StatusCode = HttpStatusCode.OK, RawBytes = expectedStream.ReadAsBytes() }); // Act var result = _recordingsApi.DownloadRecordingToFile(SOURCE_FILE_NAME, TARGET_FILE_WITH_CHANGED_NAME.FullName); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); Assert.AreEqual(Path.GetFileName(TARGET_FILE_WITH_CHANGED_NAME.FullName), result.Name); // Clean expectedStream.Close(); }
public void GetMediaFileList_ListOfMediaFileListAreOnServer_ReturnsListOfMediaFiles() { // Arrange var mediaFiles = new List <MediaFile> { new MediaFile { Name = "file1.wav" }, new MediaFile { Name = "file2.wav" } }; MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns( new RestResponse { StatusCode = HttpStatusCode.OK, Content = JsonConvert.SerializeObject(mediaFiles) }); // Act var result = _mediaFilesApi.GetMediaFilesList(); // Assert MockIRestClient.Verify(x => x.Execute(It.IsAny <RestRequest>()), Times.Once); mediaFiles.Should().BeEquivalentTo(result); }