コード例 #1
0
        public async Task GivenKnownKey_WhenAuditingPackages_ThenAddsProjectToTenant()
        {
            StateUnderTestBuilder builder = new StateUnderTestBuilder(_client);

            var context = await builder.WithUser(true, "anyTenant", $"{Guid.NewGuid()}")
                          .WithKey("anyKey", "anyTenant")
                          .Build();

            _client.DefaultRequestHeaders.Add("X-API-KEY", $"{context.Keys[0].Value}");

            await _client.PostAsJsonAsync("/api/packages",
                                          new AuditRequest
            {
                Project  = "anyProject",
                Version  = "anyVersion",
                Packages = new[] { new ProjectPackages {
                                       Name = "FluentValidation", Version = "1.0.1"
                                   } }
            });

            var tenantJson = await _client.GetStringAsync($"/api/tenants?name=anyTenant");

            var tenant = JsonConvert.DeserializeObject <TenantOverview>(tenantJson);

            tenant.Projects.First().Name.Should().Be("anyProject");
            tenant.Projects.First().Version.Should().Be("anyVersion");
        }
コード例 #2
0
        public async Task GivenUnknownKey_WhenAuditingPackages_ThenReturns401()
        {
            _client.DefaultRequestHeaders.Add("X-API-KEY", $"{Guid.NewGuid()}");

            StateUnderTestBuilder builder = new StateUnderTestBuilder(_client);

            var context = await builder.WithUser(true, "anyTenant", $"{Guid.NewGuid()}")
                          .Build();

            var response = await _client.PostAsJsonAsync("/api/packages",
                                                         new AuditRequest
            {
                Packages = new[] { new ProjectPackages {
                                       Name = "FluentValidation", Version = "1.0.1"
                                   } }
            });

            await response.Content.ReadAsAsync <AuditResponse>();

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
        }