Esempio n. 1
0
        public async Task DeleteBlobAsync_ValidatesArguments_Async()
        {
            var client = new ImageRegistryClient(new HttpClient());
            await Assert.ThrowsAsync <ArgumentNullException>(() => client.DeleteBlobAsync(null, string.Empty, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.DeleteBlobAsync(string.Empty, null, default)).ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task Dispose_Works_Async()
        {
            var httpClient = new HttpClient();
            var client     = new ImageRegistryClient(httpClient);

            Assert.False(client.IsDisposed);

            client.Dispose();

            Assert.Throws <ObjectDisposedException>(() => httpClient.BaseAddress = new Uri("http://localhost:5000"));
            Assert.True(client.IsDisposed);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.DeleteBlobAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.DeleteManifestAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.GetBlobAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.GetManifestAsync(null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.ListTagsAsync(null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.PushBlobAsync(null, null, null, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ObjectDisposedException>(() => client.PushManifestAsync(null, null, null, default)).ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task DeleteBlobAsync_ThrowsOnError_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .When(HttpMethod.Delete, "http://localhost:5000/v2/registry/blobs/sha:0")
            .Respond(HttpStatusCode.NotFound);

            var httpClient = handler.ToHttpClient();

            httpClient.BaseAddress = new Uri("http://localhost:5000");

            var client = new ImageRegistryClient(httpClient);

            await Assert.ThrowsAsync <ImageRegistryException>(() => client.DeleteBlobAsync("registry", "sha:0", default)).ConfigureAwait(false);
        }
Esempio n. 4
0
        public async Task DeleteBlobAsync_Works_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .Expect(HttpMethod.Delete, "http://localhost:5000/v2/registry/blobs/sha:0")
            .Respond(HttpStatusCode.OK);

            var httpClient = handler.ToHttpClient();

            httpClient.BaseAddress = new Uri("http://localhost:5000");

            var client = new ImageRegistryClient(httpClient);

            // Should not throw
            await client.DeleteBlobAsync("registry", "sha:0", default).ConfigureAwait(false);

            handler.VerifyNoOutstandingExpectation();
        }