Exemplo n.º 1
0
        public void TestArgumentExceptions()
        {
            var      uids = new UniqueIdSet(SortOrder.Ascending);
            UniqueId uid;

            Assert.IsFalse(uids.IsReadOnly);

            uids.Add(UniqueId.MinValue);

            Assert.Throws <ArgumentOutOfRangeException> (() => new UniqueIdSet((SortOrder)500));
            Assert.Throws <ArgumentException> (() => uids.Add(UniqueId.Invalid));
            Assert.Throws <ArgumentNullException> (() => uids.AddRange(null));
            Assert.Throws <ArgumentNullException> (() => uids.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.CopyTo(new UniqueId[1], -1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uid = uids[-1]);
            Assert.Throws <NotSupportedException> (() => uids[0]   = UniqueId.MinValue);
            Assert.Throws <NotSupportedException> (() => uids.Insert(0, UniqueId.MinValue));

            var list = new List <UniqueId> {
                UniqueId.Invalid
            };

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.ToString(null));
            Assert.Throws <ArgumentException> (() => UniqueIdSet.ToString(list));

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.TryParse(null, out uids));
        }
Exemplo n.º 2
0
 static void ProcessUnmodified(ImapCommand ic, ref UniqueIdSet uids, ulong?modseq)
 {
     if (modseq.HasValue)
     {
         foreach (var rc in ic.RespCodes.OfType <ModifiedResponseCode> ())
         {
             if (uids != null)
             {
                 uids.AddRange(rc.UidSet);
             }
             else
             {
                 uids = rc.UidSet;
             }
         }
     }
 }
Exemplo n.º 3
0
		public void TestArgumentExceptions ()
		{
			var uids = new UniqueIdSet (SortOrder.Ascending);
			UniqueId uid;

			uids.Add (UniqueId.MinValue);

			Assert.Throws<ArgumentException> (() => uids.Add (UniqueId.Invalid));
			Assert.Throws<ArgumentNullException> (() => uids.AddRange (null));
			Assert.Throws<ArgumentNullException> (() => uids.CopyTo (null, 0));
			Assert.Throws<ArgumentOutOfRangeException> (() => uids.CopyTo (new UniqueId[1], -1));
			Assert.Throws<ArgumentOutOfRangeException> (() => uids.RemoveAt (-1));
			Assert.Throws<ArgumentOutOfRangeException> (() => uid = uids[-1]);
			Assert.Throws<NotSupportedException> (() => uids[0] = UniqueId.MinValue);
			Assert.Throws<NotSupportedException> (() => uids.Insert (0, UniqueId.MinValue));

			var list = new List<UniqueId> { UniqueId.Invalid };
			Assert.Throws<ArgumentNullException> (() => UniqueIdSet.ToString (null));
			Assert.Throws<ArgumentException> (() => UniqueIdSet.ToString (list));

			Assert.Throws<ArgumentNullException> (() => UniqueIdSet.TryParse (null, out uids));
		}
Exemplo n.º 4
0
        public void TestAscendingUniqueIdSet()
        {
            UniqueId[] uids =
            {
                new UniqueId(1), new UniqueId(2), new UniqueId(3),
                new UniqueId(4), new UniqueId(5), new UniqueId(6),
                new UniqueId(7), new UniqueId(8), new UniqueId(9)
            };
            var list   = new UniqueIdSet(uids, SortOrder.Ascending);
            var actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect initial value.");
            Assert.AreEqual(9, list.Count, "Incorrect initial count.");
            Assert.AreEqual(-1, list.IndexOf(new UniqueId(500)));
            Assert.IsFalse(list.Contains(new UniqueId(500)));
            Assert.IsFalse(list.Remove(new UniqueId(500)));

            // Test Remove()

            list.Remove(uids[0]);
            actual = list.ToString();

            Assert.AreEqual("2:9", actual, "Incorrect results after Remove() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Remove() #1.");

            list.Remove(uids[uids.Length - 1]);
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after Remove() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Remove() #2.");

            list.Remove(uids[4]);
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8", actual, "Incorrect results after Remove() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after Remove() #3.");

            // Test Add()

            list.Add(new UniqueId(5));
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after Add() #1.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Add() #1.");

            list.Add(new UniqueId(1));
            actual = list.ToString();

            Assert.AreEqual("1:8", actual, "Incorrect results after Add() #2.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Add() #2.");

            list.Add(new UniqueId(9));
            actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect results after Add() #3.");
            Assert.AreEqual(9, list.Count, "Incorrect count after Add() #3.");

            // Test RemoveAt()

            list.RemoveAt(0);
            actual = list.ToString();

            Assert.AreEqual("2:9", actual, "Incorrect results after RemoveAt() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after RemoveAt() #1.");

            list.RemoveAt(7);
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after RemoveAt() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after RemoveAt() #2.");

            list.RemoveAt(3);
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8", actual, "Incorrect results after RemoveAt() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after RemoveAt() #3.");

            // Test adding a range of items

            list.AddRange(uids);
            actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect results after AddRange().");
            Assert.AreEqual(9, list.Count, "Incorrect count after AddRange().");

            // Test clearing the list
            list.Clear();
            Assert.AreEqual(0, list.Count, "Incorrect count after Clear().");
        }
