public void GivenProjects_WhenAskingToCreate_ShouldHydrateProjects()
        {
            // arrange
            string         projectsJson    = new TestData().Projects();
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(projectsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/_apis/projects?api-version=4.1-preview.1"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IProjectsFactory projectsFactory = new ProjectsFactory(vstsHttpService, configuration);

            // act
            Projects projects = projectsFactory.Create();

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(projects));

            jObject.Value <int>("count").Should().Be(2);

            JToken jProjects = jObject["projects"];

            jProjects.Should().HaveCount(2);

            jProjects[0]["id"].Value <string>().Should().Be("8e161f07-7901-483a-bfd1-52bbc68499a3");
            jProjects[0]["name"].Value <string>().Should().Be("VstsProjectMonitor");
        }
Esempio n. 2
0
 public void Setup()
 {
     _configuration   = new InMemoryConfiguration().Instance();
     _vstsHttpService = new VstsHttpService(
         new Uri(_configuration["VstsApi:BaseUrl"]),
         new FakeHttpMessageHandler(
             new TestData().BuildDefinitions(),
             new Uri(new Uri(_configuration["VstsApi:BaseUrl"]), $"/{Project}/_apis/build/definitions?api-version=4.1"),
             _configuration["VstsApi:PAT"]));
     new Privateer().SetStaticField <VstsHttpService, HttpClient>(_vstsHttpService, "_httpClient", null);
 }
