public async Task GettingRepoName_RepoBeingMocked_GetsMockedRepoName()
        {
            // Arrange
            var client = _appFactory.CreateClient();

            // Act
            var response = await client.GetAsync("api/meta/mocked");

            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299
            var orgRepoName = await response.Content.ReadAsStringAsync();

            Assert.AreEqual("IOrganisationRepositoryProxy", orgRepoName);
        }
        public async Task Can_Get_Version()
        {
            var response = await _factory.CreateClient().GetAsync("/version");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var body = response.Content.ReadAsStringAsync().Result;

            Assert.NotNull(JObject.Parse(body)["version"]);
        }
        public TestData SetupTestData(bool expectNotification)
        {
            var mockClientFactory = new MockHttpClientFactory();
            var factory           = new TestAppFactory();

            factory.ConfigureServices(services =>
            {
                services.AddControllers()
                .AddApplicationPart(typeof(GitHubHookController).Assembly)
                .AddGitHubWebHooks();
                services.Configure <TeamMentionForwardingOptions>(o =>
                {
                    o.IgnoreRepos     = new [] { IgnoredRepo };
                    o.WatchedTeam     = WatchedTeam;
                    o.TeamsWebHookUri = TestTeamsWebHookUri;
                });
                services.AddScoped <ITeamMentionForwarder, TeamMentionForwarder>();
                services.AddSingleton <Microsoft.Extensions.Internal.ISystemClock, TestClock>();
                services.AddLogging();
                services.AddSingleton <IHttpClientFactory>(mockClientFactory);

                services.AddSingleton(Mock.Of <IGitHubApplicationClientFactory>());
                services.AddSingleton(Mock.Of <ITimelineIssueTriage>());


                services.RemoveAll <GitHubVerifySignatureFilter>();
                services.AddSingleton <TestVerifySignatureFilter>();
                services.Configure <MvcOptions>(o =>
                {
                    o.Filters.Remove(o.Filters.OfType <ServiceFilterAttribute>()
                                     .First(f => f.ServiceType == typeof(GitHubVerifySignatureFilter)));
                    o.Filters.AddService <TestVerifySignatureFilter>();
                });
            });
            factory.ConfigureBuilder(app =>
            {
                app.Use(async(context, next) =>
                {
                    await next();
                });
                app.UseRouting();
                app.UseEndpoints(e => e.MapControllers());
            });

            if (expectNotification)
            {
                mockClientFactory.AddCannedResponse(TestTeamsWebHookUri, null, HttpStatusCode.NoContent, null, HttpMethod.Post);
            }

            return(new TestData(factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                BaseAddress = new Uri("https://example.test", UriKind.Absolute),
                AllowAutoRedirect = false,
            }), factory, mockClientFactory));
        }
        public async Task GettingAllIndividuals_GetsAllIndividuals()
        {
            // Arrange
            var client = _appFactory.CreateClient();

            // Act
            var response = await client.GetAsync("api/individuals");

            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299
            var json = await response.Content.ReadAsStringAsync();

            var individuals = JsonConvert.DeserializeObject <List <IndividualDto> >(json);

            Assert.AreNotEqual(0, individuals.Count);
        }
示例#5
0
        public async Task Can_Get_Planets()
        {
            var response = await _factory.CreateClient().GetAsync("/planets");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var actual = _factory.DeserializeResponse <List <Planet> >(response);

            Assert.NotNull(actual);
            Assert.NotEmpty(actual);
        }
            public TestData()
            {
                var factory = new TestAppFactory();

                factory.ConfigureServices(services =>
                {
                    services.AddControllers()
                    .AddApplicationPart(typeof(AnnotationsController).Assembly);

                    services.Configure <GrafanaOptions>(options =>
                    {
                        options.TableUri = "https://127.0.0.1:10002/devstoreaccount1/deployments";
                    });

                    services.AddLogging();
                });
                factory.ConfigureBuilder(app =>
                {
                    app.UseRouting();
                    app.UseEndpoints(e => e.MapControllers());
                });

                Client = factory.CreateClient();
            }