Beispiel #1
0
        public async Task Subscribe_Missing_Result()
        {
            var strategies = new List <ISubscriptionStrategy>();

            var target = new SubscriptionsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.DocumentClient.Object, strategies, this.Fixture.VstsService.Object);

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => target.SubscribeAsync(this.Fixture.DialogContext.Object, null));
        }
Beispiel #2
0
        public async Task Subscribe_Missing_Context()
        {
            var strategies = new List <ISubscriptionStrategy>();

            var toBot = this.Fixture.CreateMessage();

            var target = new SubscriptionsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.DocumentClient.Object, strategies, this.Fixture.VstsService.Object);

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => target.SubscribeAsync(null, this.Fixture.MakeAwaitable(toBot)));
        }
Beispiel #3
0
        public async Task Subscribe_MyApprovals()
        {
            var strategies = new List <ISubscriptionStrategy> {
                new MyApprovalSubscriptionStrategy()
            };

            var toBot = this.Fixture.CreateMessage();

            toBot.Text = "subscribe MyApprovals";

            var account = "anAccount";
            var profile = new Profile {
                Token = new OAuthToken()
            };
            var teamProject  = "TeamProject1";
            var teamProjects = new List <TeamProjectReference> {
                new TeamProjectReference {
                    Name = teamProject
                }
            };

            var subscription = new TeamFoundation.Services.WebApi.Subscription {
                CreatedBy = new IdentityRef {
                    Id = "1"
                }
            };
            var subscriptions = new List <Subscription>();

            this.Fixture.DocumentClient
            .Setup(dc => dc.CreateDocumentQuery <Subscription>(It.IsAny <Uri>(), It.IsAny <SqlQuerySpec>(), null))
            .Returns(subscriptions.AsQueryable().OrderBy(s => s.Id));
            this.Fixture.VstsService
            .Setup(s => s.GetProjects(account, profile.Token))
            .ReturnsAsync(teamProjects);
            this.Fixture.VstsService
            .Setup(s => s.CreateSubscription(account, It.IsAny <TeamFoundation.Services.WebApi.Subscription>(), profile.Token))
            .ReturnsAsync(subscription);
            this.Fixture.DocumentClient
            .Setup(dc => dc.UpsertDocumentAsync(It.IsAny <Uri>(), It.IsAny <Subscription>(), null, false))
            .Returns(Task.FromResult(new ResourceResponse <Document>()));

            var target = new SubscriptionsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.DocumentClient.Object, strategies, this.Fixture.VstsService.Object)
            {
                Account     = account,
                Profile     = profile,
                TeamProject = teamProject
            };

            await target.SubscribeAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot));

            this.Fixture.DocumentClient.VerifyAll();
            this.Fixture.DialogContext
            .Verify(c => c.PostAsync(It.IsAny <IMessageActivity>(), CancellationToken.None));
            this.Fixture.DialogContext.Verify(dc => dc.Done(It.IsAny <IMessageActivity>()));
        }
        public async Task Unsubscribe_MyApprovals()
        {
            var strategies = new List <ISubscriptionStrategy> {
                new MyApprovalSubscriptionStrategy()
            };

            var toBot = this.Fixture.CreateMessage();

            toBot.Text = "unsubscribe MyApprovals";

            var account = "anAccount";
            var profile = new Profile {
                Token = new OAuthToken()
            };
            var teamProject = "TeamProject1";

            var subscription = new Subscription
            {
                ChannelId        = toBot.ChannelId,
                SubscriptionId   = Guid.NewGuid(),
                SubscriptionType = SubscriptionType.MyApprovals,
                UserId           = toBot.From.Id
            };
            var subscriptions = new List <Subscription> {
                subscription
            };

            this.Fixture.DocumentClient
            .Setup(dc => dc.CreateDocumentQuery <Subscription>(It.IsAny <Uri>(), It.IsAny <SqlQuerySpec>(), null))
            .Returns(subscriptions.AsQueryable().OrderBy(s => s.Id));
            this.Fixture.DocumentClient
            .Setup(dc => dc.DeleteDocumentAsync(It.IsAny <Uri>(), null))
            .ReturnsAsync(new ResourceResponse <Document>());
            this.Fixture.VstsService
            .Setup(s => s.DeleteSubscription(account, subscription.SubscriptionId, profile.Token))
            .Returns(Task.CompletedTask);

            var target = new SubscriptionsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.DocumentClient.Object, strategies, this.Fixture.VstsService.Object)
            {
                Account     = account,
                Profile     = profile,
                TeamProject = teamProject
            };

            await target.SubscribeAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot));

            this.Fixture.DocumentClient.VerifyAll();
            this.Fixture.DialogContext
            .Verify(c => c.PostAsync(It.IsAny <IMessageActivity>(), CancellationToken.None));
            this.Fixture.DialogContext.Verify(dc => dc.Done(It.IsAny <IMessageActivity>()));
        }
Beispiel #5
0
        public async Task Subscribe_Empty_Text()
        {
            var strategies = new List <ISubscriptionStrategy>();

            var toBot = this.Fixture.CreateMessage();

            toBot.Text = string.Empty;

            var target = new SubscriptionsDialog(this.Fixture.AuthenticationService.Object, this.Fixture.DocumentClient.Object, strategies, this.Fixture.VstsService.Object);

            await target.SubscribeAsync(this.Fixture.DialogContext.Object, this.Fixture.MakeAwaitable(toBot));

            this.Fixture.DialogContext.Verify(c => c.Fail(It.IsAny <UnknownCommandException>()));
        }