|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | +using SysadminsLV.Asn1Parser.Universal; |
| 5 | + |
| 6 | +namespace Asn1Parser.Tests; |
| 7 | + |
| 8 | +[TestClass] |
| 9 | +public class Asn1OidTests { |
| 10 | + [TestMethod, Description("Test if at least two arcs are encoded.")] |
| 11 | + public void TestMinStringLengthEncode() { |
| 12 | + var oid = new Asn1ObjectIdentifier("0.0"); |
| 13 | + Assert.AreEqual("0.0", oid.Value.Value); |
| 14 | + String encodedB64 = Convert.ToBase64String(oid.GetRawData()); |
| 15 | + Assert.AreEqual("BgEA", encodedB64); |
| 16 | + } |
| 17 | + [TestMethod, Description("Test if at least two arcs are required.")] |
| 18 | + public void TestMinStringLengthDecode() { |
| 19 | + Byte[] rawData = Convert.FromBase64String("BgEA"); |
| 20 | + var oid = new Asn1ObjectIdentifier(rawData); |
| 21 | + Assert.AreEqual("0.0", oid.Value.Value); |
| 22 | + String encodedB64 = Convert.ToBase64String(oid.GetRawData()); |
| 23 | + Assert.AreEqual("BgEA", encodedB64); |
| 24 | + } |
| 25 | + [TestMethod, Description("Test if single arc encoding fails.")] |
| 26 | + [ExpectedException(typeof(InvalidDataException))] |
| 27 | + public void TestSingleArcEncodeFail() { |
| 28 | + new Asn1ObjectIdentifier("0"); |
| 29 | + } |
| 30 | + [TestMethod, Description("Test if 2nd arc under 'ITU' root node encoded up to 39.")] |
| 31 | + public void TestItuRootArcConstraintsPass() { |
| 32 | + new Asn1ObjectIdentifier("1.39"); |
| 33 | + } |
| 34 | + [TestMethod, Description("Test if 2nd arc under 'ITU' root node >39 fails.")] |
| 35 | + [ExpectedException(typeof(InvalidDataException))] |
| 36 | + public void TestItuRootArcConstraintsFail() { |
| 37 | + new Asn1ObjectIdentifier("1.40"); |
| 38 | + } |
| 39 | +} |
0 commit comments