Skip to content

Commit

Permalink
add compatibility matrix deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Sep 18, 2024
1 parent 52952e4 commit ca4ee7b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/GregClient/Requests/PackageUploadRequestBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ public PackageUploadRequestBody(string name, string version, string description,
string metadata, string group, IEnumerable<PackageDependency> dependencies,
string siteUrl, string repositoryUrl, bool containsBinaries,
IEnumerable<string> nodeLibraryNames, IEnumerable<string> hostDependencies,
string copyright_holder, string copyright_year, string releaseNotesUrl)
string copyright_holder, string copyright_year, string releaseNotesUrl, IEnumerable<PackageCompatibility> compatibilityMatrix)
{
this.host_dependencies = hostDependencies;
this.copyright_holder = copyright_holder;
this.copyright_year = copyright_year;
this.release_notes_url = releaseNotesUrl;
this.compatibility_matrix = compatibilityMatrix;

this.name = name;
this.version = version;
Expand Down
14 changes: 14 additions & 0 deletions src/GregClient/Requests/PackageVersionUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,18 @@ public PackageDependency(string name, string version)
public string name { get; set; }
public string version { get; set; }
}
public class PackageCompatibility
{
public PackageCompatibility(string name, List<string> versions, string min, string max)
{
this.name = name;
this.versions = versions;
this.min = min;
this.max = max;
}
public string name { get; set; }
public List<string> versions { get; set; }
public string min { get; set; }
public string max { get; set; }
}
}
5 changes: 3 additions & 2 deletions src/GregClient/Requests/PackageVersionUploadRequestBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PackageVersionUploadRequestBody(string name, string version, string descr
string metadata, string group, IEnumerable<PackageDependency> dependencies,
string siteUrl, string repositoryUrl, bool containsBinaries,
IEnumerable<string> nodeLibraryNames, IEnumerable<string> hostDependencies,
string copyright_holder, string copyright_year, string compatibility_matrix, string releaseNotesUrl)
string copyright_holder, string copyright_year, IEnumerable<PackageCompatibility> compatibilityMatrix, string releaseNotesUrl)

{
this.host_dependencies = hostDependencies;
Expand All @@ -60,6 +60,7 @@ public PackageVersionUploadRequestBody(string name, string version, string descr
this.node_libraries = nodeLibraryNames;
this.compatibility_matrix = compatibility_matrix;
this.release_notes_url = releaseNotesUrl;
this.compatibility_matrix = compatibilityMatrix;
}

/// <summary>
Expand Down Expand Up @@ -132,7 +133,7 @@ public PackageVersionUploadRequestBody(string name, string version, string descr
public IEnumerable<string> node_libraries { get; set; }
public string copyright_holder { get; set; }
public string copyright_year { get; set; }
public string compatibility_matrix { get; set; }
public IEnumerable<PackageCompatibility> compatibility_matrix { get; set; }
public string release_notes_url { get; set; }
}
}
9 changes: 8 additions & 1 deletion src/GregClient/Responses/Responses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using RestSharp;
using Greg.Converters;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Greg.Responses
{
Expand Down Expand Up @@ -78,6 +77,13 @@ public class Dependency

public string _id { get; set; }
}
public class Compatibility
{
public string name { get; set; }
public List<string> versions { get; set; }
public string min { get; set; }
public string max { get; set; }
}

public class PackageVersion
{
Expand Down Expand Up @@ -125,6 +131,7 @@ public class PackageVersion

public string size { get; set; }
public string release_notes_url { get; set; }
public List<Compatibility> compatibility_matrix { get; set; }
}

public class User
Expand Down
43 changes: 37 additions & 6 deletions src/GregClientTests/GregClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void UploadDynamoPackageVersionTest()
var keywords = new List<string>() { "neat", "ok" };
var nv = new PackageVersionUploadRequestBody("Third .NET Package", "2.1.0", "", keywords, "contents", "dynamo", "0.1.0", "metadata", "group",
new List<PackageDependency>() { new PackageDependency("peter", "0.1.0"), new PackageDependency("stephen", "0.1.0") }, "", "",
false, new List<String>(), new List<String>(), "Dynamo Team", "2021","","");
false, new List<String>(), new List<String>(), "Dynamo Team", "2021",null,"");

var files = new List<string>() { "../test/pedro.dyf", "../test/RootNode.dyf" };
var request = new PackageVersionUpload(nv, files);
Assert.That(request.RequestBody.AsJson().Equals("{\"file_hash\":null,\"name\":\"Third .NET Package\",\"version\":\"2.1.0\",\"description\":\"\",\"group\":\"group\",\"keywords\":[\"neat\",\"ok\"],\"dependencies\":[{\"name\":\"peter\",\"version\":\"0.1.0\"},{\"name\":\"stephen\",\"version\":\"0.1.0\"}],\"host_dependencies\":[],\"contents\":\"contents\",\"engine_version\":\"0.1.0\",\"engine\":\"dynamo\",\"engine_metadata\":\"metadata\",\"site_url\":\"\",\"repository_url\":\"\",\"contains_binaries\":false,\"node_libraries\":[],\"copyright_holder\":\"Dynamo Team\",\"copyright_year\":\"2021\",\"compatibility_matrix\":\"\",\"release_notes_url\":\"\"}"));
Assert.That(request.RequestBody.AsJson().Equals("{\"file_hash\":null,\"name\":\"Third .NET Package\",\"version\":\"2.1.0\",\"description\":\"\",\"group\":\"group\",\"keywords\":[\"neat\",\"ok\"],\"dependencies\":[{\"name\":\"peter\",\"version\":\"0.1.0\"},{\"name\":\"stephen\",\"version\":\"0.1.0\"}],\"host_dependencies\":[],\"contents\":\"contents\",\"engine_version\":\"0.1.0\",\"engine\":\"dynamo\",\"engine_metadata\":\"metadata\",\"site_url\":\"\",\"repository_url\":\"\",\"contains_binaries\":false,\"node_libraries\":[],\"copyright_holder\":\"Dynamo Team\",\"copyright_year\":\"2021\",\"compatibility_matrix\":null,\"release_notes_url\":\"\"}"));
Console.WriteLine(request.RequestBody.AsJson());
}

