public async Task UniqueClient_UpdatesUniqueWithoutExisting() { // Arrange using (var tc = new TestContext()) { // Act var actual = await tc.Target.UploadAsync(tc.UniqueUploadRequest); // Assert await tc.VerifyContentAsync(actual.DirectUri); await tc.VerifyContentAsync(actual.LatestUri); } }
public async Task UniqueClient_UpdatesUniqueWithExisting() { // Arrange using (var tc = new TestContext()) { tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes("oldContent")); await tc.Target.UploadAsync(tc.UniqueUploadRequest); tc.UtcNow = tc.UtcNow.AddMinutes(1); tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); // Act var actual = await tc.Target.UploadAsync(tc.UniqueUploadRequest); // Assert await tc.VerifyContentAsync(actual.DirectUri); await tc.VerifyContentAsync(actual.LatestUri); } }
public async Task UniqueClient_DoesNotOverwriteDirectTimestamp() { // Arrange using (var tc = new TestContext()) { tc.UniqueUploadRequest.Type = UploadRequestType.Timestamp; tc.Content = "content"; tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); var uploadResult = await tc.Target.UploadAsync(tc.UniqueUploadRequest); tc.Content = "newerContent"; tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); // Act & Assert var exception = await Assert.ThrowsAsync<StorageException>(() => tc.Target.UploadAsync(tc.UniqueUploadRequest)); Assert.Equal(409, exception.RequestInformation.HttpStatusCode); await tc.VerifyContentAsync(uploadResult.DirectUri, "content"); await tc.VerifyContentAsync(uploadResult.LatestUri, "content"); } }
public async Task CanUploadToDirectAndLatestWithLongOptions() { // Arrange using (var tc = new TestContext(_output)) { // Act var actual = tc.ExecuteCommand( new[] { "--connection-string", tc.ConnectionString, "--container", tc.Container, "--path-format", tc.PathFormat }, tc.Content); // Assert await tc.VerifyContentAsync(actual, direct: true, latest: true); } }
public async Task Client_DoesNotOverwriteExistingDirectBlob() { // Arrange using (var tc = new TestContext()) { tc.Content = "[1, 2]"; tc.UploadRequest.ContentType = "application/json"; tc.UploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); var uploadResult = await tc.Target.UploadAsync(tc.UploadRequest); tc.UploadRequest.ContentType = "text/plain"; tc.UploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes("foobar")); tc.UploadRequest.ETag = uploadResult.LatestETag; // Act & Assert var exception = await Assert.ThrowsAsync<StorageException>(() => tc.Target.UploadAsync(tc.UploadRequest)); Assert.Equal(409, exception.RequestInformation.HttpStatusCode); tc.UploadRequest.ContentType = "application/json"; await tc.VerifyContentAsync(uploadResult.LatestUri); } }
public async Task HasDefaultPathFormat() { // Arrange using (var tc = new TestContext(_output)) { var minTimestamp = DateTimeOffset.UtcNow; // Act var actual = tc.ExecuteCommand( new[] { "-s", tc.ConnectionString, "-c", tc.Container }, tc.Content); // Assert var maxTimestamp = DateTimeOffset.UtcNow; var result = await tc.VerifyContentAsync(actual, direct: true, latest: true); var directFileName = result.DirectUri.ToString().Split('/').Last(); Assert.EndsWith(".txt", directFileName); var unparsedTimestamp = directFileName.Substring(0, directFileName.Length - ".txt".Length); var timestampLocal = DateTime.ParseExact(unparsedTimestamp, "yyyy.MM.dd.HH.mm.ss.fffffff", CultureInfo.InvariantCulture); var timestamp = new DateTimeOffset(timestampLocal, TimeSpan.Zero); Assert.True(timestamp >= minTimestamp, "The timestamp should be greater than or equal to the minimum."); Assert.True(timestamp <= maxTimestamp, "The timestamp should be less than or equal to the maximum."); Assert.EndsWith("/latest.txt", result.LatestUri.ToString()); } }
public async Task AllowsBothDirectAndLatestUploadToBeDisabled() { // Arrange using (var tc = new TestContext(_output)) { // Act var actual = tc.ExecuteCommand( new[] { "-s", tc.ConnectionString, "-c", tc.Container, "-f", tc.PathFormat, "--no-direct", "--no-latest" }, tc.Content); // Assert await tc.VerifyContentAsync(actual, direct: false, latest: false); } }
public async Task CanSetContentTypeWithLongOptions() { // Arrange using (var tc = new TestContext(_output)) { tc.Content = "{\"foo\": 5}"; tc.ContentType = "application/json"; // Act var actual = tc.ExecuteCommand( new[] { "--connection-string", tc.ConnectionString, "--container", tc.Container, "--path-format", tc.PathFormat, "--content-type", tc.ContentType }, tc.Content); // Assert await tc.VerifyContentAsync(actual, direct: true, latest: true); } }
public async Task CanUploadOnlyLatestWithUniqueOnlyOption() { // Arrange using (var tc = new TestContext(_output)) { tc.Content = "something"; var initial = tc.ExecuteCommand( new[] { "-s", tc.ConnectionString, "-c", tc.Container, "-f", tc.PathFormat, "--no-direct" }, tc.Content); tc.Content = "something else"; // Act var actual = tc.ExecuteCommand( new[] { "--connection-string", tc.ConnectionString, "--container", tc.Container, "--path-format", tc.PathFormat, "--no-direct", "--only-unique" }, tc.Content); // Assert await tc.VerifyContentAsync(actual, direct: false, latest: true); Assert.Contains("Gettings the existing latest... different! The provided content will be uploaded.", actual.Output); } }
public async Task UniqueClient_AllowsNullEqualsAsync() { // Arrange using (var tc = new TestContext()) { tc.Content = "a1"; tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); await tc.Target.UploadAsync(tc.UniqueUploadRequest); tc.UtcNow = tc.UtcNow.AddMinutes(1); tc.Content = "a2"; tc.UniqueUploadRequest.Stream = new MemoryStream(Encoding.UTF8.GetBytes(tc.Content)); tc.UniqueUploadRequest.EqualsAsync = null; // Act var actual = await tc.Target.UploadAsync(tc.UniqueUploadRequest); // Assert await tc.VerifyContentAsync(actual.DirectUri); await tc.VerifyContentAsync(actual.LatestUri); } }