Beispiel #1
0
        public async Task TestSearchAnnotationsAsync()
        {
            var commands = CreateSearchAnnotationsCommands();

            using (var client = new ImapClient()) {
                var credentials = new NetworkCredential("username", "password");

                try {
                    await client.ReplayConnectAsync("localhost", new ImapReplayStream (commands, true));
                } catch (Exception ex) {
                    Assert.Fail("Did not expect an exception in Connect: {0}", ex);
                }

                // Note: we do not want to use SASL at all...
                client.AuthenticationMechanisms.Clear();

                try {
                    await client.AuthenticateAsync(credentials);
                } catch (Exception ex) {
                    Assert.Fail("Did not expect an exception in Authenticate: {0}", ex);
                }

                Assert.IsInstanceOf <ImapEngine> (client.Inbox.SyncRoot, "SyncRoot");

                var inbox = (ImapFolder)client.Inbox;
                await inbox.OpenAsync(FolderAccess.ReadWrite);

                Assert.AreEqual(AnnotationAccess.ReadOnly, inbox.AnnotationAccess, "AnnotationAccess");
                Assert.AreEqual(AnnotationScope.Both, inbox.AnnotationScopes, "AnnotationScopes");
                Assert.AreEqual(0, inbox.MaxAnnotationSize, "MaxAnnotationSize");

                var query = SearchQuery.AnnotationsContain(AnnotationEntry.Comment, AnnotationAttribute.Value, "a comment");
                var uids  = await inbox.SearchAsync(query);

                Assert.AreEqual(14, uids.Count, "Unexpected number of UIDs");

                // disable ANNOTATE-EXPERIMENT-1 and try again
                client.Capabilities &= ~ImapCapabilities.Annotate;

                Assert.ThrowsAsync <NotSupportedException> (async() => await inbox.SearchAsync(query));

                await client.DisconnectAsync(false);
            }
        }
Beispiel #2
0
        public void TestArgumentExceptions()
        {
            Assert.Throws <ArgumentNullException> (() => SearchQuery.And(null, SearchQuery.All));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.And(SearchQuery.All, null));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.AnnotationsContain(null, AnnotationAttribute.Value, "value"));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.AnnotationsContain(AnnotationEntry.AltSubject, null, "value"));
            Assert.Throws <ArgumentException> (() => SearchQuery.AnnotationsContain(AnnotationEntry.AltSubject, AnnotationAttribute.Size, "value"));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.BccContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.BccContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.BodyContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.BodyContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.CcContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.CcContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.DoesNotHaveCustomFlag(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.DoesNotHaveCustomFlag(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.DoesNotHaveCustomFlags(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.DoesNotHaveCustomFlags(new string[0]));
            Assert.Throws <ArgumentException> (() => SearchQuery.DoesNotHaveFlags(MessageFlags.None));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.Filter(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.Filter(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.FromContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.FromContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.Fuzzy(null));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.GMailRawSearch(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.GMailRawSearch(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HasCustomFlag(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasCustomFlag(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HasCustomFlags(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasCustomFlags(new string[0]));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasFlags(MessageFlags.None));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HasKeyword(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasKeyword(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HasKeywords(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasKeywords(new string[0]));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasKeywords(new string[] { "keyword", null }));
            Assert.Throws <ArgumentException> (() => SearchQuery.NotFlags(MessageFlags.None));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.NotKeyword(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.NotKeyword(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.NotKeywords(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.NotKeywords(new string[0]));
            Assert.Throws <ArgumentException> (() => SearchQuery.NotKeywords(new string [] { "keyword", null }));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HasGMailLabel(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.HasGMailLabel(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HeaderContains(null, "text"));
            Assert.Throws <ArgumentException> (() => SearchQuery.HeaderContains(string.Empty, "text"));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.HeaderContains("name", null));
            Assert.Throws <ArgumentOutOfRangeException> (() => SearchQuery.LargerThan(-1));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.MessageContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.MessageContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.Not(null));
            Assert.Throws <ArgumentOutOfRangeException> (() => SearchQuery.OlderThan(-1));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.Or(null, SearchQuery.All));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.Or(SearchQuery.All, null));
            Assert.Throws <ArgumentOutOfRangeException> (() => SearchQuery.SmallerThan(-1));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.SubjectContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.SubjectContains(string.Empty));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.ToContains(null));
            Assert.Throws <ArgumentException> (() => SearchQuery.ToContains(string.Empty));
            Assert.Throws <ArgumentOutOfRangeException> (() => SearchQuery.YoungerThan(-1));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.All.And(null));
            Assert.Throws <ArgumentNullException> (() => SearchQuery.All.Or(null));

            Assert.Throws <ArgumentNullException> (() => new BinarySearchQuery(SearchTerm.And, null, SearchQuery.All));
            Assert.Throws <ArgumentNullException> (() => new BinarySearchQuery(SearchTerm.And, SearchQuery.All, null));
            Assert.Throws <ArgumentNullException> (() => new FilterSearchQuery(null));
            Assert.Throws <ArgumentException> (() => new FilterSearchQuery(string.Empty));
            Assert.Throws <ArgumentException> (() => new FilterSearchQuery(MetadataTag.Create("/dev/null")));
            Assert.Throws <ArgumentNullException> (() => new HeaderSearchQuery(null, "text"));
            Assert.Throws <ArgumentException> (() => new HeaderSearchQuery(string.Empty, "text"));
            Assert.Throws <ArgumentNullException> (() => new HeaderSearchQuery("name", null));
            Assert.Throws <ArgumentNullException> (() => new TextSearchQuery(SearchTerm.BodyContains, null));
            Assert.Throws <ArgumentNullException> (() => new UidSearchQuery(null));
            Assert.Throws <ArgumentException> (() => new UidSearchQuery(new UniqueIdSet()));
            Assert.Throws <ArgumentException> (() => new UidSearchQuery(UniqueId.Invalid));
            Assert.Throws <ArgumentNullException> (() => new UnarySearchQuery(SearchTerm.Not, null));
        }