mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Merge pull request #1132 from AlexP11223/fix-type-and-visibility-affilation-mix-1107
#1107 Do no set default visibility and affiliation values to avoid mixing with type
This commit is contained in:
50
Octokit.Tests/Models/RepositoryRequestTests.cs
Normal file
50
Octokit.Tests/Models/RepositoryRequestTests.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Models
|
||||
{
|
||||
public class RepositoryRequestTests
|
||||
{
|
||||
public class TheToParametersDictionaryMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ContainsSetValues()
|
||||
{
|
||||
var request = new RepositoryRequest
|
||||
{
|
||||
Type = RepositoryType.All,
|
||||
Sort = RepositorySort.FullName,
|
||||
Direction = SortDirection.Ascending
|
||||
};
|
||||
|
||||
var parameters = request.ToParametersDictionary();
|
||||
|
||||
Assert.Equal(3, parameters.Count);
|
||||
Assert.Equal("all", parameters["type"]);
|
||||
Assert.Equal("full_name", parameters["sort"]);
|
||||
Assert.Equal("asc", parameters["direction"]);
|
||||
|
||||
request = new RepositoryRequest
|
||||
{
|
||||
Affiliation = RepositoryAffiliation.All,
|
||||
Visibility = RepositoryVisibility.Public
|
||||
};
|
||||
|
||||
parameters = request.ToParametersDictionary();
|
||||
|
||||
Assert.Equal(2, parameters.Count);
|
||||
Assert.Equal("owner, collaborator, organization_member", parameters["affiliation"]);
|
||||
Assert.Equal("public", parameters["visibility"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotReturnValuesForDefaultRequest()
|
||||
{
|
||||
var request = new RepositoryRequest();
|
||||
|
||||
var parameters = request.ToParametersDictionary();
|
||||
|
||||
Assert.Empty(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,7 @@
|
||||
<Compile Include="Models\PullRequestRequestTests.cs" />
|
||||
<Compile Include="Models\PunchCardTests.cs" />
|
||||
<Compile Include="Models\ReadOnlyPagedCollectionTests.cs" />
|
||||
<Compile Include="Models\RepositoryRequestTests.cs" />
|
||||
<Compile Include="Models\RepositoryUpdateTests.cs" />
|
||||
<Compile Include="Models\RequestParametersTests.cs" />
|
||||
<Compile Include="Models\SearchCodeRequestTests.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
@@ -19,7 +20,7 @@ namespace Octokit
|
||||
/// The type.
|
||||
/// </value>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
|
||||
public RepositoryType Type { get; set; }
|
||||
public RepositoryType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort property.
|
||||
@@ -27,7 +28,7 @@ namespace Octokit
|
||||
/// <value>
|
||||
/// The sort.
|
||||
/// </value>
|
||||
public RepositorySort Sort { get; set; }
|
||||
public RepositorySort? Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort direction.
|
||||
@@ -35,7 +36,7 @@ namespace Octokit
|
||||
/// <value>
|
||||
/// The direction.
|
||||
/// </value>
|
||||
public SortDirection Direction { get; set; }
|
||||
public SortDirection? Direction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the visibility property.
|
||||
@@ -43,7 +44,7 @@ namespace Octokit
|
||||
/// <value>
|
||||
/// The visibility.
|
||||
/// </value>
|
||||
public RepositoryVisibility Visibility { get; set; }
|
||||
public RepositoryVisibility? Visibility { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the affiliation property.
|
||||
@@ -51,13 +52,25 @@ namespace Octokit
|
||||
/// <value>
|
||||
/// The affiliation.
|
||||
/// </value>
|
||||
public RepositoryAffiliation Affiliation { get; set; }
|
||||
public RepositoryAffiliation? Affiliation { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Type: {0}, Sort: {1}, Direction: {2}", Type, Sort, Direction);
|
||||
var propValues = new List<string>();
|
||||
if (Type.HasValue)
|
||||
propValues.Add(string.Format(CultureInfo.InvariantCulture, "Type: {0}", Type));
|
||||
if (Sort.HasValue)
|
||||
propValues.Add(string.Format(CultureInfo.InvariantCulture, "Sort: {0}", Sort));
|
||||
if (Direction.HasValue)
|
||||
propValues.Add(string.Format(CultureInfo.InvariantCulture, "Direction: {0}", Direction));
|
||||
if (Visibility.HasValue)
|
||||
propValues.Add(string.Format(CultureInfo.InvariantCulture, "Visibility: {0}", Visibility));
|
||||
if (Affiliation.HasValue)
|
||||
propValues.Add(string.Format(CultureInfo.InvariantCulture, "Affiliation: {0}", Affiliation));
|
||||
|
||||
return string.Join(", ", propValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace Octokit
|
||||
Justification = "GitHub API depends on lower case strings")]
|
||||
static Func<PropertyInfo, object, string> GetValueFunc(Type propertyType)
|
||||
{
|
||||
// get underlying type if nullable
|
||||
propertyType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;
|
||||
|
||||
if (typeof(IEnumerable<string>).IsAssignableFrom(propertyType))
|
||||
{
|
||||
return (prop, value) =>
|
||||
|
||||
Reference in New Issue
Block a user