コード例 #1
0
        private void StartChannelSubscriptionInfo(ChannelSubscriptionInfo info, MockIndex startIndex, bool sendChanges)
        {
            info.IsStarted = true;
            info.Query     = new ChannelDataQuery
            {
                Channel               = info.Channel as IMockGrowingObject,
                ChannelId             = info.ChannelId,
                IsStartIndexInclusive = true,
                EndIndex              = null,
            };
            info.SendChanges = sendChanges;

            info.Query.StartIndex = startIndex == null
                ? info.Query.Channel.EndIndex
                : info.Query.Channel.GetIndex(startIndex);
        }
コード例 #2
0
        public async Task TooManyArguments()
        {
            var auth = new MockIndex <string, IAuthenticationSession>
            {
                { "PLAIN", new MockPlainTextAuth(MockPlainTextAuth.Action.Null) }
            };
            var channel         = new MockSmtpChannel();
            var mockMailBuilder = new MockMailBuilder();
            var command         = new AuthenticateCommand(auth, channel, mockMailBuilder);

            command.Initialize("MECH INITIAL");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.InvalidArguments);
            Assert.Null(channel.AuthenticatedUser);
        }
コード例 #3
0
        public async Task SuccessfulAuth()
        {
            var auth = new MockIndex <string, IAuthenticationSession>
            {
                { "PLAIN", new MockPlainTextAuth(MockPlainTextAuth.Action.Return) }
            };

            var channel         = new MockSmtpChannel();
            var mockMailBuilder = new MockMailBuilder();
            var command         = new AuthenticateCommand(auth, channel, mockMailBuilder);

            command.Initialize("PLAIN");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.AuthenticationComplete);
            Assert.NotNull(channel.AuthenticatedUser);
            Assert.Equal(MockPlainTextAuth.UserMailbox, channel.AuthenticatedUser.Mailbox);
        }
コード例 #4
0
        public async Task DuringMailSession()
        {
            var auth = new MockIndex <string, IAuthenticationSession>
            {
                { "PLAIN", new MockPlainTextAuth(MockPlainTextAuth.Action.Null) }
            };

            var channel         = new MockSmtpChannel();
            var mockMailBuilder = new MockMailBuilder {
                PendingMail = new SmtpMailMessage(new SmtpPath("*****@*****.**"))
            };
            var command = new AuthenticateCommand(auth, channel, mockMailBuilder);

            command.Initialize("PLAIN");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.BadSequence);
            Assert.Null(channel.AuthenticatedUser);
        }
コード例 #5
0
        public async Task AlreadyAuthed()
        {
            var auth = new MockIndex <string, IAuthenticationSession>
            {
                { "PLAIN", new MockPlainTextAuth(MockPlainTextAuth.Action.Null) }
            };

            var user    = new UserData("*****@*****.**");
            var channel = new MockSmtpChannel {
                AuthenticatedUser = user
            };
            var mockMailBuilder = new MockMailBuilder();
            var command         = new AuthenticateCommand(auth, channel, mockMailBuilder);

            command.Initialize("PLAIN");
            await command.ExecuteAsync(CancellationToken.None);

            SmtpTestHelper.AssertResponse(channel, SmtpReplyCode.BadSequence);
            Assert.Same(user, channel.AuthenticatedUser);
        }
コード例 #6
0
        public bool StartChannelStreaming(Guid sessionId, long channelId, bool sendChanges, MockIndex startIndex)
        {
            CheckLocked();

            ChannelSubscription channelSubscription;

            if (!ChannelSubscriptionsBySessionId.TryGetValue(sessionId, out channelSubscription))
            {
                return(false);
            }

            ChannelSubscriptionInfo info;

            if (!channelSubscription.ValidChannelIds.TryGetValue(channelId, out info))
            {
                return(false);
            }

            var channel = GetChannel(sessionId, channelId) as IMockGrowingObject;

            if (channel == null)
            {
                return(false);
            }

            StartChannelSubscriptionInfo(info, startIndex, sendChanges);

            return(true);
        }