Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjorgo committed Dec 11, 2024
1 parent a480546 commit 296d57a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 14 deletions.
34 changes: 34 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/MessageStorageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using HeboTech.ATLib.Dtos;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class MessageStorageTests
{
[Theory]
[InlineData("SM")]
[InlineData("ME")]
[InlineData("MT")]
[InlineData("BM")]
[InlineData("SR")]
[InlineData("TA")]
public void TProperties_are_set(string storageName)
{
MessageStorage storage = MessageStorage.Parse(storageName);

Assert.Equal(storageName, storage.Value);
Assert.Equal(storageName, storage);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("A")]
[InlineData("AB")]
public void Throws_on_invalid_name(string storageName)
{
Assert.Throws<ArgumentException>(() => MessageStorage.Parse(storageName));
}
}
}
25 changes: 25 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/PreferredMessageStorageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using HeboTech.ATLib.Dtos;
using HeboTech.ATLib.DTOs;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class PreferredMessageStorageTests
{
[Theory]
[InlineData("SM", 5, 10)]
[InlineData("ME", 5, 10)]
[InlineData("MT", 5, 10)]
[InlineData("BM", 5, 10)]
[InlineData("SR", 5, 10)]
[InlineData("TA", 5, 10)]
public void Test(string expectedStorageName, int expectedStorageMessages, int expectedStorageMessageLocations)
{
PreferredMessageStorage sut = new(MessageStorage.Parse(expectedStorageName), expectedStorageMessages, expectedStorageMessageLocations);

Assert.Equal(expectedStorageName, sut.StorageName);
Assert.Equal(expectedStorageMessages, sut.StorageMessages);
Assert.Equal(expectedStorageMessageLocations, sut.StorageMessageLocations);
}
}
}
8 changes: 0 additions & 8 deletions src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ namespace HeboTech.ATLib.DTOs
{
public class PreferredMessageStorage
{
/// <summary>
/// SM: SIM card storage area
/// ME: Modem storage area
/// MT: All storage combined
/// BM: Broadcast message storage area
/// SR: Status report storage area
/// TA: Terminal adaptor storage area
/// </summary>
public PreferredMessageStorage(MessageStorage storageName, int storageMessages, int storageMessageLocations)
{
StorageName = storageName;
Expand Down
3 changes: 1 addition & 2 deletions src/HeboTech.ATLib/Dtos/MessageStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected MessageStorage(string value)

public string Value { get; }

protected static MessageStorage ParseString(string value)
public static MessageStorage Parse(string value)
{
if (value == SM.ToString())
return SM;
Expand All @@ -63,7 +63,6 @@ protected static MessageStorage ParseString(string value)
}

public static implicit operator string(MessageStorage value) => value.Value;
public static explicit operator MessageStorage(string value) => ParseString(value);

public override string ToString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static SmsStatusReportStorageReferenceEventArgs CreateFromResponse(string
{
string storage = match.Groups["storage"].Value;
int index = int.Parse(match.Groups["index"].Value);
return new SmsStatusReportStorageReferenceEventArgs((MessageStorage)storage, index);
return new SmsStatusReportStorageReferenceEventArgs(MessageStorage.Parse(storage), index);
}

return default;
Expand Down
6 changes: 3 additions & 3 deletions src/HeboTech.ATLib/Modems/Generic/ModemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ public virtual async Task<ModemResponse<PreferredMessageStorages>> GetPreferredM
string[] s3Split = match.Groups["storage3"].Value.Split(',');

return ModemResponse.IsResultSuccess(new PreferredMessageStorages(
new PreferredMessageStorage((MessageStorage)s1Split[0].Trim('"'), int.Parse(s1Split[1]), int.Parse(s1Split[2])),
new PreferredMessageStorage((MessageStorage)s2Split[0].Trim('"'), int.Parse(s2Split[1]), int.Parse(s2Split[2])),
new PreferredMessageStorage((MessageStorage)s3Split[0].Trim('"'), int.Parse(s3Split[1]), int.Parse(s3Split[2]))));
new PreferredMessageStorage(MessageStorage.Parse(s1Split[0].Trim('"')), int.Parse(s1Split[1]), int.Parse(s1Split[2])),
new PreferredMessageStorage(MessageStorage.Parse(s2Split[0].Trim('"')), int.Parse(s2Split[1]), int.Parse(s2Split[2])),
new PreferredMessageStorage(MessageStorage.Parse(s3Split[0].Trim('"')), int.Parse(s3Split[1]), int.Parse(s3Split[2]))));
}
}

Expand Down

0 comments on commit 296d57a

Please sign in to comment.