Skip to content

Commit

Permalink
feat: add version_number to BoxFileVersion (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored May 11, 2022
1 parent 8415bd3 commit f174358
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Box.V2.Test.Integration/BoxFilesManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ public async Task UploadNewVersionOfBigFileInSession_ShouldUploadNewVersionOfFil
Assert.AreNotEqual(file.FileVersion.Id, response.FileVersion.Id);
}

[TestMethod]
public async Task ViewVersions_ShouldReturnCorrectVersionNumber_WhenFileVersionIsChangedByUpload()
{
var file = await CreateSmallFile();
await CreateNewFileVersion(file.Id);

var response = await UserClient.FilesManager.ViewVersionsAsync(file.Id, new List<string>() { BoxFileVersion.FieldVersionNumber });

Assert.AreEqual("1", response.Entries[0].VersionNumber);

await CreateNewFileVersion(file.Id);

response = await UserClient.FilesManager.ViewVersionsAsync(file.Id, new List<string>() { BoxFileVersion.FieldVersionNumber });

Assert.AreEqual("2", response.Entries[0].VersionNumber);
}

private int GetNumberOfParts(long totalSize, long partSize)
{
if (partSize == 0)
Expand Down
13 changes: 13 additions & 0 deletions Box.V2.Test.Integration/Configuration/Commands/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ public interface ICleanupCommand : ICommand
/// <returns></returns>
Task Execute(IBoxClient client);
}

/// <summary>
/// Interface used to create a resource. It does not perform a remove/dispose action. Used in cases such as new file version upload.
/// </summary>
public interface INonDisposableCommand : ICommand
{
/// <summary>
/// Creates resources required for the test. Returns the identifier of the resource.
/// </summary>
/// <param name="client">Box Client</param>
/// <returns>Resource Id</returns>
Task<string> Execute(IBoxClient client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.IO;
using System.Threading.Tasks;
using Box.V2.Models;

namespace Box.V2.Test.Integration.Configuration.Commands.DisposableCommands
{
public class CreateNewFileVersion : CommandBase, INonDisposableCommand
{
private readonly string _fileName;
private readonly string _filePath;
private readonly string _fileId;

public string FileId;
public BoxFile File;

public CreateNewFileVersion(string fileName, string filePath, string fileId, CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User) : base(scope, accessLevel)
{
_fileName = fileName;
_filePath = filePath;
_fileId = fileId;
}

public async Task<string> Execute(IBoxClient client)
{
using (var fileStream = new FileStream(_filePath, FileMode.OpenOrCreate))
{
var response = await client.FilesManager.UploadNewVersionAsync(_fileName, _fileId, fileStream);
File = response;
FileId = File.Id;
return FileId;
}
}
}
}
13 changes: 13 additions & 0 deletions Box.V2.Test.Integration/Configuration/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public static async Task ExecuteCommand(ICleanupCommand command)
await command.Execute(client);
}

public static async Task ExecuteCommand(INonDisposableCommand command)
{
IBoxClient client = GetClient(command);
await command.Execute(client);
}

public static async Task<string> ExecuteCommand(IDisposableCommand command)
{
IBoxClient client = GetClient(command);
Expand Down Expand Up @@ -332,6 +338,13 @@ public static async Task<BoxCollaborationWhitelistTargetEntry> AddCollaborationE
return addCollaborationExemptCommand.WhitelistTargetEntry;
}

public static async Task<BoxFile> CreateNewFileVersion(string fileId)
{
var createNewFileVersionCommand = new CreateNewFileVersion(GetUniqueName("file"), GetSmallFilePath(), fileId);
await ExecuteCommand(createNewFileVersionCommand);
return createNewFileVersionCommand.File;
}

public static async Task Retry(Func<Task> action, int retries = 3, int sleep = 1000)
{
var retryCount = 0;
Expand Down
3 changes: 3 additions & 0 deletions Box.V2.Test/Box.V2.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<None Update="Fixtures\BoxFileRequest\GetFileRequest200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFiles\ViewVersions200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fixtures\BoxFiles\UploadNewVersionUsingSession200.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
6 changes: 3 additions & 3 deletions Box.V2.Test/BoxFilesManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,15 @@ public async Task UploadNewVersion_ValidResponse_ValidFile()
public async Task ViewVersions_ValidResponse_ValidFileVersions()
{
/*** Arrange ***/
var responseString = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file_version\", \"id\": \"672259576\", \"sha1\": \"359c6c1ed98081b9a69eb3513b9deced59c957f9\", \"name\": \"Dragons.js\", \"size\": 92556, \"created_at\": \"2012-08-20T10:20:30-07:00\", \"modified_at\": \"2012-11-28T13:14:58-08:00\", \"modified_by\": { \"type\": \"user\", \"id\": \"183732129\", \"name\": \"sean rose\", \"login\": \"[email protected]\" } } ] }";
Handler.Setup(h => h.ExecuteAsync<BoxCollection<BoxFileVersion>>(It.IsAny<IBoxRequest>()))
.Returns(Task.FromResult<IBoxResponse<BoxCollection<BoxFileVersion>>>(new BoxResponse<BoxCollection<BoxFileVersion>>()
{
Status = ResponseStatus.Success,
ContentString = responseString
ContentString = LoadFixtureFromJson("Fixtures/BoxFiles/ViewVersions200.json")
}));

/*** Act ***/
BoxCollection<BoxFileVersion> c = await _filesManager.ViewVersionsAsync("0");
BoxCollection<BoxFileVersion> c = await _filesManager.ViewVersionsAsync("0", new List<string>() { BoxFileVersion.FieldVersionNumber });

/*** Assert ***/
Assert.AreEqual(c.TotalCount, 1);
Expand All @@ -324,6 +323,7 @@ public async Task ViewVersions_ValidResponse_ValidFileVersions()
Assert.AreEqual("183732129", f.ModifiedBy.Id);
Assert.AreEqual("sean rose", f.ModifiedBy.Name);
Assert.AreEqual("[email protected]", f.ModifiedBy.Login);
Assert.AreEqual("1", f.VersionNumber);
}

[TestMethod]
Expand Down
21 changes: 21 additions & 0 deletions Box.V2.Test/Fixtures/BoxFiles/ViewVersions200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"total_count": 1,
"entries": [
{
"type": "file_version",
"id": "672259576",
"sha1": "359c6c1ed98081b9a69eb3513b9deced59c957f9",
"name": "Dragons.js",
"size": 92556,
"created_at": "2012-08-20T10:20:30-07:00",
"modified_at": "2012-11-28T13:14:58-08:00",
"modified_by": {
"type": "user",
"id": "183732129",
"name": "sean rose",
"login": "[email protected]"
},
"version_number" : "1"
}
]
}
7 changes: 7 additions & 0 deletions Box.V2/Models/BoxFileVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BoxFileVersion : BoxEntity
public const string FieldRestoredAt = "restored_at";
public const string FieldRestoredBy = "restored_by";
public const string FieldFileVersion = "file_version";
public const string FieldVersionNumber = "version_number";

/// <summary>
/// The sha1 hash of this file
Expand Down Expand Up @@ -102,5 +103,11 @@ public class BoxFileVersion : BoxEntity
/// </summary>
[JsonProperty(PropertyName = FieldFileVersion)]
public virtual BoxFileVersion FileVersion { get; private set; }

/// <summary>
/// The version number of the file version
/// </summary>
[JsonProperty(PropertyName = FieldVersionNumber)]
public virtual string VersionNumber { get; private set; }
}
}

0 comments on commit f174358

Please sign in to comment.