Beispiel #1
0
        static void TestParse(string text)
        {
            var          buffer = Encoding.ASCII.GetBytes(text);
            GroupAddress group;

            try {
                Assert.IsTrue(GroupAddress.TryParse(text, out group), "GroupAddress.TryParse(string) should succeed.");
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.TryParse(string) should not throw an exception: {0}", ex);
            }

            try {
                Assert.IsTrue(GroupAddress.TryParse(buffer, out group), "GroupAddress.TryParse(byte[]) should succeed.");
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.TryParse(byte[]) should not throw an exception: {0}", ex);
            }

            try {
                Assert.IsTrue(GroupAddress.TryParse(buffer, 0, out group), "GroupAddress.TryParse(byte[], int) should succeed.");
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.TryParse(byte[], int) should not throw an exception: {0}", ex);
            }

            try {
                Assert.IsTrue(GroupAddress.TryParse(buffer, 0, buffer.Length, out group), "GroupAddress.TryParse(byte[], int, int) should succeed.");
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.TryParse(byte[], int, int) should not throw an exception: {0}", ex);
            }

            try {
                group = GroupAddress.Parse(text);
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.Parse(string) should not throw an exception: {0}", ex);
            }

            try {
                group = GroupAddress.Parse(buffer);
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.Parse(string) should not throw an exception: {0}", ex);
            }

            try {
                group = GroupAddress.Parse(buffer, 0);
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.Parse(string) should not throw an exception: {0}", ex);
            }

            try {
                group = GroupAddress.Parse(buffer, 0, buffer.Length);
            } catch (Exception ex) {
                Assert.Fail("GroupAddress.Parse(string) should not throw an exception: {0}", ex);
            }
        }
Beispiel #2
0
        public void TestNestedGroupAddresses()
        {
            const string expected = "(NIL NIL NIL NIL NIL ((NIL NIL \"Agents of Shield\" NIL)(NIL NIL \"Mutants\" NIL)(\"Skye\" NIL \"skye\" \"shield.gov\")(NIL NIL NIL NIL)(\"Leo Fitz\" NIL \"fitz\" \"shield.gov\")(\"Melinda May\" NIL \"may\" \"shield.gov\")(NIL NIL NIL NIL)) NIL NIL NIL NIL)";
            var          group    = GroupAddress.Parse("Agents of Shield: Mutants: Skye <*****@*****.**>;, Leo Fitz <*****@*****.**>, Melinda May <*****@*****.**>;");
            var          envelope = new Envelope();

            envelope.To.Add(group);

            Assert.AreEqual(expected, envelope.ToString());
            Assert.IsTrue(Envelope.TryParse(expected, out envelope));
            Assert.AreEqual(expected, envelope.ToString());
            Assert.AreEqual(1, envelope.To.Count);
            Assert.AreEqual(group.ToString(), envelope.To[0].ToString());
        }
Beispiel #3
0
        static void TestParseFailure(string text, bool result, int tokenIndex, int errorIndex)
        {
            var          buffer = text.Length > 0 ? Encoding.ASCII.GetBytes(text) : new byte[1];
            GroupAddress group;

            Assert.AreEqual(result, GroupAddress.TryParse(text, out group), "GroupAddress.TryParse(string)");
            Assert.AreEqual(result, GroupAddress.TryParse(buffer, out group), "GroupAddress.TryParse(byte[])");
            Assert.AreEqual(result, GroupAddress.TryParse(buffer, 0, out group), "GroupAddress.TryParse(byte[], int)");
            Assert.AreEqual(result, GroupAddress.TryParse(buffer, 0, buffer.Length, out group), "GroupAddress.TryParse(byte[], int, int)");

            try {
                GroupAddress.Parse(text);
                Assert.Fail("GroupAddress.Parse(string) should fail.");
            } catch (ParseException ex) {
                Assert.AreEqual(tokenIndex, ex.TokenIndex, "ParseException did not have the correct token index.");
                Assert.AreEqual(errorIndex, ex.ErrorIndex, "ParseException did not have the error index.");
            } catch {
                Assert.Fail("GroupAddress.Parse(string) should throw ParseException.");
            }

            try {
                GroupAddress.Parse(buffer);
                Assert.Fail("GroupAddress.Parse(byte[]) should fail.");
            } catch (ParseException ex) {
                Assert.AreEqual(tokenIndex, ex.TokenIndex, "ParseException did not have the correct token index.");
                Assert.AreEqual(errorIndex, ex.ErrorIndex, "ParseException did not have the error index.");
            } catch {
                Assert.Fail("GroupAddress.Parse(new byte[]) should throw ParseException.");
            }

            try {
                GroupAddress.Parse(buffer, 0);
                Assert.Fail("GroupAddress.Parse(byte[], int) should fail.");
            } catch (ParseException ex) {
                Assert.AreEqual(tokenIndex, ex.TokenIndex, "ParseException did not have the correct token index.");
                Assert.AreEqual(errorIndex, ex.ErrorIndex, "ParseException did not have the error index.");
            } catch {
                Assert.Fail("GroupAddress.Parse(new byte[], int) should throw ParseException.");
            }

            try {
                GroupAddress.Parse(buffer, 0, buffer.Length);
                Assert.Fail("GroupAddress.Parse(byte[], int, int) should fail.");
            } catch (ParseException ex) {
                Assert.AreEqual(tokenIndex, ex.TokenIndex, "ParseException did not have the correct token index.");
                Assert.AreEqual(errorIndex, ex.ErrorIndex, "ParseException did not have the error index.");
            } catch {
                Assert.Fail("GroupAddress.Parse(new byte[], int, int) should throw ParseException.");
            }
        }