mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 21:09:51 +00:00
[FEAT]: Custom Properties (#2933)
* add custom properties model and clients * observable * observable tests * add search * error CS8370: 'target-typed object creation' * Error CS8370: 'target-typed object creation' * add patch with body that return status code * fixes for failed ConventionTests * working UnitTests * (de)serialization and model tests * Update Repository.cs
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class CustomPropertyValuesTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanBeDeserialized()
|
||||
{
|
||||
const string json = @"[
|
||||
{
|
||||
""property_name"": ""test_ms"",
|
||||
""value"": [
|
||||
""option_d"",
|
||||
""option_e""
|
||||
]
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_ss"",
|
||||
""value"": ""option_c""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_str"",
|
||||
""value"": ""hello""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_tf"",
|
||||
""value"": ""unset""
|
||||
}
|
||||
]
|
||||
";
|
||||
var serializer = new SimpleJsonSerializer();
|
||||
|
||||
var properties = serializer.Deserialize<IReadOnlyList<CustomPropertyValue>>(json);
|
||||
|
||||
Assert.NotNull(properties);
|
||||
Assert.Equal(4, properties.Count);
|
||||
|
||||
var testMs = properties[0];
|
||||
Assert.Equal("test_ms", testMs.PropertyName);
|
||||
Assert.Equal(new List<string> { "option_d", "option_e" }, testMs.Values);
|
||||
|
||||
var testSs = properties[1];
|
||||
Assert.Equal("test_ss", testSs.PropertyName);
|
||||
Assert.Equal("option_c", testSs.Value);
|
||||
Assert.Equal(new List<string> { "option_c" }, testSs.Values);
|
||||
|
||||
var testStr = properties[2];
|
||||
Assert.Equal("test_str", testStr.PropertyName);
|
||||
Assert.Equal("hello", testStr.Value);
|
||||
|
||||
var testTf = properties[3];
|
||||
Assert.Equal("test_tf", testTf.PropertyName);
|
||||
Assert.Equal("unset", testTf.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class CustomPropertyValueUpdateTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanSerializeMultiSelect()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_ms\"," +
|
||||
"\"value\":[\"option_d\",\"option_e\"]}";
|
||||
|
||||
|
||||
var update = new CustomPropertyValueUpdate("test_ms", new List<string> { "option_d", "option_e" });
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeSingleSelect()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_ss\"," +
|
||||
"\"value\":\"option_c\"}";
|
||||
|
||||
var update = new CustomPropertyValueUpdate("test_ss", "option_c");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeString()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_str\"," +
|
||||
"\"value\":\"hello\"}";
|
||||
|
||||
var update = new CustomPropertyValueUpdate("test_str", "hello");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeTrueFalse()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_tf\"," +
|
||||
"\"value\":\"true\"}";
|
||||
|
||||
var update = new CustomPropertyValueUpdate("test_tf", "true");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class OrganizationCustomPropertiesTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanBeDeserialized()
|
||||
{
|
||||
const string json = @"[
|
||||
{
|
||||
""property_name"": ""test_ms"",
|
||||
""value_type"": ""multi_select"",
|
||||
""required"": true,
|
||||
""default_value"": [
|
||||
""option_d"",
|
||||
""option_e""
|
||||
],
|
||||
""description"": ""multi_select property"",
|
||||
""allowed_values"": [
|
||||
""option_a"",
|
||||
""option_b"",
|
||||
""option_c"",
|
||||
""option_d"",
|
||||
""option_e""
|
||||
],
|
||||
""values_editable_by"": ""org_actors""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_ss"",
|
||||
""value_type"": ""single_select"",
|
||||
""required"": true,
|
||||
""default_value"": ""option_c"",
|
||||
""description"": ""single_select property"",
|
||||
""allowed_values"": [
|
||||
""option_a"",
|
||||
""option_b"",
|
||||
""option_c"",
|
||||
""option_d"",
|
||||
""option_e""
|
||||
],
|
||||
""values_editable_by"": ""org_actors""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_str"",
|
||||
""value_type"": ""string"",
|
||||
""required"": false,
|
||||
""description"": ""string property"",
|
||||
""values_editable_by"": ""org_actors""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_tf"",
|
||||
""value_type"": ""true_false"",
|
||||
""required"": true,
|
||||
""default_value"": ""unset"",
|
||||
""description"": ""true_false property"",
|
||||
""values_editable_by"": ""org_actors""
|
||||
}
|
||||
]
|
||||
";
|
||||
var serializer = new SimpleJsonSerializer();
|
||||
|
||||
var properties = serializer.Deserialize<IReadOnlyList<OrganizationCustomProperty>>(json);
|
||||
Assert.NotNull(properties);
|
||||
Assert.Equal(4, properties.Count);
|
||||
|
||||
var testMs = properties[0];
|
||||
Assert.Equal("test_ms", testMs.PropertyName);
|
||||
Assert.Equal(CustomPropertyValueType.MultiSelect, testMs.ValueType);
|
||||
Assert.True(testMs.Required);
|
||||
Assert.Equal(new List<string> { "option_d", "option_e" }, testMs.DefaultValues);
|
||||
Assert.Equal("multi_select property", testMs.Description);
|
||||
Assert.Equal(new List<string> { "option_a", "option_b", "option_c", "option_d", "option_e" }, testMs.AllowedValues);
|
||||
Assert.Equal(CustomPropertyValuesEditableBy.OrgActors, testMs.ValuesEditableBy);
|
||||
|
||||
var testSs = properties[1];
|
||||
Assert.Equal("test_ss", testSs.PropertyName);
|
||||
Assert.Equal(CustomPropertyValueType.SingleSelect, testSs.ValueType);
|
||||
Assert.True(testSs.Required);
|
||||
Assert.Equal("option_c", testSs.DefaultValue);
|
||||
Assert.Equal(new List<string> { "option_c" }, testSs.DefaultValues);
|
||||
Assert.Equal("single_select property", testSs.Description);
|
||||
Assert.Equal(new List<string> { "option_a", "option_b", "option_c", "option_d", "option_e" }, testSs.AllowedValues);
|
||||
Assert.Equal(CustomPropertyValuesEditableBy.OrgActors, testSs.ValuesEditableBy);
|
||||
|
||||
var testStr = properties[2];
|
||||
Assert.Equal("test_str", testStr.PropertyName);
|
||||
Assert.Equal(CustomPropertyValueType.String, testStr.ValueType);
|
||||
Assert.False(testStr.Required);
|
||||
Assert.Equal("string property", testStr.Description);
|
||||
Assert.Equal(CustomPropertyValuesEditableBy.OrgActors, testStr.ValuesEditableBy);
|
||||
|
||||
var testTf = properties[3];
|
||||
Assert.Equal("test_tf", testTf.PropertyName);
|
||||
Assert.Equal(CustomPropertyValueType.TrueFalse, testTf.ValueType);
|
||||
Assert.True(testTf.Required);
|
||||
Assert.Equal("unset", testTf.DefaultValue);
|
||||
Assert.Equal("true_false property", testTf.Description);
|
||||
Assert.Equal(CustomPropertyValuesEditableBy.OrgActors, testTf.ValuesEditableBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class OrganizationCustomPropertyUpdateTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanSerializeMultiSelect()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_ms\"," +
|
||||
"\"value_type\":\"multi_select\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":[\"option_d\",\"option_e\"]}";
|
||||
|
||||
|
||||
var update = new OrganizationCustomPropertyUpdate("test_ms", CustomPropertyValueType.MultiSelect, new List<string> { "option_d", "option_e" });
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeSingleSelect()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_ss\"," +
|
||||
"\"value_type\":\"single_select\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"option_c\"}";
|
||||
|
||||
var update = new OrganizationCustomPropertyUpdate("test_ss", CustomPropertyValueType.SingleSelect, "option_c");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeString()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_str\"," +
|
||||
"\"value_type\":\"string\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"hello\"}";
|
||||
|
||||
var update = new OrganizationCustomPropertyUpdate("test_str", CustomPropertyValueType.String, "hello");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeTrueFalse()
|
||||
{
|
||||
var expected = "{\"property_name\":\"test_tf\"," +
|
||||
"\"value_type\":\"true_false\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"true\"}";
|
||||
|
||||
var update = new OrganizationCustomPropertyUpdate("test_tf", CustomPropertyValueType.TrueFalse, "true");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class OrganizationCustomPropertyValuesTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanBeDeserialized()
|
||||
{
|
||||
const string json = @"[
|
||||
{
|
||||
""repository_id"": 816170000,
|
||||
""repository_name"": ""somerepo"",
|
||||
""repository_full_name"": ""contoso/somerepo"",
|
||||
""properties"": [
|
||||
{
|
||||
""property_name"": ""test_ms"",
|
||||
""value"": [
|
||||
""option_d"",
|
||||
""option_e""
|
||||
]
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_ss"",
|
||||
""value"": ""option_c""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_str"",
|
||||
""value"": null
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_tf"",
|
||||
""value"": ""true""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""repository_id"": 813230000,
|
||||
""repository_name"": ""entities"",
|
||||
""repository_full_name"": ""contoso/entities"",
|
||||
""properties"": [
|
||||
{
|
||||
""property_name"": ""test_ms"",
|
||||
""value"": [
|
||||
""option_d"",
|
||||
""option_e""
|
||||
]
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_ss"",
|
||||
""value"": ""option_c""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_str"",
|
||||
""value"": ""hello""
|
||||
},
|
||||
{
|
||||
""property_name"": ""test_tf"",
|
||||
""value"": ""unset""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
";
|
||||
var serializer = new SimpleJsonSerializer();
|
||||
|
||||
var properties = serializer.Deserialize<IReadOnlyList<OrganizationCustomPropertyValues>>(json);
|
||||
Assert.NotNull(properties);
|
||||
Assert.Equal(2, properties.Count);
|
||||
|
||||
var somerepo = properties[0];
|
||||
Assert.Equal(816170000, somerepo.RepositoryId);
|
||||
Assert.Equal("somerepo", somerepo.RepositoryName);
|
||||
Assert.Equal("contoso/somerepo", somerepo.RepositoryFullName);
|
||||
Assert.Equal(4, somerepo.Properties.Count);
|
||||
|
||||
var somerepoTestMs = somerepo.Properties[0];
|
||||
Assert.Equal("test_ms", somerepoTestMs.PropertyName);
|
||||
Assert.Equal(new List<string> { "option_d", "option_e" }, somerepoTestMs.Values);
|
||||
|
||||
var somerepoTestSs = somerepo.Properties[1];
|
||||
Assert.Equal("test_ss", somerepoTestSs.PropertyName);
|
||||
Assert.Equal("option_c", somerepoTestSs.Value);
|
||||
Assert.Equal(new List<string> { "option_c" }, somerepoTestSs.Values);
|
||||
|
||||
var somerepoTestStr = somerepo.Properties[2];
|
||||
Assert.Equal("test_str", somerepoTestStr.PropertyName);
|
||||
Assert.Null(somerepoTestStr.Value);
|
||||
|
||||
var somerepoTestTf = somerepo.Properties[3];
|
||||
Assert.Equal("test_tf", somerepoTestTf.PropertyName);
|
||||
Assert.Equal("true", somerepoTestTf.Value);
|
||||
|
||||
|
||||
var entities = properties[1];
|
||||
Assert.Equal(813230000, entities.RepositoryId);
|
||||
Assert.Equal("entities", entities.RepositoryName);
|
||||
Assert.Equal("contoso/entities", entities.RepositoryFullName);
|
||||
Assert.Equal(4, entities.Properties.Count);
|
||||
|
||||
var entitiesTestMs = entities.Properties[0];
|
||||
Assert.Equal("test_ms", entitiesTestMs.PropertyName);
|
||||
Assert.Equal(new List<string> { "option_d", "option_e" }, entitiesTestMs.Values);
|
||||
|
||||
var entitiesTestSs = entities.Properties[1];
|
||||
Assert.Equal("test_ss", entitiesTestSs.PropertyName);
|
||||
Assert.Equal("option_c", entitiesTestSs.Value);
|
||||
Assert.Equal(new List<string> { "option_c" }, entitiesTestSs.Values);
|
||||
|
||||
var entitiesTestStr = entities.Properties[2];
|
||||
Assert.Equal("test_str", entitiesTestStr.PropertyName);
|
||||
Assert.Equal("hello", entitiesTestStr.Value);
|
||||
|
||||
var entitiesTestTf = entities.Properties[3];
|
||||
Assert.Equal("test_tf", entitiesTestTf.PropertyName);
|
||||
Assert.Equal("unset", entitiesTestTf.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class UpsertOrganizationCustomPropertyTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanSerializeMultiSelect()
|
||||
{
|
||||
var expected = "{\"value_type\":\"multi_select\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":[\"option_d\",\"option_e\"]}";
|
||||
|
||||
|
||||
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.MultiSelect, new List<string> { "option_d", "option_e" });
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeSingleSelect()
|
||||
{
|
||||
var expected = "{\"value_type\":\"single_select\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"option_c\"}";
|
||||
|
||||
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.SingleSelect, "option_c");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeString()
|
||||
{
|
||||
var expected = "{\"value_type\":\"string\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"hello\"}";
|
||||
|
||||
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.String, "hello");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanSerializeTrueFalse()
|
||||
{
|
||||
var expected = "{\"value_type\":\"true_false\"," +
|
||||
"\"required\":true," +
|
||||
"\"default_value\":\"true\"}";
|
||||
|
||||
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.TrueFalse, "true");
|
||||
|
||||
var json = new SimpleJsonSerializer().Serialize(update);
|
||||
|
||||
Assert.Equal(expected, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user