コード例 #1
0
ファイル: MessageTest.cs プロジェクト: bednarz1990/sdk-dotnet
        public void SendTextMessage_WithPhoneNumbersAndMessage_ResponseServerError()
        {
            // Arrange
            MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>()))
            .Returns(new RestResponse {
                StatusCode = HttpStatusCode.InternalServerError
            });

            // Act + Assert
            Assert.ThrowsException <InvalidOperationException>(() => _messageApi.SendTextMessage(new PhoneNumber("123456789"), new PhoneNumber("123456789"), "Hello"));
        }
コード例 #2
0
        public void ValidateCredentials_StatusCodeInternalServerError_ShouldThrowIOException()
        {
            // Arrange
            MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns(
                new RestResponse {
                StatusCode = HttpStatusCode.InternalServerError
            });

            // Act + Assert
            Assert.ThrowsException <InvalidOperationException>(() => _validator.ValidateCredentials());
        }
コード例 #3
0
ファイル: MessageTest.cs プロジェクト: bednarz1990/sdk-dotnet
        public void SendTextMessage_WithPhoneNumbersAndNoMessage_ArgumentExceptionThrowed()
        {
            // Arrange
            MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns(
                new RestResponse {
                StatusCode = HttpStatusCode.OK
            });

            // Act + Assert
            Assert.ThrowsException <ArgumentException>(() => _messageApi.SendTextMessage(new PhoneNumber("123456789"), new PhoneNumber("123456789"), null));
        }
コード例 #4
0
        public async Task DownloadRecordingAsync_ApiReturnsError_FailureInvoked()
        {
            // Arrange
            MockIRestClient.Setup(rc => rc.ExecuteTaskAsync(It.IsAny <RestRequest>())).ReturnsAsync(
                new RestResponse()
            {
                StatusCode = HttpStatusCode.InternalServerError
            });

            // Act + Assert
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => _recordingsApi.DownloadRecordingToFileAsync(SOURCE_FILE_NAME, TARGET_DIR));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: CallsTests.cs プロジェクト: bednarz1990/sdk-dotnet
        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);
        }
コード例 #8
0
ファイル: CallsTests.cs プロジェクト: bednarz1990/sdk-dotnet
        public void GetCalls_ListOfCalls_ReturnsCalls()
        {
            // Arrange
            var calls = BuildCallsList();

            MockIRestClient.Setup(rc => rc.Execute <List <Call> >(It.IsAny <RestRequest>())).Returns(
                new RestResponse <List <Call> > {
                StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(calls)
            });

            // Act
            var result = _callsApi.GetCalls();

            // Assert
            calls.Should().BeEquivalentTo(result);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
ファイル: MessageTest.cs プロジェクト: bednarz1990/sdk-dotnet
        public void SendTextMessage_WithPhoneNumbersAndMessage_ResponseBodyOK()
        {
            // Arrange
            var responseBody = "{\"ok\":true,\"message\":\"SMS sent\"}";

            MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns(
                new RestResponse {
                StatusCode = HttpStatusCode.OK, Content = responseBody
            });

            // Act
            var result = _messageApi.SendTextMessage(new PhoneNumber("123456789"), new PhoneNumber("123456789"), "Hello");

            // Assert
            Assert.AreEqual(result, responseBody);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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();
        }
コード例 #20
0
ファイル: CallsTests.cs プロジェクト: bednarz1990/sdk-dotnet
        public void DeleteCall_FailureMessage_DeleteCallResponseException()
        {
            // Arrange
            var callId         = new Guid("d64baf26-b116-4478-97b5-899de580461f");
            var failureMessage = "NORMAL TEMPORARY_FAILURE";

            MockIRestClient.Setup(rc => rc.Execute(It.IsAny <RestRequest>())).Returns(
                new RestResponse {
                StatusCode = HttpStatusCode.Accepted, Content = "{\"failure\" : \"" + failureMessage + "\"}"
            });

            // Act + Assert
            var exception = Assert.ThrowsException <DeleteCallResponseException>(() =>
                                                                                 _callsApi.DeleteCall(callId));

            Assert.AreEqual(failureMessage, exception.Message);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
ファイル: CallsTests.cs プロジェクト: bednarz1990/sdk-dotnet
        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);
        }
コード例 #23
0
        public void CreateSipUser_SipUserWithName_ReturnsSipUser()
        {
            // 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.CreateSipUser(sipUser.Name);

            // Assert
            Assert.AreEqual(result.Name, sipUser.Name);
        }
コード例 #24
0
ファイル: CallsTests.cs プロジェクト: bednarz1990/sdk-dotnet
        public void GetCallByGuid_OneCall_ReturnsProperCall()
        {
            // Arrange
            var calls = BuildCallsList();
            var guid  = calls.First().Uuid;

            MockIRestClient.Setup(rc => rc.Execute <Call>(It.IsAny <RestRequest>())).Returns(
                new RestResponse <Call> {
                StatusCode = HttpStatusCode.Accepted, Content = JsonConvert.SerializeObject(calls.First())
            });

            // Act
            var result = _callsApi.GetCall(guid);

            // Assert
            Assert.IsNotNull(result);
            calls.First().Should().BeEquivalentTo(result);
        }
コード例 #25
0
        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();
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }