public async Task WhenICreatedAServiceHook(KeyValuePair <string, string> teamProject) { var service = new VstsService(); var teamProjects = await service.GetProjects(Config.Account, Config.Token); var tp = teamProjects.FirstOrDefault(p => p.Name.Equals(teamProject.Value, StringComparison.OrdinalIgnoreCase)); var subscription = new Subscription { ConsumerActionId = "httpRequest", ConsumerId = "webHooks", ConsumerInputs = new Dictionary <string, string> { { "url", "https://myservice/myhookeventreceiver" } }, EventType = "build.complete", PublisherId = "tfs", PublisherInputs = new Dictionary <string, string> { { "buildStatus", "Failed" }, { "definitionName", "Build 1" }, { "projectId", tp.Id.ToString() } }, ResourceVersion = "1.0-preview.1" }; subscription = await service.CreateSubscription(Config.Account, subscription, Config.Token); ScenarioContext.Current["SubscriptionId"] = subscription.Id; }
public async Task GetProjectsTest() { var account = "anaccount"; var service = new VstsService(); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(null, this.token)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(account, null)); using (ShimsContext.Create()) { var accounts = new List <Account> { new Account(Guid.Empty) { AccountName = "myaccount", AccountUri = new Uri("https://myaccount.visualstudio.com") } }; var expected = new List <TeamProjectReference> { new TeamProjectReference { Id = Guid.NewGuid(), Name = "My Project", Url = "https://myaccount.visualstudio.com/my%20project" } }; var clients = new VssHttpClientBase[] { GetAccountHttpClient(accounts), GetProjectHttpClient(expected), GetProfileHttpClient(new Profile()) }; InitializeConnectionShim(clients); // await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async () => await service.GetProjects("someaccount", this.token)); IEnumerable <TeamProjectReference> actual = await service.GetProjects(accounts[0].AccountName, this.token); expected.ShouldAllBeEquivalentTo(actual); } }