Esempio n. 3
0
        public void GivenNullBugsData_WhenAskingToCreate_ThenItShouldThrowException()
        {
            // arrange
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(null, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/Strickland/_apis/wit/wiql?$top=10000&api-version=5.0-preview.2"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IBugsFactory bugsFactory = new BugsFactory(vstsHttpService, configuration);

            // act
            Action action = () => Task.WaitAll(bugsFactory.Create("Strickland"));

            // assert
            action.Should().Throw <Exception>().WithMessage("Value cannot be null.\r\nParameter name: content");
        }
Esempio n. 4
0
        public void GivenNoBugData_WhenAskingToCreate_ThenItShouldReturnNullObject()
        {
            // arrange
            const string   bugsJson        = "";
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(bugsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/Strickland/_apis/wit/wiql?$top=10000&api-version=5.0-preview.2"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IBugsFactory bugsFactory = new BugsFactory(vstsHttpService, configuration);

            // act
            Bugs bugs = bugsFactory.Create("Strickland").Result;

            // assert
            bugs.Should().BeOfType <NullBugs>();
        }
        public void GivenNullProjects_WhenAskingToCreate_ShouldThrowException()
        {
            // arrange
            string         projectsJson    = null;
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(projectsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/_apis/projects?api-version=4.1-preview.1"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IProjectsFactory projectsFactory = new ProjectsFactory(vstsHttpService, configuration);

            // act
            Action action = () => projectsFactory.Create();

            // assert
            action.Should().Throw <Exception>().WithMessage("Value cannot be null.\r\nParameter name: content");
        }
        public void GivenEmptyProjects_WhenAskingToCreate_ShouldReturnNullObject()
        {
            // arrange
            const string   projectsJson    = "";
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(projectsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/_apis/projects?api-version=4.1-preview.1"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IProjectsFactory projectsFactory = new ProjectsFactory(vstsHttpService, configuration);

            // act
            Projects projects = projectsFactory.Create();

            // assert
            projects.Should().BeOfType <NullProjects>();
        }
Esempio n. 7
0
        public void GivenProjectName_ShouldHydrateBuilds()
        {
            // arrange
            const string projectName = "POCs";

            _configuration   = new InMemoryConfiguration().Instance();
            _vstsHttpService = new VstsHttpService(new Uri(_configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(new TestData().Builds(), new Uri(new Uri(_configuration["VstsApi:BaseUrl"]), "/POCs/_apis/build/builds?api-version=5.0-preview.4"), _configuration["VstsApi:PAT"]));
            new Privateer().SetStaticField <VstsHttpService, HttpClient>(_vstsHttpService, "_httpClient", null);

            IBuildsFactory buildsFactory = new BuildsFactory(_vstsHttpService, _configuration);

            // act
            Builds buildsResult = buildsFactory.Create(projectName);

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(buildsResult));

            jObject.Value <int>("count").Should().Be(2);

            JToken jBuilds = jObject["builds"];

            jBuilds.Should().HaveCount(2);
            jBuilds[0].Value <string>("status").Should().Be("inProgress");
            jBuilds[1].Value <string>("status").Should().Be("completed");
            jBuilds[0].Value <string>("result").Should().Be("pending");
            jBuilds[1].Value <string>("result").Should().Be("succeeded");
            jBuilds[0].Value <string>("buildNumber").Should().Be("1.0.0.2");
            jBuilds[1].Value <string>("buildNumber").Should().Be("20180401.7");

            DateTime dateTime1 = DateTime.Parse("2018-05-17T03:56:10.1694968Z");

            jBuilds[0].Value <DateTime>("startTime").AddHours(TimeZoneInfo.Local.GetUtcOffset(dateTime1).TotalHours).Should().Be(dateTime1);

            DateTime dateTime2 = DateTime.Parse("2018-04-01T22:42:00.0890697Z");

            jBuilds[1].Value <DateTime>("startTime").AddHours(TimeZoneInfo.Local.GetUtcOffset(dateTime2).TotalHours).Should().Be(dateTime2);

            JObject jDefinition = jBuilds[0].Value <JObject>("definition");

            jDefinition["id"].Value <int>().Should().Be(3);
            jDefinition["name"].Value <string>().Should().Be("Honest Joe's CI");

            JObject jRequestedFor = jBuilds[0].Value <JObject>("requestedFor");

            jRequestedFor["displayName"].Value <string>().Should().Be("Jim");
            jRequestedFor["imageUrl"].Value <string>().Should().Be("https://iontechdotorg.visualstudio.com/_api/_common/identityImage?id=f9a18dab-76b3-42bc-bb3a-103865994dae");
        }
Esempio n. 8
0
        public void GivenDehydratedBugsResponse_WhenAskingToCreate_ThenItShouldReturnDehydratedObject()
        {
            // arrange
            const string   bugsJson        = "{}";
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(bugsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/Strickland/_apis/wit/wiql?$top=10000&api-version=5.0-preview.2"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IBugsFactory bugsFactory = new BugsFactory(vstsHttpService, configuration);

            // act
            Bugs bugs = bugsFactory.Create("Strickland").Result;

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(bugs));

            JToken jBugs = jObject["bugs"];

            jBugs.Should().HaveCount(0);
        }
        public void GivenDehydratedProjectsResponse_WhenAskingToCreate_ShouldReturnDehydratedObject()
        {
            // arrange
            const string   projectsJson    = "{}";
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(projectsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/_apis/projects?api-version=4.1-preview.1"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IProjectsFactory projectsFactory = new ProjectsFactory(vstsHttpService, configuration);

            // act
            Projects projects = projectsFactory.Create();

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(projects));

            jObject.Value <int>("count").Should().Be(0);

            JToken jProjects = jObject["projects"];

            jProjects.Should().HaveCount(0);
        }
Esempio n. 10
0
        public void GivenProjectNameAndDefinitionId_ShouldHydrateBuilds()
        {
            // arrange
            const string projectName        = "POCs";
            List <int>   buildDefinitionIds = new List <int> {
                1, 2
            };

            _configuration   = new InMemoryConfiguration().Instance();
            _vstsHttpService = new VstsHttpService(new Uri(_configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(new TestData().Builds(), new Uri(new Uri(_configuration["VstsApi:BaseUrl"]), $"/POCs/_apis/build/builds?definitions={string.Join(",", buildDefinitionIds)}&api-version=5.0-preview.4"), _configuration["VstsApi:PAT"]));
            new Privateer().SetStaticField <VstsHttpService, HttpClient>(_vstsHttpService, "_httpClient", null);

            IBuildsFactory buildsFactory = new BuildsFactory(_vstsHttpService, _configuration);

            // act
            Builds buildsResult = buildsFactory.Create(projectName, buildDefinitionIds);

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(buildsResult));

            jObject.Value <int>("count").Should().Be(2);
        }
Esempio n. 11
0
        public void GivenBugData_WhenAskingToCreate_ThenItShouldReturnBugs()
        {
            // arrange
            string         bugsJson        = new TestData().Bugs();
            IConfiguration configuration   = new InMemoryConfiguration().Instance();
            IHttpService   vstsHttpService = new VstsHttpService(new Uri(configuration["VstsApi:BaseUrl"]), new FakeHttpMessageHandler(bugsJson, new Uri(new Uri(configuration["VstsApi:BaseUrl"]), "/Strickland/_apis/wit/wiql?$top=10000&api-version=5.0-preview.2"), configuration["VstsApi:PAT"]));

            new Privateer().SetStaticField <VstsHttpService, HttpClient>((VstsHttpService)vstsHttpService, "_httpClient", null);
            IBugsFactory bugsFactory = new BugsFactory(vstsHttpService, configuration);

            // act
            Bugs bugs = bugsFactory.Create("Strickland").Result;

            // assert
            JObject jObject = JObject.Parse(JsonConvert.SerializeObject(bugs));

            JToken jBugs = jObject["bugs"];

            jBugs.Should().HaveCount(11);

            jBugs[0].Value <int>("id").Should().Be(777);
            jBugs[0].Value <string>("url").Should().Be("https://premeraservices.visualstudio.com/d30fd324-c3ab-4edc-ac5d-ba4514ba5ec4/_apis/wit/workItems/777");
        }