Exemplo n.º 5
0
        public void TestUnsortedUniqueIdSet()
        {
            UniqueId[] uids =
            {
                new UniqueId(1), new UniqueId(2), new UniqueId(3),
                new UniqueId(4), new UniqueId(5), new UniqueId(6),
                new UniqueId(7), new UniqueId(8), new UniqueId(9)
            };
            var list   = new UniqueIdSet(uids);
            var actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect initial value.");
            Assert.AreEqual(9, list.Count, "Incorrect initial count.");

            // Test Remove()

            list.Remove(uids[0]);
            actual = list.ToString();

            Assert.AreEqual("2:9", actual, "Incorrect results after Remove() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Remove() #1.");

            list.Remove(uids[uids.Length - 1]);
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after Remove() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Remove() #2.");

            list.Remove(uids[4]);
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8", actual, "Incorrect results after Remove() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after Remove() #3.");

            // Test Add()

            list.Add(new UniqueId(5));
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8,5", actual, "Incorrect results after Add() #1.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Add() #1.");

            list.Add(new UniqueId(1));
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8,5,1", actual, "Incorrect results after Add() #2.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Add() #2.");

            list.Add(new UniqueId(9));
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8,5,1,9", actual, "Incorrect results after Add() #3.");
            Assert.AreEqual(9, list.Count, "Incorrect count after Add() #3.");

            // Test RemoveAt()

            list.RemoveAt(0);
            actual = list.ToString();

            Assert.AreEqual("3:4,6:8,5,1,9", actual, "Incorrect results after RemoveAt() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after RemoveAt() #1.");

            list.RemoveAt(7);
            actual = list.ToString();

            Assert.AreEqual("3:4,6:8,5,1", actual, "Incorrect results after RemoveAt() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after RemoveAt() #2.");

            list.RemoveAt(3);
            actual = list.ToString();

            Assert.AreEqual("3:4,6,8,5,1", actual, "Incorrect results after RemoveAt() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after RemoveAt() #3.");

            // Test adding a range of items

            list.AddRange(uids);
            actual = list.ToString();

            Assert.AreEqual("3:4,6,8,5,1:2,7,9", actual, "Incorrect results after AddRange().");
            Assert.AreEqual(9, list.Count, "Incorrect count after AddRange().");

            // Test clearing the list
            list.Clear();
            Assert.AreEqual(0, list.Count, "Incorrect count after Clear().");
        }
