diff --git a/src/HeboTech.ATLib.Tests/DTOs/MessageStorageTests.cs b/src/HeboTech.ATLib.Tests/DTOs/MessageStorageTests.cs new file mode 100644 index 0000000..d62fcd3 --- /dev/null +++ b/src/HeboTech.ATLib.Tests/DTOs/MessageStorageTests.cs @@ -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(() => MessageStorage.Parse(storageName)); + } + } +} diff --git a/src/HeboTech.ATLib.Tests/DTOs/PreferredMessageStorageTests.cs b/src/HeboTech.ATLib.Tests/DTOs/PreferredMessageStorageTests.cs new file mode 100644 index 0000000..1e144c6 --- /dev/null +++ b/src/HeboTech.ATLib.Tests/DTOs/PreferredMessageStorageTests.cs @@ -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); + } + } +} diff --git a/src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs b/src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs index 3d9099d..a13dd70 100644 --- a/src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs +++ b/src/HeboTech.ATLib/DTOs/PreferredMessageStorage.cs @@ -4,14 +4,6 @@ namespace HeboTech.ATLib.DTOs { public class PreferredMessageStorage { - /// - /// 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 - /// public PreferredMessageStorage(MessageStorage storageName, int storageMessages, int storageMessageLocations) { StorageName = storageName; diff --git a/src/HeboTech.ATLib/Dtos/MessageStorage.cs b/src/HeboTech.ATLib/Dtos/MessageStorage.cs index 98f5327..85c5f11 100644 --- a/src/HeboTech.ATLib/Dtos/MessageStorage.cs +++ b/src/HeboTech.ATLib/Dtos/MessageStorage.cs @@ -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; @@ -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() { diff --git a/src/HeboTech.ATLib/Events/SmsStatusReportStorageReferenceEventArgs.cs b/src/HeboTech.ATLib/Events/SmsStatusReportStorageReferenceEventArgs.cs index b0de518..127195c 100644 --- a/src/HeboTech.ATLib/Events/SmsStatusReportStorageReferenceEventArgs.cs +++ b/src/HeboTech.ATLib/Events/SmsStatusReportStorageReferenceEventArgs.cs @@ -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; diff --git a/src/HeboTech.ATLib/Modems/Generic/ModemBase.cs b/src/HeboTech.ATLib/Modems/Generic/ModemBase.cs index ac8209b..e9ba584 100644 --- a/src/HeboTech.ATLib/Modems/Generic/ModemBase.cs +++ b/src/HeboTech.ATLib/Modems/Generic/ModemBase.cs @@ -338,9 +338,9 @@ public virtual async Task> 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])))); } }