Skip to content

Commit

Permalink
Merge pull request octokit#1132 from AlexP11223/fix-type-and-visibili…
Browse files Browse the repository at this point in the history
…ty-affilation-mix-1107

octokit#1107 Do no set default visibility and affiliation values to avoid mixing with type
  • Loading branch information
shiftkey committed Mar 10, 2016
2 parents a7935da + 7866f3c commit ca025b9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
50 changes: 50 additions & 0 deletions Octokit.Tests/Models/RepositoryRequestTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
25 changes: 19 additions & 6 deletions Octokit/Models/Request/RepositoryRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
Expand All @@ -19,45 +20,57 @@ public class RepositoryRequest : RequestParameters
/// 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.
/// </summary>
/// <value>
/// The sort.
/// </value>
public RepositorySort Sort { get; set; }
public RepositorySort? Sort { get; set; }

/// <summary>
/// Gets or sets the sort direction.
/// </summary>
/// <value>
/// The direction.
/// </value>
public SortDirection Direction { get; set; }
public SortDirection? Direction { get; set; }

/// <summary>
/// Gets or sets the visibility property.
/// </summary>
/// <value>
/// The visibility.
/// </value>
public RepositoryVisibility Visibility { get; set; }
public RepositoryVisibility? Visibility { get; set; }

/// <summary>
/// Gets or sets the affiliation property.
/// </summary>
/// <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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Octokit/Models/Request/RequestParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ static List<PropertyParameter> GetPropertyParametersForType(Type type)
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) =>
Expand Down

0 comments on commit ca025b9

Please sign in to comment.