Example #1
0
        public async Task GetBlobAsync_ValidatesArguments_Async()
        {
            var client = new ImageRegistryClient(new HttpClient());
            await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetBlobAsync(null, string.Empty, default)).ConfigureAwait(false);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetBlobAsync(string.Empty, null, default)).ConfigureAwait(false);
        }
Example #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);
        }
Example #3
0
        public async Task GetBlobAsync_ThrowsOnError_Async()
        {
            var handler = new MockHttpMessageHandler();

            handler
            .When(HttpMethod.Get, "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.GetBlobAsync("registry", "sha:0", default)).ConfigureAwait(false);

            handler.VerifyNoOutstandingExpectation();
        }
Example #4
0
        public async Task GetBlobAsync_Works_Async()
        {
            var handler = new MockHttpMessageHandler();

            using (MemoryStream content = new MemoryStream())
            {
                handler
                .Expect(HttpMethod.Get, "http://localhost:5000/v2/registry/blobs/sha:0")
                .Respond(HttpStatusCode.OK, new StreamContent(content));

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

                var client = new ImageRegistryClient(httpClient);

                var result = await client.GetBlobAsync("registry", "sha:0", default).ConfigureAwait(false);

                Assert.NotNull(result);
            }

            handler.VerifyNoOutstandingExpectation();
        }