diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 5a1025e..75fcdfe 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -6,20 +6,36 @@ on: pull_request: branches: [ master ] +env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_NOLOGO: true + jobs: build: - runs-on: ubuntu-latest - + steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 3.1.x + dotnet-version: '9.0.x' + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- + - name: Restore dependencies run: dotnet restore + - name: Build - run: dotnet build --no-restore + run: dotnet build --no-restore --configuration Release + - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test --no-build --configuration Release --verbosity normal \ No newline at end of file diff --git a/NEventSocket.Tests/Applications/Applications.cs b/NEventSocket.Tests/Applications/Applications.cs index b562c1a..39f8fa1 100644 --- a/NEventSocket.Tests/Applications/Applications.cs +++ b/NEventSocket.Tests/Applications/Applications.cs @@ -2,11 +2,12 @@ { using NEventSocket.FreeSwitch; - using Xunit; + using NUnit.Framework; + [TestFixture] public class Applications { - [Fact] + [Test] public void can_build_say_string() { var options = new SayOptions @@ -20,10 +21,10 @@ public void can_build_say_string() var toString = options.ToString(); - Assert.Equal("en NUMBER iterated FEMININE 1234", toString); + Assert.That(toString, Is.EqualTo("en NUMBER iterated FEMININE 1234")); } - [Fact] + [Test] public void can_build_originate_string() { var options = new OriginateOptions() @@ -50,10 +51,10 @@ public void can_build_originate_string() const string Expected = "{origination_uuid='985cea12-4e70-4c03-8a2c-2c4b4502bbbb',bypass_media='true',origination_caller_id_name='Test',origination_caller_id_number='12341234',execute_on_originate='start_dtmf',ignore_early_media='true',originate_retries='3',originate_retry_sleep_ms='4000',return_ring_ready='true',originate_timeout='20',hangup_after_bridge='false',foo='bar',baz='widgets'}"; - Assert.Equal(Expected, toString); + Assert.That(toString, Is.EqualTo(Expected)); } - [Fact] + [Test] public void can_build_play_get_digits_string() { var options = new PlayGetDigitsOptions() @@ -72,7 +73,7 @@ public void can_build_play_get_digits_string() var toString = options.ToString(); - Assert.Equal(@"4 8 3 4000 # ivr/8000/ivr-please_enter_pin_followed_by_pound.wav ivr/8000/ivr-that_was_an_invalid_entry.wav play_get_digits_result ^(1|2|3|4|5|6|7|8|9|0)+ 2000", toString); + Assert.That(toString, Is.EqualTo(@"4 8 3 4000 # ivr/8000/ivr-please_enter_pin_followed_by_pound.wav ivr/8000/ivr-that_was_an_invalid_entry.wav play_get_digits_result ^(1|2|3|4|5|6|7|8|9|0)+ 2000")); } } } \ No newline at end of file diff --git a/NEventSocket.Tests/Applications/BridgeTests.cs b/NEventSocket.Tests/Applications/BridgeTests.cs index 0b11124..c47547a 100644 --- a/NEventSocket.Tests/Applications/BridgeTests.cs +++ b/NEventSocket.Tests/Applications/BridgeTests.cs @@ -1,15 +1,15 @@ namespace NEventSocket.Tests.Applications { - using System.IO; - using System.Runtime.Serialization.Formatters.Binary; + using System.Text.Json; using NEventSocket.FreeSwitch; - using Xunit; + using NUnit.Framework; + [TestFixture] public class BridgeTests { - [Fact] + [Test] public void can_format_BridgeOptions() { var options = new BridgeOptions() @@ -24,45 +24,38 @@ public void can_format_BridgeOptions() RingBack = "${uk-ring}" }; - // channel variables have no effect on ToString(), they're set on the a-leg of the call before initiating the bridge. // todo: allow exporting variables? options.ChannelVariables.Add("foo", "bar"); options.ChannelVariables.Add("baz", "widgets"); var toString = options.ToString(); const string Expected = "{origination_uuid='985cea12-4e70-4c03-8a2c-2c4b4502bbbb',leg_timeout='20',origination_caller_id_name='Dan B Leg',origination_caller_id_number='987654321',ignore_early_media='true'}"; - Assert.Equal(Expected, toString); + Assert.That(toString, Is.EqualTo(Expected)); } - [Fact] + [Test] public void can_serialize_and_deserialize_BridgeOptions() { - using (var ms = new MemoryStream()) + var options = new BridgeOptions() { - var formatter = new BinaryFormatter(); - - var options = new BridgeOptions() - { - UUID = "985cea12-4e70-4c03-8a2c-2c4b4502bbbb", - TimeoutSeconds = 20, - CallerIdName = "Dan B Leg", - CallerIdNumber = "987654321", - HangupAfterBridge = false, - IgnoreEarlyMedia = true, - ContinueOnFail = true, - RingBack = "${uk-ring}" - }; + UUID = "985cea12-4e70-4c03-8a2c-2c4b4502bbbb", + TimeoutSeconds = 20, + CallerIdName = "Dan B Leg", + CallerIdNumber = "987654321", + HangupAfterBridge = false, + IgnoreEarlyMedia = true, + ContinueOnFail = true, + RingBack = "${uk-ring}" + }; - options.ChannelVariables.Add("foo", "bar"); - options.ChannelVariables.Add("baz", "widgets"); + options.ChannelVariables.Add("foo", "bar"); + options.ChannelVariables.Add("baz", "widgets"); - formatter.Serialize(ms, options); + var json = JsonSerializer.Serialize(options); - ms.Seek(0, SeekOrigin.Begin); + var fromJson = JsonSerializer.Deserialize(json); - var fromStream = formatter.Deserialize(ms) as BridgeOptions; - Assert.Equal(options, fromStream); - } + Assert.That(fromJson.ChannelVariables, Is.EquivalentTo(options.ChannelVariables)); } } } \ No newline at end of file diff --git a/NEventSocket.Tests/Applications/OriginateTests.cs b/NEventSocket.Tests/Applications/OriginateTests.cs index 9a15c59..f7336ad 100644 --- a/NEventSocket.Tests/Applications/OriginateTests.cs +++ b/NEventSocket.Tests/Applications/OriginateTests.cs @@ -1,16 +1,16 @@ namespace NEventSocket.Tests.Applications { using System.Collections.Generic; - using System.IO; - using System.Runtime.Serialization.Formatters.Binary; + using System.Text.Json; using NEventSocket.FreeSwitch; - using Xunit; + using NUnit.Framework; + [TestFixture] public class OriginateTests { - [Fact] + [Test] public void can_format_originate_options() { var options = new OriginateOptions() @@ -26,26 +26,25 @@ public void can_format_originate_options() IgnoreEarlyMedia = true, }; - Assert.Equal( - "{origination_caller_id_name='Dan',origination_caller_id_number='0123457890',execute_on_originate='my_app::my_arg',originate_retries='5',originate_retry_sleep_ms='200',return_ring_ready='true',originate_timeout='60',origination_uuid='83fe4f3d-b957-4b26-b6bf-3879d7e21972',ignore_early_media='true'}", - options.ToString()); + Assert.That(options.ToString(), Is.EqualTo( + "{origination_caller_id_name='Dan',origination_caller_id_number='0123457890',execute_on_originate='my_app::my_arg',originate_retries='5',originate_retry_sleep_ms='200',return_ring_ready='true',originate_timeout='60',origination_uuid='83fe4f3d-b957-4b26-b6bf-3879d7e21972',ignore_early_media='true'}")); } - [Fact] + [Test] public void can_set_enterprise_channel_variables() { - var options = new OriginateOptions - { + var options = new OriginateOptions + { EnterpriseChannelVariables = new Dictionary { {"e1" , "ev1"}, {"e2" , "ev2"} } }.ToString(); - Assert.Contains("", options); + Assert.That(options, Does.Contain("")); } - [Fact] + [Test] public void can_set_enterprise_channel_variables_and_channel_variables() { var options = new OriginateOptions @@ -53,50 +52,43 @@ public void can_set_enterprise_channel_variables_and_channel_variables() EnterpriseChannelVariables = new Dictionary { { "e1", "ev1" }, { "e2", "ev2" } }, ChannelVariables = new Dictionary { { "c1", "cv1" }, { "c2", "cv2" } } }.ToString(); - Assert.Contains("{c1='cv1',c2='cv2'}", options); + Assert.That(options, Does.Contain("{c1='cv1',c2='cv2'}")); } - [Fact] + [Test] public void can_set_caller_id_type() { var options = new OriginateOptions() { SipCallerIdType = SipCallerIdType.RPid }.ToString(); - Assert.Contains("sip_cid_type='rpid'", options); + Assert.That(options, Does.Contain("sip_cid_type='rpid'")); } - [Fact] + [Test] public void can_set_privacy() { var options = new OriginateOptions() { OriginationPrivacy = OriginationPrivacy.HideName | OriginationPrivacy.HideNumber | OriginationPrivacy.Screen}.ToString(); - Assert.Contains("origination_privacy='hide_name:hide_number:screen'", options); + Assert.That(options, Does.Contain("origination_privacy='hide_name:hide_number:screen'")); } - [Fact] + [Test] public void can_serialize_and_deserialize_OriginateOptions() { - using (var ms = new MemoryStream()) - { - var formatter = new BinaryFormatter(); - var options = new OriginateOptions() - { - CallerIdName = "Dan", - CallerIdNumber = "0123457890", - ExecuteOnOriginate = "my_app::my_arg", - Retries = 5, - RetrySleepMs = 200, - ReturnRingReady = true, - TimeoutSeconds = 60, - UUID = "83fe4f3d-b957-4b26-b6bf-3879d7e21972", - IgnoreEarlyMedia = true, - }; - - formatter.Serialize(ms, options); + { + CallerIdName = "Dan", + CallerIdNumber = "0123457890", + ExecuteOnOriginate = "my_app::my_arg", + Retries = 5, + RetrySleepMs = 200, + ReturnRingReady = true, + TimeoutSeconds = 60, + UUID = "83fe4f3d-b957-4b26-b6bf-3879d7e21972", + IgnoreEarlyMedia = true, + }; - ms.Seek(0, SeekOrigin.Begin); + var json = JsonSerializer.Serialize(options); + var fromJson = JsonSerializer.Deserialize(json); - var fromStream = formatter.Deserialize(ms) as OriginateOptions; - Assert.Equal(options, fromStream); - } + Assert.That(fromJson.ChannelVariables, Is.EquivalentTo(options.ChannelVariables)); } } } \ No newline at end of file diff --git a/NEventSocket.Tests/NEventSocket.Tests.csproj b/NEventSocket.Tests/NEventSocket.Tests.csproj index 079c537..cc4e418 100644 --- a/NEventSocket.Tests/NEventSocket.Tests.csproj +++ b/NEventSocket.Tests/NEventSocket.Tests.csproj @@ -1,17 +1,19 @@  - netcoreapp3.1 + net9.0 false + true - - - - - + + + + + + diff --git a/NEventSocket.Tests/Sockets/InboundSocketTests.cs b/NEventSocket.Tests/Sockets/InboundSocketTests.cs index ec42ee4..9285dc9 100644 --- a/NEventSocket.Tests/Sockets/InboundSocketTests.cs +++ b/NEventSocket.Tests/Sockets/InboundSocketTests.cs @@ -2,21 +2,23 @@ { using System; using System.Reactive.Linq; - using System.Text.RegularExpressions; + using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Logging; + using NUnit.Framework; + using NEventSocket; using NEventSocket.Logging; using NEventSocket.Tests.Fakes; using NEventSocket.Tests.TestSupport; - using Xunit; - + [TestFixture] public class InboundSocketTests { - public InboundSocketTests() + [SetUp] + public void SetUp() { PreventThreadPoolStarvation.Init(); Logger.Configure(LoggerFactory.Create(builder => @@ -29,7 +31,7 @@ public InboundSocketTests() })); } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task sending_a_correct_password_should_connect() { using (var listener = new FakeFreeSwitchListener(0)) @@ -63,17 +65,17 @@ public async Task sending_a_correct_password_should_connect() using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { - Assert.True(authRequestReceived); + Assert.That(authRequestReceived, Is.True); await client.Exit(); await Wait.Until(() => exitRequestReceived); - Assert.True(exitRequestReceived); + Assert.That(exitRequestReceived, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public void an_invalid_password_should_throw_an_InboundSocketConnectionFailedException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -95,27 +97,27 @@ public void an_invalid_password_should_throw_an_InboundSocketConnectionFailedExc await socket.Send("Content-Type: auth/request"); }); - var aggregateException = Record.Exception(() => InboundSocket.Connect("127.0.0.1", listener.Port, "WrongPassword").Wait()); - Assert.True(authRequestReceived); - Assert.IsType(aggregateException.InnerException); - Assert.Equal("Invalid password when trying to connect to 127.0.0.1:" + listener.Port, aggregateException.InnerException.Message); + var aggregateException = Assert.Throws(() => InboundSocket.Connect("127.0.0.1", listener.Port, "WrongPassword").Wait()); + Assert.That(authRequestReceived, Is.True); + Assert.That(aggregateException.InnerException, Is.TypeOf()); + Assert.That(aggregateException.InnerException.Message, Is.EqualTo("Invalid password when trying to connect to 127.0.0.1:" + listener.Port)); } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public void when_no_AuthRequest_received_it_should_throw_TimeoutException_wrapped_in_InboundSocketConnectionFailedException() { using (var listener = new FakeFreeSwitchListener(0)) { listener.Start(); - var aggregateException = Record.Exception(() => InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Wait()); - Assert.IsType(aggregateException.InnerException); - Assert.IsType(aggregateException.InnerException.InnerException); + var aggregateException = Assert.Throws(() => InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Wait()); + Assert.That(aggregateException.InnerException, Is.TypeOf()); + Assert.That(aggregateException.InnerException.InnerException, Is.TypeOf()); } } - [Fact(Timeout = 5000, Skip = "Removing timeouts")] + [Test, CancelAfter(5000), Ignore("Removing timeouts")] public void when_no_response_to_auth_received_it_should_throw_TimeoutException_wrapped_in_InboundSocketConnectionFailedException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -128,13 +130,13 @@ public void when_no_response_to_auth_received_it_should_throw_TimeoutException_w await socket.Send("Content-Type: auth/request"); }); - var aggregateException = Record.Exception(() => InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Wait()); - Assert.IsType(aggregateException.InnerException); - Assert.IsType(aggregateException.InnerException.InnerException); + var aggregateException = Assert.Throws(() => InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Wait()); + Assert.That(aggregateException.InnerException, Is.TypeOf()); + Assert.That(aggregateException.InnerException.InnerException, Is.TypeOf()); } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_api() { using (var listener = new FakeFreeSwitchListener(0)) @@ -165,12 +167,12 @@ public async Task can_send_api() using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { var result = await client.SendApi("status"); - Assert.True(result.Success); + Assert.That(result.Success, Is.True); } } } - [Fact(Timeout = 5000, Skip = "Removing timeouts")] + [Test, CancelAfter(5000), Ignore("Removing timeouts")] public async Task when_no_api_response_received_it_should_throw_a_TimeOutException() { using (var listener = new FakeFreeSwitchListener(0)) @@ -207,21 +209,21 @@ public async Task when_no_api_response_received_it_should_throw_a_TimeOutExcepti await socket.Send("Content-Type: auth/request"); }); - using (var client = InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Result) + using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100))) { client.ResponseTimeOut = TimeSpan.FromMilliseconds(100); - var ex = Record.Exception(() => client.SendApi("status").Wait()); + var ex = Assert.Throws(() => client.SendApi("status").Wait()); - Assert.NotNull(ex); - Assert.IsType(ex.InnerException); - Assert.True(apiRequestReceived); + Assert.That(ex, Is.Not.Null); + Assert.That(ex.InnerException, Is.TypeOf()); + Assert.That(apiRequestReceived, Is.True); await client.Exit(); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_command() { using (var listener = new FakeFreeSwitchListener(0)) @@ -252,12 +254,12 @@ public async Task can_send_command() using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { var result = await client.SendCommand("test"); - Assert.True(result.Success); + Assert.That(result.Success, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_multiple_commands() { using (var listener = new FakeFreeSwitchListener(0)) @@ -295,16 +297,16 @@ public async Task can_send_multiple_commands() using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { var result = await client.SendCommand("test"); - Assert.True(result.Success); + Assert.That(result.Success, Is.True); result = await client.SendCommand("event CHANNEL_ANSWER"); - Assert.False(result.Success); + Assert.That(result.Success, Is.False); } } } - [Fact(Timeout = 5000, Skip = "Removing timeouts")] - public void when_no_command_reply_received_it_should_throw_a_TimeOutException() + [Test, CancelAfter(5000), Ignore("Removing timeouts")] + public async Task when_no_command_reply_received_it_should_throw_a_TimeOutException() { using (var listener = new FakeFreeSwitchListener(0)) { @@ -332,17 +334,17 @@ public void when_no_command_reply_received_it_should_throw_a_TimeOutException() await socket.Send("Content-Type: auth/request"); }); - using (var client = InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100)).Result) + using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon", TimeSpan.FromMilliseconds(100))) { - var ex = Record.Exception(() => client.SendCommand("test").Wait()); - Assert.NotNull(ex); - Assert.IsType(ex.InnerException); - Assert.True(commandRequestReceived); + var ex = Assert.Throws(() => client.SendCommand("test").Wait()); + Assert.That(ex, Is.Not.Null); + Assert.That(ex.InnerException, Is.TypeOf()); + Assert.That(commandRequestReceived, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs, Skip = "Removing timeouts")] + [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Removing timeouts")] public async Task when_the_inbound_socket_is_disposed_it_should_complete_the_observables() { using (var listener = new FakeFreeSwitchListener(0)) @@ -382,12 +384,12 @@ public async Task when_the_inbound_socket_is_disposed_it_should_complete_the_obs client.Dispose(); await Wait.Until(() => completed); - Assert.True(completed); + Assert.That(completed, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task when_FreeSwitch_disconnects_it_should_complete_the_observables() { using (var listener = new FakeFreeSwitchListener(0)) @@ -433,12 +435,12 @@ public async Task when_FreeSwitch_disconnects_it_should_complete_the_observables await Wait.Until(() => completed); - Assert.True(completed); + Assert.That(completed, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task when_a_command_reply_error_is_received_in_response_to_an_application_request_it_should_return_a_failed_ApplicationResult() { using (var listener = new FakeFreeSwitchListener(0)) @@ -473,12 +475,12 @@ public async Task when_a_command_reply_error_is_received_in_response_to_an_appli using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { var result = await client.Play("c1cdaeae-ebb0-4f3f-8f75-0f673bfbc046", "test.wav"); - Assert.False(result.Success); + Assert.That(result.Success, Is.False); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task when_a_CHANNEL_EXECUTE_COMPLETE_event_is_returned_it_should_complete_the_Application() { using (var listener = new FakeFreeSwitchListener(0)) @@ -526,8 +528,8 @@ public async Task when_a_CHANNEL_EXECUTE_COMPLETE_event_is_returned_it_should_co using (var client = await InboundSocket.Connect("127.0.0.1", listener.Port, "ClueCon")) { var result = await client.Play("4e1cfa50-4c2f-44c9-aaf3-8ca590bed0e4", "test.wav"); - Assert.True(result.Success); - Assert.Equal("FILE PLAYED", result.ResponseText); + Assert.That(result.Success, Is.True); + Assert.That(result.ResponseText, Is.EqualTo("FILE PLAYED")); } } } diff --git a/NEventSocket.Tests/Sockets/MessageParsingTests.cs b/NEventSocket.Tests/Sockets/MessageParsingTests.cs index 13cd8ed..a112bec 100644 --- a/NEventSocket.Tests/Sockets/MessageParsingTests.cs +++ b/NEventSocket.Tests/Sockets/MessageParsingTests.cs @@ -6,13 +6,15 @@ using NEventSocket.Tests.Properties; using NEventSocket.Tests.TestSupport; using NEventSocket.Util; -using Xunit; +using NUnit.Framework; namespace NEventSocket.Tests.Sockets { + [TestFixture] public class MessageParsingTests { - [Theory, MemberData(nameof(ExampleMessages))] + [Test] + [TestCaseSource(nameof(ExampleMessages))] public void it_should_parse_the_expected_messages_from_a_stream(int expectedMessageCount, string exampleInput) { int parsedMessageCount = 0; @@ -22,15 +24,15 @@ public void it_should_parse_the_expected_messages_from_a_stream(int expectedMess .Select(parser => parser.ExtractMessage()) .Subscribe(_ => parsedMessageCount++); - Assert.Equal(expectedMessageCount, parsedMessageCount); + Assert.That(parsedMessageCount, Is.EqualTo(expectedMessageCount)); } - [Theory] - [InlineData(TestMessages.BackgroundJob)] - [InlineData(TestMessages.CallState)] - [InlineData(TestMessages.ConnectEvent)] - [InlineData(TestMessages.DisconnectEvent)] - [InlineData(TestMessages.PlaybackComplete)] + [Test] + [TestCase(TestMessages.BackgroundJob)] + [TestCase(TestMessages.CallState)] + [TestCase(TestMessages.ConnectEvent)] + [TestCase(TestMessages.DisconnectEvent)] + [TestCase(TestMessages.PlaybackComplete)] public void can_parse_test_messages(string input) { var parser = new Parser(); @@ -41,16 +43,16 @@ public void can_parse_test_messages(string input) parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var message = parser.ExtractMessage(); - Assert.NotNull(message); + Assert.That(message, Is.Not.Null); Console.WriteLine(message.ToString()); } - [Theory] - [InlineData(TestMessages.BackgroundJob)] - [InlineData(TestMessages.CallState)] + [Test] + [TestCase(TestMessages.BackgroundJob)] + [TestCase(TestMessages.CallState)] public void it_should_extract_the_body_from_a_message(string input) { var parser = new Parser(); @@ -60,19 +62,19 @@ public void it_should_extract_the_body_from_a_message(string input) parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); BasicMessage payload = parser.ExtractMessage(); - Assert.Equal(ContentTypes.EventPlain, payload.ContentType); - Assert.NotNull(payload.BodyText); - Assert.Equal(payload.ContentLength, payload.BodyText.Length); + Assert.That(payload.ContentType, Is.EqualTo(ContentTypes.EventPlain)); + Assert.That(payload.BodyText, Is.Not.Null); + Assert.That(payload.BodyText.Length, Is.EqualTo(payload.ContentLength)); Console.WriteLine(payload.ToString()); } - [Theory] - [InlineData(TestMessages.BackgroundJob, EventName.BackgroundJob)] - [InlineData(TestMessages.CallState, EventName.ChannelCallstate)] + [Test] + [TestCase(TestMessages.BackgroundJob, EventName.BackgroundJob)] + [TestCase(TestMessages.CallState, EventName.ChannelCallstate)] public void it_should_parse_event_messages(string input, EventName eventName) { var parser = new Parser(); @@ -82,16 +84,16 @@ public void it_should_parse_event_messages(string input, EventName eventName) parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var eventMessage = new EventMessage(parser.ExtractMessage()); - Assert.NotNull(eventMessage); - Assert.Equal(eventName, eventMessage.EventName); + Assert.That(eventMessage, Is.Not.Null); + Assert.That(eventMessage.EventName, Is.EqualTo(eventName)); Console.WriteLine(eventMessage.ToString()); } - [Fact] + [Test] public void it_should_parse_BackgroundJobResult_OK() { var input = TestMessages.BackgroundJob; @@ -103,16 +105,16 @@ public void it_should_parse_BackgroundJobResult_OK() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var backroundJobResult = new BackgroundJobResult(new EventMessage(parser.ExtractMessage())); - Assert.NotNull(backroundJobResult); - Assert.True(backroundJobResult.Success); + Assert.That(backroundJobResult, Is.Not.Null); + Assert.That(backroundJobResult.Success, Is.True); Console.WriteLine(backroundJobResult.ToString()); } - [Fact] + [Test] public void it_should_parse_BackgroundJobResult_ERR() { var input = TestMessages.BackgroundJobError; @@ -124,17 +126,17 @@ public void it_should_parse_BackgroundJobResult_ERR() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var backroundJobResult = new BackgroundJobResult(new EventMessage(parser.ExtractMessage())); - Assert.NotNull(backroundJobResult); - Assert.False(backroundJobResult.Success); - Assert.Equal("Error", backroundJobResult.ErrorMessage); + Assert.That(backroundJobResult, Is.Not.Null); + Assert.That(backroundJobResult.Success, Is.False); + Assert.That(backroundJobResult.ErrorMessage, Is.EqualTo("Error")); Console.WriteLine(backroundJobResult.ToString()); } - [Fact] + [Test] public void it_should_parse_Command_Reply_OK() { var parser = new Parser(); @@ -145,16 +147,16 @@ public void it_should_parse_Command_Reply_OK() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var reply = new CommandReply(parser.ExtractMessage()); - Assert.NotNull(reply); - Assert.True(reply.Success); + Assert.That(reply, Is.Not.Null); + Assert.That(reply.Success, Is.True); Console.WriteLine(reply); } - [Fact] + [Test] public void it_should_parse_Command_Reply_ERR() { var parser = new Parser(); @@ -165,17 +167,17 @@ public void it_should_parse_Command_Reply_ERR() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var reply = new CommandReply(parser.ExtractMessage()); - Assert.NotNull(reply); - Assert.False(reply.Success); - Assert.Equal("Error", reply.ErrorMessage); + Assert.That(reply, Is.Not.Null); + Assert.That(reply.Success, Is.False); + Assert.That(reply.ErrorMessage, Is.EqualTo("Error")); Console.WriteLine(reply); } - [Fact] + [Test] public void it_should_parse_Api_Response_OK() { var parser = new Parser(); @@ -186,16 +188,16 @@ public void it_should_parse_Api_Response_OK() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var response = new ApiResponse(parser.ExtractMessage()); - Assert.NotNull(response); - Assert.True(response.Success); + Assert.That(response, Is.Not.Null); + Assert.That(response.Success, Is.True); Console.WriteLine(response); } - [Fact] + [Test] public void it_should_parse_Api_Response_ERR() { var parser = new Parser(); @@ -206,17 +208,17 @@ public void it_should_parse_Api_Response_ERR() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var response = new ApiResponse(parser.ExtractMessage()); - Assert.NotNull(response); - Assert.False(response.Success); - Assert.Equal("Error", response.ErrorMessage); + Assert.That(response, Is.Not.Null); + Assert.That(response.Success, Is.False); + Assert.That(response.ErrorMessage, Is.EqualTo("Error")); Console.WriteLine(response); } - [Fact] + [Test] public void it_should_treat_Api_Response_ERR_no_reply_as_Success() { var parser = new Parser(); @@ -227,17 +229,17 @@ public void it_should_treat_Api_Response_ERR_no_reply_as_Success() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var response = new ApiResponse(parser.ExtractMessage()); - Assert.NotNull(response); - Assert.True(response.Success); - Assert.Equal("no reply", response.ErrorMessage); + Assert.That(response, Is.Not.Null); + Assert.That(response.Success, Is.True); + Assert.That(response.ErrorMessage, Is.EqualTo("no reply")); Console.WriteLine(response); } - [Fact] + [Test] public void it_should_trim_new_lines_from__the_end_of_ApiResponse_Body_text() { var parser = new Parser(); @@ -248,19 +250,19 @@ public void it_should_trim_new_lines_from__the_end_of_ApiResponse_Body_text() parser.Append(c); } - Assert.True(parser.Completed); + Assert.That(parser.Completed, Is.True); var response = new ApiResponse(parser.ExtractMessage()); - Assert.NotNull(response); - Assert.True(response.Success); - Assert.Equal("no reply", response.ErrorMessage); - Assert.Equal("-ERR no reply", response.BodyText); + Assert.That(response, Is.Not.Null); + Assert.That(response.Success, Is.True); + Assert.That(response.ErrorMessage, Is.EqualTo("no reply")); + Assert.That(response.BodyText, Is.EqualTo("-ERR no reply")); Console.WriteLine(response); } - [Theory] - [MemberData(nameof(ExampleSessions))] + [Test] + [TestCaseSource(nameof(ExampleSessions))] public void Can_parse_example_sessions_to_completion(string input) { if (Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER") == null) @@ -283,10 +285,10 @@ public void Can_parse_example_sessions_to_completion(string input) } }); - Assert.True(gotDisconnectNotice); + Assert.That(gotDisconnectNotice, Is.True); } - [Fact] + [Test] public void Can_parse_disconnect_notice() { var msg = @"Content-Type: text/disconnect-notice diff --git a/NEventSocket.Tests/Sockets/OutboundListenerTests.cs b/NEventSocket.Tests/Sockets/OutboundListenerTests.cs index 28df83e..a974b64 100644 --- a/NEventSocket.Tests/Sockets/OutboundListenerTests.cs +++ b/NEventSocket.Tests/Sockets/OutboundListenerTests.cs @@ -6,16 +6,18 @@ using Microsoft.Extensions.Logging; + using NUnit.Framework; + using NEventSocket; using NEventSocket.Logging; using NEventSocket.Tests.Fakes; using NEventSocket.Tests.TestSupport; - using Xunit; - + [TestFixture] public class OutboundListenerTests { - public OutboundListenerTests() + [SetUp] + public void SetUp() { PreventThreadPoolStarvation.Init(); Logger.Configure(LoggerFactory.Create(builder => @@ -28,7 +30,7 @@ public OutboundListenerTests() })); } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public void Disposing_the_listener_completes_the_connections_observable() { using (var listener = new OutboundListener(0)) @@ -41,11 +43,11 @@ public void Disposing_the_listener_completes_the_connections_observable() listener.Dispose(); - Assert.True(completed); + Assert.That(completed, Is.True); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task Disposing_the_listener_disposes_any_connected_clients() { using (var listener = new OutboundListener(0)) @@ -66,11 +68,11 @@ public async Task Disposing_the_listener_disposes_any_connected_clients() await Wait.Until(() => connected); listener.Dispose(); - Assert.True(disposed); + Assert.That(disposed, Is.True); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task Stopping_the_listener_does_not_dispose_any_connected_clients() { using (var listener = new OutboundListener(0)) @@ -92,14 +94,14 @@ public async Task Stopping_the_listener_does_not_dispose_any_connected_clients() listener.Stop(); - Assert.False(disposed); + Assert.That(disposed, Is.False); listener.Dispose(); - Assert.True(disposed); + Assert.That(disposed, Is.True); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task Can_restart_the_listener_after_stopping() { using (var listener = new OutboundListener(0)) @@ -117,7 +119,7 @@ public async Task Can_restart_the_listener_after_stopping() listener.Stop(); //not listening - Assert.ThrowsAny(() => new FakeFreeSwitchSocket(listener.Port)); + Assert.Throws(() => new FakeFreeSwitchSocket(listener.Port)); listener.Start(); new FakeFreeSwitchSocket(listener.Port); @@ -125,7 +127,7 @@ public async Task Can_restart_the_listener_after_stopping() } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task a_new_connection_produces_an_outbound_socket() { using (var listener = new OutboundListener(0)) @@ -139,11 +141,11 @@ public async Task a_new_connection_produces_an_outbound_socket() var client = new FakeFreeSwitchSocket(listener.Port); await Wait.Until(() => connected); - Assert.True(connected); + Assert.That(connected, Is.True); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task each_new_connection_produces_a_new_outbound_socket_from_the_Connections_observable() { const int NumberOfConnections = 3; @@ -162,11 +164,11 @@ public async Task each_new_connection_produces_a_new_outbound_socket_from_the_Co } await Wait.Until(() => connected == NumberOfConnections); - Assert.Equal(NumberOfConnections, connected); + Assert.That(connected, Is.EqualTo(NumberOfConnections)); } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task ProblematicSocket_connect_errors_should_not_cause_subsequent_connections_to_fail() { var connectionsHandled = 0; @@ -182,56 +184,56 @@ public async Task ProblematicSocket_connect_errors_should_not_cause_subsequent_c using (var client = new FakeFreeSwitchSocket(listener.Port)) { await Wait.Until(() => ProblematicListener.Counter == 1); - Assert.Equal(0, connectionsHandled); - Assert.Equal(1, ProblematicListener.Counter); - Assert.False(observableCompleted); + Assert.That(connectionsHandled, Is.EqualTo(0)); + Assert.That(ProblematicListener.Counter, Is.EqualTo(1)); + Assert.That(observableCompleted, Is.False); } using (var client = new FakeFreeSwitchSocket(listener.Port)) { await Wait.Until(() => connectionsHandled == 1); - Assert.Equal(1, connectionsHandled); - Assert.Equal(2, ProblematicListener.Counter); - Assert.False(observableCompleted); + Assert.That(connectionsHandled, Is.EqualTo(1)); + Assert.That(ProblematicListener.Counter, Is.EqualTo(2)); + Assert.That(observableCompleted, Is.False); } } - Assert.True(observableCompleted); + Assert.That(observableCompleted, Is.True); } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public void IsStarted_is_false_when_initialized() { using (var listener = new OutboundListener(0)) { - Assert.False(listener.IsStarted); + Assert.That(listener.IsStarted, Is.False); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public void IsStarted_is_true_when_started() { using (var listener = new OutboundListener(0)) { listener.Start(); - Assert.True(listener.IsStarted); + Assert.That(listener.IsStarted, Is.True); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public void IsStarted_is_false_when_stopped() { using (var listener = new OutboundListener(0)) { listener.Start(); - Assert.True(listener.IsStarted); + Assert.That(listener.IsStarted, Is.True); listener.Stop(); - Assert.False(listener.IsStarted); + Assert.That(listener.IsStarted, Is.False); } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public async Task IsStarted_is_false_when_disposed() { using (var listener = new OutboundListener(0)) @@ -243,14 +245,14 @@ public async Task IsStarted_is_false_when_disposed() } } - [Fact(Timeout = 2000)] + [Test, CancelAfter(2000)] public void Starting_should_be_idempotent() { using (var listener = new OutboundListener(0)) { listener.Start(); listener.Start(); - Assert.True(listener.IsStarted); + Assert.That(listener.IsStarted, Is.True); } } } diff --git a/NEventSocket.Tests/Sockets/OutboundSocketTests.cs b/NEventSocket.Tests/Sockets/OutboundSocketTests.cs index 9c519e3..27117c2 100644 --- a/NEventSocket.Tests/Sockets/OutboundSocketTests.cs +++ b/NEventSocket.Tests/Sockets/OutboundSocketTests.cs @@ -1,5 +1,4 @@ - -namespace NEventSocket.Tests.Sockets +namespace NEventSocket.Tests.Sockets { using System; using System.Reactive.Linq; @@ -7,17 +6,19 @@ namespace NEventSocket.Tests.Sockets using Microsoft.Extensions.Logging; + using NUnit.Framework; + using NEventSocket; using NEventSocket.FreeSwitch; using NEventSocket.Logging; using NEventSocket.Tests.Fakes; using NEventSocket.Tests.TestSupport; - using Xunit; - + [TestFixture] public class OutboundSocketTests { - public OutboundSocketTests() + [SetUp] + public void SetUp() { PreventThreadPoolStarvation.Init(); Logger.Configure(LoggerFactory.Create(builder => @@ -31,7 +32,7 @@ public OutboundSocketTests() } - [Fact(Timeout = TimeOut.TestTimeOutMs, Skip = "Removing timeouts")] + [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Removing timeouts")] public async Task Disposing_the_listener_completes_the_message_observables() { using (var listener = new OutboundListener(0)) @@ -51,7 +52,7 @@ public async Task Disposing_the_listener_completes_the_message_observables() await connection.Connect(); channelDataReceived = connection.ChannelData != null; - Assert.True(channelDataReceived); + Assert.That(channelDataReceived, Is.True); }); using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port)) @@ -65,14 +66,14 @@ public async Task Disposing_the_listener_completes_the_message_observables() await Wait.Until(() => messagesObservableCompleted); await Wait.Until(() => eventsObservableCompleted); - Assert.True(connected, "Expect a connection to have been made."); - Assert.True(messagesObservableCompleted, "Expect the BasicMessage observable to be completed"); - Assert.True(eventsObservableCompleted, "Expect the EventMessage observable to be completed"); + Assert.That(connected, Is.True, "Expect a connection to have been made."); + Assert.That(messagesObservableCompleted, Is.True, "Expect the BasicMessage observable to be completed"); + Assert.That(eventsObservableCompleted, Is.True, "Expect the EventMessage observable to be completed"); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task When_FreeSwitch_disconnects_it_completes_the_message_observables() { using (var listener = new OutboundListener(0)) @@ -100,15 +101,15 @@ public async Task When_FreeSwitch_disconnects_it_completes_the_message_observabl await Wait.Until(() => messagesObservableCompleted); await Wait.Until(() => eventsObservableCompleted); - Assert.True(connected, "Expect a connection to have been made."); - Assert.True(disposed, "Expect the socket to have been disposed."); - Assert.True(messagesObservableCompleted, "Expect the BasicMessage observable to be completed"); - Assert.True(eventsObservableCompleted, "Expect the EventMessage observable to be completed"); + Assert.That(connected, Is.True, "Expect a connection to have been made."); + Assert.That(disposed, Is.True, "Expect the socket to have been disposed."); + Assert.That(messagesObservableCompleted, Is.True, "Expect the BasicMessage observable to be completed"); + Assert.That(eventsObservableCompleted, Is.True, "Expect the EventMessage observable to be completed"); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task Calling_Connect_on_a_new_OutboundSocket_should_populate_the_ChannelData() { using (var listener = new OutboundListener(0)) @@ -129,14 +130,14 @@ public async Task Calling_Connect_on_a_new_OutboundSocket_should_populate_the_Ch await Wait.Until(() => channelData != null); - Assert.NotNull(channelData); - Assert.Equal(ChannelState.Execute, channelData.ChannelState); - Assert.Equal("RINGING", channelData.Headers["Channel-Call-State"]); + Assert.That(channelData, Is.Not.Null); + Assert.That(channelData.ChannelState, Is.EqualTo(ChannelState.Execute)); + Assert.That(channelData.Headers["Channel-Call-State"], Is.EqualTo("RINGING")); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task Calling_Exit_on_a_disconnected_OutboundSocket_should_close_gracefully() { using (var listener = new OutboundListener(0)) @@ -166,12 +167,12 @@ public async Task Calling_Exit_on_a_disconnected_OutboundSocket_should_close_gra await Wait.Until(() => channelData != null); await Wait.Until(() => exited); - Assert.True(exited); + Assert.That(exited, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs, Skip = "Low priority right now")] + [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("Low priority right now")] public async Task Calling_Connect_on_a_OutboundSocket_that_was_disconnected_should_throw_OperationCanceledException() { using (var listener = new OutboundListener(0)) @@ -179,19 +180,19 @@ public async Task Calling_Connect_on_a_OutboundSocket_that_was_disconnected_shou listener.Start(); Exception ex = null; - listener.Connections.Subscribe((socket) => ex = Record.Exception(() => socket.Connect().Wait())); + listener.Connections.Subscribe((socket) => ex = Assert.Throws(() => socket.Connect().Wait())); using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port)) { freeSwitch.MessagesReceived.FirstAsync(m => m.StartsWith("connect")).Subscribe(_ => freeSwitch.Dispose()); await Wait.Until(() => ex != null); - Assert.IsType(ex.InnerException); + Assert.That(ex.InnerException, Is.TypeOf()); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task Channel_listener_should_handle_where_FS_disconnects_before_channelData_event_received() { using (var listener = new OutboundListener(0)) @@ -211,12 +212,12 @@ public async Task Channel_listener_should_handle_where_FS_disconnects_before_cha }); await Wait.Until(() => firstConnectionReceived); - Assert.False(channelCallbackCalled); + Assert.That(channelCallbackCalled, Is.False); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs, Skip = "not working in some test runners")] + [Test, CancelAfter(TimeOut.TestTimeOutMs), Ignore("not working in some test runners")] public async Task Channel_connect_errors_should_not_cause_subsequent_connections_to_fail() { using (var listener = new OutboundListener(0)) @@ -237,7 +238,7 @@ public async Task Channel_connect_errors_should_not_cause_subsequent_connections }); await Wait.Until(() => firstConnectionReceived); - Assert.False(channelCallbackCalled); + Assert.That(channelCallbackCalled, Is.False); } using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port)) @@ -256,12 +257,12 @@ public async Task Channel_connect_errors_should_not_cause_subsequent_connections await Wait.Until(() => secondConnectionReceived); - Assert.True(channelCallbackCalled); + Assert.That(channelCallbackCalled, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_api() { using (var listener = new OutboundListener(0)) @@ -294,14 +295,14 @@ public async Task can_send_api() await Wait.Until(() => apiRequestReceived); await Wait.Until(() => apiResponse != null); - Assert.True(apiRequestReceived); - Assert.NotNull(apiResponse); - Assert.True(apiResponse.Success); + Assert.That(apiRequestReceived, Is.True); + Assert.That(apiResponse, Is.Not.Null); + Assert.That(apiResponse.Success, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_command() { using (var listener = new OutboundListener(0)) @@ -333,14 +334,14 @@ public async Task can_send_command() await Wait.Until(() => commandRequestReceived); - Assert.True(commandRequestReceived); - Assert.NotNull(commandReply); - Assert.True(commandReply.Success); + Assert.That(commandRequestReceived, Is.True); + Assert.That(commandReply, Is.Not.Null); + Assert.That(commandReply.Success, Is.True); } } } - [Fact(Timeout = TimeOut.TestTimeOutMs)] + [Test, CancelAfter(TimeOut.TestTimeOutMs)] public async Task can_send_multple_commands() { using (var listener = new OutboundListener(0)) @@ -380,9 +381,9 @@ public async Task can_send_multple_commands() await Wait.Until(() => commandRequestReceived); - Assert.True(commandRequestReceived); - Assert.NotNull(commandReply); - Assert.False(commandReply.Success); + Assert.That(commandRequestReceived, Is.True); + Assert.That(commandReply, Is.Not.Null); + Assert.That(commandReply.Success, Is.False); } } } diff --git a/NEventSocket.Tests/TestSupport/TestEnvironmentSupport.cs b/NEventSocket.Tests/TestSupport/TestEnvironmentSupport.cs index 70c2f37..71085a3 100644 --- a/NEventSocket.Tests/TestSupport/TestEnvironmentSupport.cs +++ b/NEventSocket.Tests/TestSupport/TestEnvironmentSupport.cs @@ -1,8 +1,9 @@ using System; -using Xunit; +using NUnit.Framework; namespace NEventSocket.Tests.TestSupport { + [TestFixture] public class TestEnvironmentSupport { static TestEnvironmentSupport() @@ -14,7 +15,7 @@ static TestEnvironmentSupport() } } - [Fact] + [Test] public void EmptyTest() { } diff --git a/NEventSocket.Tests/Util/StringExtensionsTests.cs b/NEventSocket.Tests/Util/StringExtensionsTests.cs index 3f8649b..9088672 100644 --- a/NEventSocket.Tests/Util/StringExtensionsTests.cs +++ b/NEventSocket.Tests/Util/StringExtensionsTests.cs @@ -1,98 +1,97 @@ using System; using FluentAssertions; using NEventSocket; -using Xunit; +using NUnit.Framework; using NEventSocket.FreeSwitch; using NEventSocket.Util; namespace NEventSocket.Tests.Util { - - + [TestFixture] public class StringExtensionsTests { - [Fact] + [Test] public void can_format_strings() { const string Format = "{0} {1} {2}"; var output = Format.Fmt(1, 2, 3); - Assert.Equal("1 2 3", output); + Assert.That(output, Is.EqualTo("1 2 3")); } - [Fact] + [Test] public void can_convert_camelcase_to_uppercaseunderscore() { const string Input = "ThisIsAStringInCamelCase"; - Assert.Equal("THIS_IS_A_STRING_IN_CAMEL_CASE", Input.ToUpperWithUnderscores()); + Assert.That(Input.ToUpperWithUnderscores(), Is.EqualTo("THIS_IS_A_STRING_IN_CAMEL_CASE")); } - [Fact] + [Test] public void can_convert_uppercaseunderscore_to_camelcase() { const string Input = "THIS_IS_A_STRING_IN_UPPER_CASE"; - Assert.Equal("ThisIsAStringInUpperCase", Input.ToPascalCase()); + Assert.That(Input.ToPascalCase(), Is.EqualTo("ThisIsAStringInUpperCase")); } - [Fact] + [Test] public void can_convert_uppercaseunderscore_to_enum() { const string Input = "UNALLOCATED_NUMBER"; var output = Input.HeaderToEnum(); - Assert.Equal(HangupCause.UnallocatedNumber, output); + Assert.That(output, Is.EqualTo(HangupCause.UnallocatedNumber)); } - [Fact] + [Test] public void if_unable_to_convert_string_to_nullable_enum_it_should_return_null() { const string Input = "THIS_IS_AN_INVALID_HANGUPCAUSE"; var output = Input.HeaderToEnumOrNull(); - Assert.Null(output); + Assert.That(output, Is.Null); } - [Fact] + [Test] public void if_unable_to_convert_string_to_enum_it_should_throw_an_ArgumentException() { const string Input = "THIS_IS_AN_INVALID_HANGUPCAUSE"; Assert.Throws(() => Input.HeaderToEnum()); } - [Theory] - [InlineData(0, "digits/0.wav")] - [InlineData(1, "digits/1.wav")] - [InlineData(2, "digits/2.wav")] - [InlineData(10, "digits/10.wav")] - [InlineData(11, "digits/11.wav")] - [InlineData(12, "digits/12.wav")] - [InlineData(20, "digits/20.wav")] - [InlineData(23, "digits/20.wav!digits/3.wav")] - [InlineData(36, "digits/30.wav!digits/6.wav")] - [InlineData(100, "digits/1.wav!digits/hundred.wav")] - [InlineData(110, "digits/1.wav!digits/hundred.wav!digits/10.wav")] - [InlineData(116, "digits/1.wav!digits/hundred.wav!digits/16.wav")] - [InlineData(123, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav")] - [InlineData(199, "digits/1.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] - [InlineData(1000, "digits/1.wav!digits/thousand.wav")] - [InlineData(1005, "digits/1.wav!digits/thousand.wav!digits/5.wav")] - [InlineData(1010, "digits/1.wav!digits/thousand.wav!digits/10.wav")] - [InlineData(1016, "digits/1.wav!digits/thousand.wav!digits/16.wav")] - [InlineData(1023, "digits/1.wav!digits/thousand.wav!digits/20.wav!digits/3.wav")] - [InlineData(1099, "digits/1.wav!digits/thousand.wav!digits/90.wav!digits/9.wav")] - [InlineData(1200, "digits/1.wav!digits/thousand.wav!digits/2.wav!digits/hundred.wav")] - [InlineData(1305, "digits/1.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/5.wav")] - [InlineData(1310, "digits/1.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/10.wav")] - [InlineData(2316, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/16.wav")] - [InlineData(2323, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/20.wav!digits/3.wav")] - [InlineData(2399, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] - [InlineData(20009, "digits/20.wav!digits/thousand.wav!digits/9.wav")] - [InlineData(21239, "digits/20.wav!digits/1.wav!digits/thousand.wav!digits/2.wav!digits/hundred.wav!digits/30.wav!digits/9.wav")] - [InlineData(123456, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/thousand.wav!digits/4.wav!digits/hundred.wav!digits/50.wav!digits/6.wav")] - [InlineData(999999, "digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav!digits/thousand.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] - [InlineData(2123456, "digits/2.wav!digits/million.wav!digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/thousand.wav!digits/4.wav!digits/hundred.wav!digits/50.wav!digits/6.wav")] - [InlineData(9999999, "digits/9.wav!digits/million.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav!digits/thousand.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] - [InlineData(1000023, "digits/1.wav!digits/million.wav!digits/20.wav!digits/3.wav")] - [InlineData(123000000, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/million.wav")] + [Test] + [TestCase(0, "digits/0.wav")] + [TestCase(1, "digits/1.wav")] + [TestCase(2, "digits/2.wav")] + [TestCase(10, "digits/10.wav")] + [TestCase(11, "digits/11.wav")] + [TestCase(12, "digits/12.wav")] + [TestCase(20, "digits/20.wav")] + [TestCase(23, "digits/20.wav!digits/3.wav")] + [TestCase(36, "digits/30.wav!digits/6.wav")] + [TestCase(100, "digits/1.wav!digits/hundred.wav")] + [TestCase(110, "digits/1.wav!digits/hundred.wav!digits/10.wav")] + [TestCase(116, "digits/1.wav!digits/hundred.wav!digits/16.wav")] + [TestCase(123, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav")] + [TestCase(199, "digits/1.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] + [TestCase(1000, "digits/1.wav!digits/thousand.wav")] + [TestCase(1005, "digits/1.wav!digits/thousand.wav!digits/5.wav")] + [TestCase(1010, "digits/1.wav!digits/thousand.wav!digits/10.wav")] + [TestCase(1016, "digits/1.wav!digits/thousand.wav!digits/16.wav")] + [TestCase(1023, "digits/1.wav!digits/thousand.wav!digits/20.wav!digits/3.wav")] + [TestCase(1099, "digits/1.wav!digits/thousand.wav!digits/90.wav!digits/9.wav")] + [TestCase(1200, "digits/1.wav!digits/thousand.wav!digits/2.wav!digits/hundred.wav")] + [TestCase(1305, "digits/1.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/5.wav")] + [TestCase(1310, "digits/1.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/10.wav")] + [TestCase(2316, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/16.wav")] + [TestCase(2323, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/20.wav!digits/3.wav")] + [TestCase(2399, "digits/2.wav!digits/thousand.wav!digits/3.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] + [TestCase(20009, "digits/20.wav!digits/thousand.wav!digits/9.wav")] + [TestCase(21239, "digits/20.wav!digits/1.wav!digits/thousand.wav!digits/2.wav!digits/hundred.wav!digits/30.wav!digits/9.wav")] + [TestCase(123456, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/thousand.wav!digits/4.wav!digits/hundred.wav!digits/50.wav!digits/6.wav")] + [TestCase(999999, "digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav!digits/thousand.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] + [TestCase(2123456, "digits/2.wav!digits/million.wav!digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/thousand.wav!digits/4.wav!digits/hundred.wav!digits/50.wav!digits/6.wav")] + [TestCase(9999999, "digits/9.wav!digits/million.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav!digits/thousand.wav!digits/9.wav!digits/hundred.wav!digits/90.wav!digits/9.wav")] + [TestCase(1000023, "digits/1.wav!digits/million.wav!digits/20.wav!digits/3.wav")] + [TestCase(123000000, "digits/1.wav!digits/hundred.wav!digits/20.wav!digits/3.wav!digits/million.wav")] public void can_convert_digits_to_file_strings(int input, string expectedOutput) { var output = Digits.ToFileString(input); diff --git a/NEventSocket.sln.DotSettings b/NEventSocket.sln.DotSettings index 8db27b2..dd5bffa 100644 --- a/NEventSocket.sln.DotSettings +++ b/NEventSocket.sln.DotSettings @@ -267,6 +267,7 @@ True True True + True True True True diff --git a/NEventSocket/FreeSwitch/BridgeOptions.cs b/NEventSocket/FreeSwitch/BridgeOptions.cs index 374777c..490c432 100644 --- a/NEventSocket/FreeSwitch/BridgeOptions.cs +++ b/NEventSocket/FreeSwitch/BridgeOptions.cs @@ -333,7 +333,7 @@ public OriginationPrivacy OriginationPrivacy /// /// Container for any Channel Variables to be set on the A-Leg before executing the bridge /// - public IDictionary ChannelVariables { get; private set; } + public IDictionary ChannelVariables { get; set; } /// /// Implements the operator ==. diff --git a/NEventSocket/InboundSocketConnectionFailedException.cs b/NEventSocket/InboundSocketConnectionFailedException.cs index f2d1159..a0a274c 100644 --- a/NEventSocket/InboundSocketConnectionFailedException.cs +++ b/NEventSocket/InboundSocketConnectionFailedException.cs @@ -33,14 +33,5 @@ public InboundSocketConnectionFailedException(string message) : base(message) public InboundSocketConnectionFailedException(string message, Exception innerException) : base(message, innerException) { } - - /// - /// Initializes a new instance of the class. - /// - /// The information. - /// The context. - protected InboundSocketConnectionFailedException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } } } diff --git a/NEventSocket/NEventSocket.csproj b/NEventSocket/NEventSocket.csproj index 9db4ff8..4f1e32d 100644 --- a/NEventSocket/NEventSocket.csproj +++ b/NEventSocket/NEventSocket.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net9.0 NEventSocket.DotNetCore iamkinetic iamkinetic @@ -12,19 +12,13 @@ FreeSwitch NEventSocket DotNetCore - Fix a few issues with the ObservableSocket. https://github.com/iamkinetic/NEventSocket - - - - - - 2.2.1.0 2.2.1.0 - - + +