Skip to content

Commit

Permalink
Ussd multi line response (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjorgo authored Apr 17, 2022
1 parent 95da8d8 commit b88f66d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/HeboTech.ATLib.Tests/Events/UssdResponseEventArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HeboTech.ATLib.Events;
using Xunit;

namespace HeboTech.ATLib.Tests.Events
{
public class UssdResponseEventArgsTests
{
[Fact]
public void CreateFromResponse_accepts_singleline_response()
{
string response = "+CUSD: 1,\"Single line response\",15";

UssdResponseEventArgs dut = UssdResponseEventArgs.CreateFromResponse(response);

Assert.Equal(1, dut.Status);
Assert.Equal("Single line response", dut.Response);
Assert.Equal(15, dut.CodingScheme);
}

[Fact]
public void CreateFromResponse_accepts_multiline_response()
{
string response = "+CUSD: 1,\"Line1\r\nLine 2\r\nLine 3\r\nLine 4\r\nLine 5\r\nLine 6\r\nLine 7\",15";

UssdResponseEventArgs dut = UssdResponseEventArgs.CreateFromResponse(response);

Assert.Equal(1, dut.Status);
Assert.Equal("Line1\r\nLine 2\r\nLine 3\r\nLine 4\r\nLine 5\r\nLine 6\r\nLine 7", dut.Response);
Assert.Equal(15, dut.CodingScheme);
}
}
}
2 changes: 1 addition & 1 deletion src/HeboTech.ATLib/Events/UssdResponseEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public UssdResponseEventArgs(int status, string response, int codingScheme)

public static UssdResponseEventArgs CreateFromResponse(string response)
{
var match = Regex.Match(response, @"\+CUSD:\s(?<status>\d),""(?<message>.*)"",(?<codingScheme>\d+)");
var match = Regex.Match(response, @"\+CUSD:\s(?<status>\d),""(?<message>(?s).*)"",(?<codingScheme>\d+)");
if (match.Success)
{
int status = int.Parse(match.Groups["status"].Value);
Expand Down
6 changes: 3 additions & 3 deletions src/HeboTech.ATLib/HeboTech.ATLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>HeboTech</Authors>
<Product>HeboTech ATLib</Product>
<Version>4.0.0</Version>
<Version>4.1.0</Version>
<PackageId>HeboTech.ATLib</PackageId>
<PackageTags>atcommand at command gsm sms hayes simcom d-link tp-link dwm-222 ma260 sim5320</PackageTags>
<Description>AT command library that makes it easy to communicate with modems.</Description>
Expand All @@ -13,8 +13,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/hbjorgo/ATLib</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/hbjorgo/ATLib/releases</PackageReleaseNotes>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<FileVersion>4.0.0.0</FileVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<FileVersion>4.1.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit b88f66d

Please sign in to comment.