Esempio n. 1
0
        public void Should_Push_New_Asset_With_Put_Under_5MB(string assetUri)
        {
            _server.Stub(x => x.Put(assetUri))
            .OK();

            var asset    = new ProGetAssetPusher(_log, _config);
            var tempFile = new FilePath($"{Path.GetTempPath()}{Path.GetRandomFileName()}");

            using (var fileStream = new FileStream(tempFile.FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                fileStream.SetLength(4194304);
            }
            var result = Record.Exception(() => asset.Publish(tempFile, $"{Host}{assetUri}"));

            File.Delete(tempFile.FullPath);
            Assert.Null(result);
        }
Esempio n. 2
0
        public void Should_Throw_Exception_When_Asset_Push_Fails_As_Put(string assetUri)
        {
            _server.Stub(x => x.Put(assetUri))
            .WithStatus(HttpStatusCode.BadRequest);

            var asset    = new ProGetAssetPusher(_log, _config);
            var tempFile = new FilePath($"{Path.GetTempPath()}{Path.GetRandomFileName()}");

            using (var fileStream = new FileStream(tempFile.FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                fileStream.SetLength(4194304);
            }
            var result = Record.Exception(() => asset.Publish(tempFile, $"{Host}{assetUri}"));

            File.Delete(tempFile.FullPath);
            Assert.IsCakeException(result, "Upload failed. This request would have overwritten an existing package.");
        }
        public void Should_Push_New_Asset_With_Multipart_Post_Over_5MB(string assetUri)
        {
            using (var server = FluentMockServer.Start())
            {
                server.Given(Request.Create().WithPath(assetUri).UsingPost())
                .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));

                var asset    = new ProGetAssetPusher(_log, _config);
                var tempFile = new FilePath($"{Path.GetTempPath()}{Path.GetRandomFileName()}");
                using (var fileStream = new FileStream(tempFile.FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                {
                    fileStream.SetLength(6291456);
                }
                var result = Record.Exception(() => asset.Publish(tempFile, $"http://localhost:{server.Ports[0]}{assetUri}"));
                File.Delete(tempFile.FullPath);
                Assert.Null(result);
            }
        }
        public void Should_Throw_Exception_When_Asset_Push_Fails_As_Put(string assetUri)
        {
            using (var server = FluentMockServer.Start())
            {
                server.Given(Request.Create().WithPath(assetUri).UsingPut())
                .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.BadRequest));

                var asset    = new ProGetAssetPusher(_log, _config);
                var tempFile = new FilePath($"{Path.GetTempPath()}Should_Throw_Exception_When_Asset_Push_Fails_As_Put.txt");

                if (File.Exists(tempFile.FullPath))
                {
                    File.Delete(tempFile.FullPath);
                }

                using (var fileStream = new FileStream(tempFile.FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                {
                    fileStream.SetLength(4194304);
                }
                var result = Record.Exception(() => asset.Publish(tempFile, $"http://localhost:{server.Ports[0]}{assetUri}"));

                ExtraAssert.IsCakeException(result, "Upload failed. This request would have overwritten an existing package.");
            }
        }