Exemplo n.º 6
0
        async Task <IList <UniqueId> > StoreAsync(IList <UniqueId> uids, ulong?modseq, IList <Annotation> annotations, bool doAsync, CancellationToken cancellationToken)
        {
            if (uids == null)
            {
                throw new ArgumentNullException(nameof(uids));
            }

            if (modseq.HasValue && !SupportsModSeq)
            {
                throw new NotSupportedException("The ImapFolder does not support mod-sequences.");
            }

            if (annotations == null)
            {
                throw new ArgumentNullException(nameof(annotations));
            }

            CheckState(true, true);

            if (AnnotationAccess == AnnotationAccess.None)
            {
                throw new NotSupportedException("The ImapFolder does not support annotations.");
            }

            if (uids.Count == 0 || annotations.Count == 0)
            {
                return(new UniqueId[0]);
            }

            var         builder  = new StringBuilder("UID STORE %s ");
            var         values   = new List <object> ();
            UniqueIdSet modified = null;

            if (modseq.HasValue)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "(UNCHANGEDSINCE {0}) ", modseq.Value);
            }

            ImapUtils.FormatAnnotations(builder, annotations, values, true);
            builder.Append("\r\n");

            var command = builder.ToString();
            var args    = values.ToArray();

            foreach (var ic in Engine.QueueCommands(cancellationToken, this, command, uids, args))
            {
                await Engine.RunAsync(ic, doAsync).ConfigureAwait(false);

                ProcessResponseCodes(ic, null);

                if (ic.Response != ImapCommandResponse.Ok)
                {
                    throw ImapCommandException.Create("STORE", ic);
                }

                if (modseq.HasValue)
                {
                    var rc = ic.RespCodes.OfType <ModifiedResponseCode> ().FirstOrDefault();

                    if (rc != null)
                    {
                        if (modified != null)
                        {
                            modified.AddRange(rc.UidSet);
                        }
                        else
                        {
                            modified = rc.UidSet;
                        }
                    }
                }
            }

            if (modified == null)
            {
                return(new UniqueId[0]);
            }

            return(modified);
        }
Exemplo n.º 7
0
		public void TestSortedUniqueIdSet ()
		{
			UniqueId[] uids = {
				new UniqueId (1), new UniqueId (2), new UniqueId (3),
				new UniqueId (4), new UniqueId (5), new UniqueId (6),
				new UniqueId (7), new UniqueId (8), new UniqueId (9)
			};
			var list = new UniqueIdSet (uids, true);
			var actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect initial value.");
			Assert.AreEqual (9, list.Count, "Incorrect initial count.");

			// Test Remove()

			list.Remove (uids[0]);
			actual = list.ToString ();

			Assert.AreEqual ("2:9", actual, "Incorrect results after Remove() #1.");
			Assert.AreEqual (8, list.Count, "Incorrect count after Remove() #1.");

			list.Remove (uids[uids.Length - 1]);
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after Remove() #2.");
			Assert.AreEqual (7, list.Count, "Incorrect count after Remove() #2.");

			list.Remove (uids[4]);
			actual = list.ToString ();

			Assert.AreEqual ("2:4,6:8", actual, "Incorrect results after Remove() #3.");
			Assert.AreEqual (6, list.Count, "Incorrect count after Remove() #3.");

			// Test Add()

			list.Add (new UniqueId (5));
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after Add() #1.");
			Assert.AreEqual (7, list.Count, "Incorrect count after Add() #1.");

			list.Add (new UniqueId (1));
			actual = list.ToString ();

			Assert.AreEqual ("1:8", actual, "Incorrect results after Add() #2.");
			Assert.AreEqual (8, list.Count, "Incorrect count after Add() #2.");

			list.Add (new UniqueId (9));
			actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect results after Add() #3.");
			Assert.AreEqual (9, list.Count, "Incorrect count after Add() #3.");

			// Test RemoveAt()

			list.RemoveAt (0);
			actual = list.ToString ();

			Assert.AreEqual ("2:9", actual, "Incorrect results after RemoveAt() #1.");
			Assert.AreEqual (8, list.Count, "Incorrect count after RemoveAt() #1.");

			list.RemoveAt (7);
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after RemoveAt() #2.");
			Assert.AreEqual (7, list.Count, "Incorrect count after RemoveAt() #2.");

			list.RemoveAt (3);
			actual = list.ToString ();

			Assert.AreEqual ("2:4,6:8", actual, "Incorrect results after RemoveAt() #3.");
			Assert.AreEqual (6, list.Count, "Incorrect count after RemoveAt() #3.");

			// Test adding a range of items

			list.AddRange (uids);
			actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect results after AddRange().");
			Assert.AreEqual (9, list.Count, "Incorrect count after AddRange().");

			// Test clearing the list
			list.Clear ();
			Assert.AreEqual (0, list.Count, "Incorrect count after Clear().");
		}