[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:
Colby Williams
2024-06-17 17:01:20 -05:00
committed by GitHub
parent 7d54cb0d85
commit 9a3177e385
53 changed files with 3121 additions and 1 deletions

View File

@@ -0,0 +1,172 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Clients
{
public class OrganizationCustomPropertiesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new OrganizationCustomPropertiesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertiesClient(connection);
await client.GetAll("org");
connection.Received()
.Get<IReadOnlyList<OrganizationCustomProperty>>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/schema"), null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertiesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(""));
}
}
public class GetMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertiesClient(connection);
await client.Get("org", "property");
connection.Received()
.Get<OrganizationCustomProperty>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/schema/property"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertiesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "property"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("org", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "property"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("org", ""));
}
}
public class BatchCreateOrUpdateMethod
{
[Fact]
public async Task PatchTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertiesClient(connection);
var properties = new UpsertOrganizationCustomProperties
{
Properties = new List<OrganizationCustomPropertyUpdate>
{
new OrganizationCustomPropertyUpdate("name", CustomPropertyValueType.String, "default")
}
};
await client.CreateOrUpdate("org", properties);
connection.Received()
.Patch<IReadOnlyList<OrganizationCustomProperty>>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/schema"), properties);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertiesClient(Substitute.For<IApiConnection>());
var properties = new UpsertOrganizationCustomProperties
{
Properties = new List<OrganizationCustomPropertyUpdate>
{
new OrganizationCustomPropertyUpdate("name", CustomPropertyValueType.String, "default")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, properties));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", new UpsertOrganizationCustomProperties()));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", properties));
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PostsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertiesClient(connection);
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.String, "value");
await client.CreateOrUpdate("org", "property", update);
connection.Received()
.Put<OrganizationCustomProperty>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/schema/property"), update);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertiesClient(Substitute.For<IApiConnection>());
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.String, "value");
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, "property", update));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", null, update));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "property", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "property", new UpsertOrganizationCustomProperty()));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", "property", update));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("owner", "", update));
}
}
public class DeleteMethod
{
[Fact]
public async Task DeletesTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertiesClient(connection);
await client.Delete("org", "property");
connection.Received()
.Delete(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/schema/property"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertiesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "property"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "property"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", ""));
}
}
}
}

View File

@@ -0,0 +1,110 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Clients
{
public class OrganizationCustomPropertyValuesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new OrganizationCustomPropertyValuesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertyValuesClient(connection);
await client.GetAll("org");
connection.Received()
.GetAll<OrganizationCustomPropertyValues>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/values"), Arg.Any<IDictionary<string, string>>());
}
[Fact]
public void RequestsTheCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertyValuesClient(connection);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
client.GetAll("org", options);
connection.Received()
.GetAll<OrganizationCustomPropertyValues>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/values"), options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertyValuesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, new OrganizationCustomPropertyValuesRequest()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("org", repositoryQuery: null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(""));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", new OrganizationCustomPropertyValuesRequest()));
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PatchTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new OrganizationCustomPropertyValuesClient(connection);
var propertyValues = new UpsertOrganizationCustomPropertyValues
{
RepositoryNames = new List<string> { "repo" },
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await client.CreateOrUpdate("org", propertyValues);
connection.Received()
.Patch(Arg.Is<Uri>(u => u.ToString() == "orgs/org/properties/values"), propertyValues);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new OrganizationCustomPropertyValuesClient(Substitute.For<IApiConnection>());
var propertyValues = new UpsertOrganizationCustomPropertyValues
{
RepositoryNames = new List<string> { "repo" },
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, propertyValues));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", new UpsertOrganizationCustomPropertyValues()));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", propertyValues));
}
}
}
}

View File

