示例#1
0
            public async Task EnsuresArgumentsNotNull()
            {
                var releasesClient = new ReleasesClient(Substitute.For <IApiConnection>());

                var release    = new Release("https://uploads.github.com/anything");
                var uploadData = new ReleaseAssetUpload("good", "good/good", Stream.Null, null);
                await Assert.ThrowsAsync <ArgumentNullException>(() => releasesClient.UploadAsset(null, uploadData));

                await Assert.ThrowsAsync <ArgumentNullException>(() => releasesClient.UploadAsset(release, null));
            }
示例#2
0
            public async Task EnsuresArgumentsNotNull()
            {
                var releasesClient = new ReleasesClient(Substitute.For <IApiConnection>());

                var release = new Release {
                    UploadUrl = "https://uploads.github.com/anything"
                };
                var uploadData = new ReleaseAssetUpload {
                    FileName = "good", ContentType = "good/good", RawData = Stream.Null
                };
                await AssertEx.Throws <ArgumentNullException>(async() => await releasesClient.UploadAsset(null, uploadData));

                await AssertEx.Throws <ArgumentNullException>(async() => await releasesClient.UploadAsset(release, null));
            }
示例#3
0
            public async Task OverrideDefaultTimeout()
            {
                var newTimeout = TimeSpan.FromSeconds(100);

                var apiConnection = Substitute.For <IApiConnection>();

                var fixture = new ReleasesClient(apiConnection);

                var release    = new Release("https://uploads.github.com/anything");
                var uploadData = new ReleaseAssetUpload("good", "good/good", Stream.Null, newTimeout);

                await fixture.UploadAsset(release, uploadData);

                apiConnection.Received().Post <ReleaseAsset>(Arg.Any <Uri>(), uploadData.RawData, Arg.Any <string>(), uploadData.ContentType, newTimeout);
            }
示例#4
0
            public async Task UploadsToCorrectUrl()
            {
                var client         = Substitute.For <IApiConnection>();
                var releasesClient = new ReleasesClient(client);
                var release        = new Release("https://uploads.test.dev/does/not/matter/releases/1/assets{?name}");
                var rawData        = Substitute.For <Stream>();
                var upload         = new ReleaseAssetUpload("example.zip", "application/zip", rawData, null);

                await releasesClient.UploadAsset(release, upload);

                client.Received().Post <ReleaseAsset>(
                    Arg.Is <Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
                    rawData,
                    "application/vnd.github.v3",
                    Arg.Is <string>(contentType => contentType == "application/zip"));
            }
            public void UploadsToCorrectUrl()
            {
                var client = Substitute.For<IApiConnection>();
                var releasesClient = new ReleasesClient(client);
                var release = new Release { UploadUrl = "https://uploads.test.dev/does/not/matter/releases/1/assets{?name}" };
                var rawData = Substitute.For<Stream>();
                var upload = new ReleaseAssetUpload { FileName = "example.zip", ContentType = "application/zip", RawData = rawData };

                releasesClient.UploadAsset(release, upload);

                client.Received().Post<ReleaseAsset>(
                    Arg.Is<Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
                    rawData,
                    "application/vnd.github.v3",
                    Arg.Is<string>(contentType => contentType == "application/zip"));
            }
示例#6
0
            public async Task CanBeCancelled()
            {
                var httpClient    = new CancellationTestHttpClient();
                var connection    = new Connection(new ProductHeaderValue("TEST"), httpClient);
                var apiConnection = new ApiConnection(connection);

                var fixture = new ReleasesClient(apiConnection);

                var release    = new Release("https://uploads.github.com/anything");
                var uploadData = new ReleaseAssetUpload("good", "good/good", Stream.Null, null);

                using (var cts = new CancellationTokenSource())
                {
                    var uploadTask = fixture.UploadAsset(release, uploadData, cts.Token);

                    cts.Cancel();

                    await Assert.ThrowsAsync <TaskCanceledException>(() => uploadTask);
                }
            }
            public void UploadsToCorrectUrl()
            {
                var client         = Substitute.For <IApiConnection>();
                var releasesClient = new ReleasesClient(client);
                var release        = new Release {
                    UploadUrl = "https://uploads.test.dev/does/not/matter/releases/1/assets{?name}"
                };
                var rawData = Substitute.For <Stream>();
                var upload  = new ReleaseAssetUpload {
                    FileName = "example.zip", ContentType = "application/zip", RawData = rawData
                };

                releasesClient.UploadAsset(release, upload);

                client.Received().Post <ReleaseAsset>(
                    Arg.Is <Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
                    rawData,
                    "application/vnd.github.manifold-preview",
                    Arg.Is <string>(contentType => contentType == "application/zip"));
            }
            public async Task OverrideDefaultTimeout()
            {
                var newTimeout = TimeSpan.FromSeconds(100);

                var apiConnection = Substitute.For<IApiConnection>();

                var fixture = new ReleasesClient(apiConnection);

                var release = new Release("https://uploads.github.com/anything");
                var uploadData = new ReleaseAssetUpload("good", "good/good", Stream.Null, newTimeout);

                await fixture.UploadAsset(release, uploadData);

                apiConnection.Received().Post<ReleaseAsset>(Arg.Any<Uri>(), uploadData.RawData, Arg.Any<string>(), uploadData.ContentType, newTimeout);
            }
            public async Task EnsuresNonNullArguments()
            {
                var releasesClient = new ReleasesClient(Substitute.For<IApiConnection>());

                var release = new Release("https://uploads.github.com/anything");
                var uploadData = new ReleaseAssetUpload("good", "good/good", Stream.Null, null);

                await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.UploadAsset(null, uploadData));
                await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.UploadAsset(release, null));
            }
示例#10
0
            public async Task EnsuresArgumentsNotNull()
            {
                var releasesClient = new ReleasesClient(Substitute.For<IApiConnection>());

                var release = new Release { UploadUrl = "https://uploads.github.com/anything" };
                var uploadData = new ReleaseAssetUpload { FileName = "good", ContentType = "good/good", RawData = Stream.Null };
                await AssertEx.Throws<ArgumentNullException>(async () => await releasesClient.UploadAsset(null, uploadData));
                await AssertEx.Throws<ArgumentNullException>(async () => await releasesClient.UploadAsset(release, null));
            }