Skip to content

Commit

Permalink
Merge pull request #51 from hbjorgo/feature/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjorgo authored Dec 11, 2024
2 parents ba81c04 + 296d57a commit 83a3c98
Show file tree
Hide file tree
Showing 54 changed files with 577 additions and 175 deletions.
8 changes: 4 additions & 4 deletions src/HeboTech.ATLib.TestConsole/FunctionalityTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.Dtos;
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.Events;
using HeboTech.ATLib.Modems.Cinterion;
using HeboTech.ATLib.Modems.D_LINK;
using HeboTech.ATLib.Modems.Generic;
using HeboTech.ATLib.Parsers;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -37,8 +37,8 @@ public static async Task RunAsync(System.IO.Stream stream, string pin)
{
using AtChannel atChannel = AtChannel.Create(stream);
atChannel.EnableDebug(Log);
using IMC55i modem = new MC55i(atChannel);
//using IDWM222 modem = new DWM222(atChannel);
//using IMC55i modem = new MC55i(atChannel);
using IDWM222 modem = new DWM222(atChannel);
atChannel.Open();
await atChannel.ClearAsync();

Expand Down
39 changes: 39 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/CharacterSetHelpersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using HeboTech.ATLib.CodingSchemes;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class CharacterSetHelpersTests
{
[Theory]
[InlineData("GSM", CharacterSet.Gsm7)]
[InlineData("UCS2", CharacterSet.UCS2)]
public void FromString_returns_correct_string(string value, CharacterSet expectedCharacterSet)
{
Assert.Equal(expectedCharacterSet, CharacterSetHelpers.FromString(value));
}

[Theory]
[InlineData("InvalidCharacterSet")]
public void FromString_throws_on_unknown_characterset(string value)
{
Assert.Throws<ArgumentException>(() => CharacterSetHelpers.FromString(value));
}

[Theory]
[InlineData(CharacterSet.Gsm7, "GSM")]
[InlineData(CharacterSet.UCS2, "UCS2")]
public void ToString_returns_correct_string(CharacterSet characterSet, string expectedValue)
{
Assert.Equal(expectedValue, CharacterSetHelpers.ToString(characterSet));
}

[Theory]
[InlineData((CharacterSet)255)]
public void ToString_throws_on_unknown_characterset(CharacterSet characterSet)
{
Assert.Throws<ArgumentException>(() => CharacterSetHelpers.ToString(characterSet));
}
}
}
16 changes: 16 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/CharacterSetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HeboTech.ATLib.CodingSchemes;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class CharacterSetTests
{
[Theory]
[InlineData(CharacterSet.Gsm7, 0x00)]
[InlineData(CharacterSet.UCS2, 0x08)]
public void Has_correct_values(CharacterSet characterSet, int expectedValue)
{
Assert.Equal(expectedValue, (int)characterSet);
}
}
}
20 changes: 20 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/CodingGroupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HeboTech.ATLib.CodingSchemes;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class CodingGroupTests
{
[Theory]
[InlineData(CodingGroup.GeneralDataCoding, 0)]
[InlineData(CodingGroup.MessageMarkedForAutomaticDeletion, 1)]
[InlineData(CodingGroup.Reserved, 2)]
[InlineData(CodingGroup.MessageWaitingInfo_DiscardMessage, 3)]
[InlineData(CodingGroup.MessageWaitingInfo_StoreMessage, 4)]
[InlineData(CodingGroup.DataCoding_MessageClass, 5)]
internal void Has_correct_values(CodingGroup codingGroup, int expectedValue)
{
Assert.Equal(expectedValue, (int)codingGroup);
}
}
}
30 changes: 30 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/DataCodingSchemeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HeboTech.ATLib.CodingSchemes;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class DataCodingSchemeTests
{
[Theory]
[InlineData(0x00, CharacterSet.Gsm7, MessageClass.Default, CodingGroup.GeneralDataCoding)]
[InlineData(0x08, CharacterSet.UCS2, MessageClass.Default, CodingGroup.GeneralDataCoding)]
[InlineData(0x11, CharacterSet.Gsm7, MessageClass.Class1, CodingGroup.GeneralDataCoding)]
internal void ParseByte_returns_correct_DataCodingScheme(byte value, CharacterSet expectedCharacterSet, MessageClass expectedMessageClass, CodingGroup expectedCodingGroup)
{
var dcs = DataCodingScheme.ParseByte(value);

Assert.Equal(expectedCharacterSet, dcs.CharacterSet);
Assert.Equal(expectedMessageClass, dcs.MessageClass);
Assert.Equal(expectedCodingGroup, dcs.CodingGroup);
}

[Theory]
[InlineData(0x01)]
[InlineData(0xFF)]
internal void ParseByte_throws_on_unknown_value(byte value)
{
Assert.Throws<ArgumentException>(() => DataCodingScheme.ParseByte(value));
}
}
}
28 changes: 28 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/Gsm7ExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using HeboTech.ATLib.CodingSchemes;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class Gsm7ExtensionTests
{
[Theory]
[InlineData(Gsm7Extension.Default, 0x00)]
[InlineData(Gsm7Extension.Turkish, 0x01)]
[InlineData(Gsm7Extension.Spanish, 0x02)]
[InlineData(Gsm7Extension.Portugese, 0x03)]
[InlineData(Gsm7Extension.BengaliAndAssamese, 0x04)]
[InlineData(Gsm7Extension.Gujarati, 0x05)]
[InlineData(Gsm7Extension.Hindi, 0x06)]
[InlineData(Gsm7Extension.Kannada, 0x07)]
[InlineData(Gsm7Extension.Malayalam, 0x08)]
[InlineData(Gsm7Extension.Oriya, 0x09)]
[InlineData(Gsm7Extension.Punjabi, 0x0A)]
[InlineData(Gsm7Extension.Tamil, 0x0B)]
[InlineData(Gsm7Extension.Telugu, 0x0C)]
[InlineData(Gsm7Extension.Urdu, 0x0D)]
internal void Has_correct_values(Gsm7Extension gsm7Extension, int expectedValue)
{
Assert.Equal(expectedValue, (int)gsm7Extension);
}
}
}
4 changes: 2 additions & 2 deletions src/HeboTech.ATLib.Tests/CodingSchemes/Gsm7Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void EncodeToBytes_returns_encoded_bytes_with_default_extension_table(str
[InlineData("À", Gsm7Extension.Portugese, Gsm7Extension.Portugese, "14")]
[InlineData("Φ", Gsm7Extension.Portugese, Gsm7Extension.Portugese, "1B09")]
[InlineData("ΦΣ", Gsm7Extension.Portugese, Gsm7Extension.Portugese, "1BC90603")]
public void EncodeToBytes_returns_encoded_bytes_with_extension_table(string gsm7Bit, Gsm7Extension singleShift, Gsm7Extension lockingShift, string expected)
internal void EncodeToBytes_returns_encoded_bytes_with_extension_table(string gsm7Bit, Gsm7Extension singleShift, Gsm7Extension lockingShift, string expected)
{
byte[] result = Gsm7.Encode(gsm7Bit, 0, singleShift, lockingShift);

Expand All @@ -120,7 +120,7 @@ public void DecodeFromBytes_returns_decoded_text_with_default_extension_table(st
[InlineData("14", Gsm7Extension.Portugese, Gsm7Extension.Portugese, "À")]
[InlineData("1B", Gsm7Extension.Portugese, Gsm7Extension.Portugese, " ")]
[InlineData("1B09", Gsm7Extension.Portugese, Gsm7Extension.Portugese, "Φ")]
public void DecodeFromBytes_returns_decoded_text_with_extension_table(string gsm7Bit, Gsm7Extension singleShift, Gsm7Extension lockingShift, string expected)
internal void DecodeFromBytes_returns_decoded_text_with_extension_table(string gsm7Bit, Gsm7Extension singleShift, Gsm7Extension lockingShift, string expected)
{
string result = Gsm7.Decode(Convert.FromHexString(gsm7Bit), 0, singleShift, lockingShift);

Expand Down
19 changes: 19 additions & 0 deletions src/HeboTech.ATLib.Tests/CodingSchemes/MessageClassTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HeboTech.ATLib.CodingSchemes;
using Xunit;

namespace HeboTech.ATLib.Tests.CodingSchemes
{
public class MessageClassTests
{
[Theory]
[InlineData(MessageClass.Default, 0x00)]
[InlineData(MessageClass.Class0, 0x01)]
[InlineData(MessageClass.Class1, 0x02)]
[InlineData(MessageClass.Class2, 0x03)]
[InlineData(MessageClass.Class3, 0x04)]
internal void Has_correct_values(MessageClass messageClass, int expectedValue)
{
Assert.Equal(expectedValue, (int)messageClass);
}
}
}
29 changes: 29 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/BatteryChargeStatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using HeboTech.ATLib.DTOs;
using HeboTech.ATLib.Extensions;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class BatteryChargeStatusTests
{
[Theory]
[InlineData(BatteryChargeStatus.PoweredByBattery, 0)]
[InlineData(BatteryChargeStatus.Charging, 1)]
[InlineData(BatteryChargeStatus.ChargingFinished, 2)]
[InlineData(BatteryChargeStatus.PowerFault, 3)]
internal void Has_correct_values(BatteryChargeStatus batteryChargeStatus, int expectedValue)
{
Assert.Equal(expectedValue, (int)batteryChargeStatus);
}

[Theory]
[InlineData(BatteryChargeStatus.PoweredByBattery, "Powered by battery")]
[InlineData(BatteryChargeStatus.Charging, "Charging")]
[InlineData(BatteryChargeStatus.ChargingFinished, "Charging finished")]
[InlineData(BatteryChargeStatus.PowerFault, "Power fault")]
internal void Has_correct_descriptions(BatteryChargeStatus batteryChargeStatus, string expectedValue)
{
Assert.Equal(expectedValue, batteryChargeStatus.GetDescription());
}
}
}
29 changes: 29 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/BatteryStatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using HeboTech.ATLib.DTOs;
using UnitsNet;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class BatteryStatusTests
{
[Fact]
internal void Sets_properties()
{
BatteryStatus sut = new(BatteryChargeStatus.Charging, Ratio.FromPercent(69));

Assert.Equal(BatteryChargeStatus.Charging, sut.Status);
Assert.Equal(Ratio.FromPercent(69), sut.ChargeLevel);
Assert.Null(sut.Voltage);
}

[Fact]
internal void Sets_properties_including_voltage()
{
BatteryStatus sut = new(BatteryChargeStatus.Charging, Ratio.FromPercent(69), ElectricPotential.FromVolts(2.7));

Assert.Equal(BatteryChargeStatus.Charging, sut.Status);
Assert.Equal(Ratio.FromPercent(69), sut.ChargeLevel);
Assert.Equal(ElectricPotential.FromVolts(2.7), sut.Voltage);
}
}
}
17 changes: 17 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/CallDetailsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HeboTech.ATLib.DTOs;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class CallDetailsTests
{
[Fact]
internal void Sets_properties()
{
CallDetails sut = new(TimeSpan.FromMinutes(7));

Assert.Equal(TimeSpan.FromMinutes(7), sut.Duration);
}
}
}
16 changes: 16 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/ImsiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HeboTech.ATLib.DTOs;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class ImsiTests
{
[Fact]
public void Sets_properties()
{
Imsi sut = new("123451234512345");

Assert.Equal("123451234512345", sut.Value);
}
}
}
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));
}
}
}
24 changes: 24 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/NumberPlanIdentificationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using HeboTech.ATLib.DTOs;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class NumberplanIdentificationTests
{
[Theory]
[InlineData(NumberPlanIdentification.Unknown, 0x00)]
[InlineData(NumberPlanIdentification.ISDN, 0x01)]
[InlineData(NumberPlanIdentification.DataNumbering, 0x03)]
[InlineData(NumberPlanIdentification.Telex, 0x04)]
[InlineData(NumberPlanIdentification.ServiceCentreSpecific1, 0x05)]
[InlineData(NumberPlanIdentification.ServiceCentreSpecific2, 0x06)]
[InlineData(NumberPlanIdentification.NationalNumbering, 0x08)]
[InlineData(NumberPlanIdentification.PrivateNumbering, 0x09)]
[InlineData(NumberPlanIdentification.ErmesNumbering, 0x0A)]
[InlineData(NumberPlanIdentification.ReservedForExtension, 0x0F)]
internal void Has_correct_values(NumberPlanIdentification numberplanIdentification, int expectedValue)
{
Assert.Equal(expectedValue, (int)numberplanIdentification);
}
}
}
30 changes: 30 additions & 0 deletions src/HeboTech.ATLib.Tests/DTOs/PersonalIdentificationNumberTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HeboTech.ATLib.DTOs;
using System;
using Xunit;

namespace HeboTech.ATLib.Tests.DTOs
{
public class PersonalIdentificationNumberTests
{
[Fact]
internal void Sets_properties()
{
PersonalIdentificationNumber sut = new("1234");

Assert.Equal("1234", sut.Pin);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("12345")]
[InlineData("A123")]
[InlineData("ABCD")]
internal void Invalid_pin_throws(string pin)
{
Assert.Throws<ArgumentException>(() => new PersonalIdentificationNumber(pin));
}
}
}
Loading

0 comments on commit 83a3c98

Please sign in to comment.