@@ -0,0 +1,90 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Clients
{
public class RepositoryCustomPropertiesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new RepositoryCustomPropertiesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCustomPropertiesClient(connection);
await client.GetAll("org", "repo");
connection.Received()
.Get<IReadOnlyList<CustomPropertyValue>>(Arg.Is<Uri>(u => u.ToString() == "repos/org/repo/properties/values"), null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryCustomPropertiesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "repo"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("org", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "repo"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("org", ""));
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PatchTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCustomPropertiesClient(connection);
var propertyValues = new UpsertRepositoryCustomPropertyValues
{
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await client.CreateOrUpdate("org", "repo", propertyValues);
connection.Received()
.Patch(Arg.Is<Uri>(u => u.ToString() == "repos/org/repo/properties/values"), propertyValues);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryCustomPropertiesClient(Substitute.For<IApiConnection>());
var propertyValues = new UpsertRepositoryCustomPropertyValues
{
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, "repo", propertyValues));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", null, propertyValues));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", "repo", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", "repo", new UpsertRepositoryCustomPropertyValues()));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", "repo", propertyValues));
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("org", "", propertyValues));
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,169 @@
using NSubstitute;
using Octokit.Reactive;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableOrganizationCustomPropertiesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableOrganizationCustomPropertiesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertiesClient(gitHubClient);
client.GetAll("org");
gitHubClient.Received().Organization.CustomProperty.GetAll("org");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertiesClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("").ToTask());
}
}
public class GetMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertiesClient(gitHubClient);
await client.Get("org", "property");
gitHubClient.Received().Organization.CustomProperty.Get("org", "property");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertiesClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "property").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("org", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "property").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("org", "").ToTask());
}
}
public class BatchCreateOrUpdateMethod
{
[Fact]
public void PostsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertiesClient(gitHubClient);
var properties = new UpsertOrganizationCustomProperties
{
Properties = new List<OrganizationCustomPropertyUpdate>
{
new OrganizationCustomPropertyUpdate("name", CustomPropertyValueType.String, "default")
}
};
client.CreateOrUpdate("org", properties);
gitHubClient.Received().Organization.CustomProperty.CreateOrUpdate("org", properties);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertiesClient(Substitute.For<IGitHubClient>());
var properties = new UpsertOrganizationCustomProperties
{
Properties = new List<OrganizationCustomPropertyUpdate>
{
new OrganizationCustomPropertyUpdate("name", CustomPropertyValueType.String, "default")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, properties).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", new UpsertOrganizationCustomProperties()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", properties).ToTask());
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PostsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertiesClient(gitHubClient);
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.String, "value");
await client.CreateOrUpdate("org", "property", update);
gitHubClient.Received().Organization.CustomProperty.CreateOrUpdate("org", "property", update);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertiesClient(Substitute.For<IGitHubClient>());
var update = new UpsertOrganizationCustomProperty(CustomPropertyValueType.String, "value");
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, "property", update).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", null, update).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "property", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("owner", "property", new UpsertOrganizationCustomProperty()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", "property", update).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("owner", "", update).ToTask());
}
}
public class DeleteMethod
{
[Fact]
public async Task DeletesTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertiesClient(gitHubClient);
await client.Delete("org", "property");
gitHubClient.Received().Organization.CustomProperty.Delete("org", "property");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertiesClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "property").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "property").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "").ToTask());
}
}
}
}

View File

@@ -0,0 +1,89 @@
using NSubstitute;
using Octokit.Reactive;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableOrganizationCustomPropertyValuesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableOrganizationCustomPropertyValuesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertyValuesClient(gitHubClient);
client.GetAll("org");
gitHubClient.Received().Organization.CustomProperty.Values.GetAll("org");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertyValuesClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("").ToTask());
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PostsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationCustomPropertyValuesClient(gitHubClient);
var propertyValues = new UpsertOrganizationCustomPropertyValues
{
RepositoryNames = new List<string> { "repo" },
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await client.CreateOrUpdate("org", propertyValues);
gitHubClient.Received().Organization.CustomProperty.Values.CreateOrUpdate("org", propertyValues);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableOrganizationCustomPropertyValuesClient(Substitute.For<IGitHubClient>());
var propertyValues = new UpsertOrganizationCustomPropertyValues
{
RepositoryNames = new List<string> { "repo" },
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, propertyValues).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", new UpsertOrganizationCustomPropertyValues()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", propertyValues).ToTask());
}
}
}
}

View File

@@ -0,0 +1,91 @@
using NSubstitute;
using Octokit.Reactive;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableRepositoryCustomPropertiesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableRepositoryCustomPropertiesClient(null));
}
}
public class GetAllMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryCustomPropertiesClient(gitHubClient);
client.GetAll("org", "repo");
gitHubClient.Received().Repository.CustomProperty.GetAll("org", "repo");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositoryCustomPropertiesClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "repo").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("org", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "repo").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("org", "").ToTask());
}
}
public class CreateOrUpdateMethod
{
[Fact]
public async Task PostsTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryCustomPropertiesClient(gitHubClient);
var propertyValues = new UpsertRepositoryCustomPropertyValues
{
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await client.CreateOrUpdate("org", "repo", propertyValues);
gitHubClient.Received().Repository.CustomProperty.CreateOrUpdate("org", "repo", propertyValues);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositoryCustomPropertiesClient(Substitute.For<IGitHubClient>());
var propertyValues = new UpsertRepositoryCustomPropertyValues
{
Properties = new List<CustomPropertyValueUpdate>
{
new CustomPropertyValueUpdate("name", "value")
}
};
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate(null, "repo", propertyValues).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", null, propertyValues).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", "repo", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateOrUpdate("org", "repo", new UpsertRepositoryCustomPropertyValues()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("", "repo", propertyValues).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateOrUpdate("org", "", propertyValues).ToTask());
}
}
}
}