Expand All @@ -70,11 +70,11 @@ public void UploadDynamoPackageWithHostDependencyTest()
var keywords = new List<string>() { "Civil" };
var nv = new PackageVersionUploadRequestBody("Third .NET Package", "2.1.0", "", keywords, "contents", "dynamo", "0.1.0", "metadata", "group",
new List<PackageDependency>() { new PackageDependency("Ram", "0.1.0"), new PackageDependency("Ian", "0.1.0") }, "", "",
false, new List<String>(), new List<String>() { "Civil3D" }, "Dynamo Team", "2021", "", "");
false, new List<String>(), new List<String>() { "Civil3D" }, "Dynamo Team", "2021", null, "");

var files = new List<string>() { "../test/pedro.dyf", "../test/RootNode.dyf" };
var request = new PackageVersionUpload(nv, files);
Assert.That(request.RequestBody.AsJson().Equals("{\"file_hash\":null,\"name\":\"Third .NET Package\",\"version\":\"2.1.0\",\"description\":\"\",\"group\":\"group\",\"keywords\":[\"Civil\"],\"dependencies\":[{\"name\":\"Ram\",\"version\":\"0.1.0\"},{\"name\":\"Ian\",\"version\":\"0.1.0\"}],\"host_dependencies\":[\"Civil3D\"],\"contents\":\"contents\",\"engine_version\":\"0.1.0\",\"engine\":\"dynamo\",\"engine_metadata\":\"metadata\",\"site_url\":\"\",\"repository_url\":\"\",\"contains_binaries\":false,\"node_libraries\":[],\"copyright_holder\":\"Dynamo Team\",\"copyright_year\":\"2021\",\"compatibility_matrix\":\"\",\"release_notes_url\":\"\"}"));
Assert.That(request.RequestBody.AsJson().Equals("{\"file_hash\":null,\"name\":\"Third .NET Package\",\"version\":\"2.1.0\",\"description\":\"\",\"group\":\"group\",\"keywords\":[\"Civil\"],\"dependencies\":[{\"name\":\"Ram\",\"version\":\"0.1.0\"},{\"name\":\"Ian\",\"version\":\"0.1.0\"}],\"host_dependencies\":[\"Civil3D\"],\"contents\":\"contents\",\"engine_version\":\"0.1.0\",\"engine\":\"dynamo\",\"engine_metadata\":\"metadata\",\"site_url\":\"\",\"repository_url\":\"\",\"contains_binaries\":false,\"node_libraries\":[],\"copyright_holder\":\"Dynamo Team\",\"copyright_year\":\"2021\",\"compatibility_matrix\":null,\"release_notes_url\":\"\"}"));
Console.WriteLine(request.RequestBody.AsJson());
}

Expand All @@ -83,7 +83,7 @@ public void UploadDynamoPackageVersionWithFilesTest()
{
var keywords = new List<string>() { "neat", "ok" };
var nv = new PackageVersionUploadRequestBody("Third .NET Package", "2.1.0", "", keywords, "contents", "dynamo", "0.1.0", "metadata", "group",
new List<PackageDependency>() { new PackageDependency("peter", "0.1.0"), new PackageDependency("stephen", "0.1.0") }, "", "", false, new List<String>(), new List<String>(), "", "", "", "");
new List<PackageDependency>() { new PackageDependency("peter", "0.1.0"), new PackageDependency("stephen", "0.1.0") }, "", "", false, new List<String>(), new List<String>(), "", "", null, "");

var files = new List<string>() {Assembly.GetExecutingAssembly().Location };

Expand Down Expand Up @@ -160,6 +160,37 @@ public void ListHostsTest()
Console.WriteLine(JsonSerializer.Serialize(hostsResponse.content));
Assert.That(hostsResponse.content.Count, Is.EqualTo(5));
}


[Test]

public void TestCompatibilityDeserializationTest()
{
var mockResponse= @"[
{
""name"" : ""dynamo"",
""versions"" : [""2.17"",""2.18""],
""min"" : ""2.17"",
""max"" : ""3.0""
},
{
""name"" : ""revit"",
""versions"" : [""2024"",""2025""],
""min"" : ""2025""
},
{
""name"" : ""civil3d"",
""min"" : ""2025"",
""max"" : ""2024""
},
{
""name"" : "".net"",
""max"" : ""net8""
}
]";
var cm = JsonSerializer.Deserialize<List<PackageCompatibility>>(mockResponse);
Assert.That(cm, !Is.Null);
Assert.That(cm, Has.Count.EqualTo(4));
}

}
}

0 comments on commit ca4ee7b

Please sign in to comment.