mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 18:35:35 +00:00
Refactor search result classes
They are now readonly and implement a generic base class.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace Octokit.Tests.Models
|
||||
Assert.Equal(1, actual.Id);
|
||||
Assert.Equal("topic-branch", actual.Sha);
|
||||
Assert.Equal("https://api.github.com/repos/octocat/example/deployments/1", actual.Url);
|
||||
Assert.Equal(new Dictionary<string, string> { { "environment", "production" } }, actual.Payload);
|
||||
Assert.Equal(new ReadOnlyDictionary<string, string>(new Dictionary<string, string> { { "environment", "production" } }), actual.Payload);
|
||||
Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.CreatedAt);
|
||||
Assert.Equal(DateTimeOffset.Parse("2012-07-20T01:19:13Z"), actual.UpdatedAt);
|
||||
Assert.Equal("Deploy request from hubot", actual.Description);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class SearchRepositoryRequestTests
|
||||
{
|
||||
public class TheMergedQualifiersMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnsAReadOnlyDictionary()
|
||||
{
|
||||
var request = new SearchCodeRequest("test");
|
||||
|
||||
var result = request.MergedQualifiers();
|
||||
|
||||
// If I can cast this to a writeable collection, then that defeats the purpose of a read only.
|
||||
AssertEx.IsReadOnlyCollection<string>(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SortNotSpecifiedByDefault()
|
||||
{
|
||||
var request = new SearchCodeRequest("test");
|
||||
Assert.True(String.IsNullOrWhiteSpace(request.Sort));
|
||||
Assert.False(request.Parameters.ContainsKey("sort"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Octokit;
|
||||
using Octokit.Internal;
|
||||
using Xunit;
|
||||
|
||||
public class SearchRepositoryResultTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanBeDeserialized()
|
||||
{
|
||||
const string json = @"{
|
||||
""total_count"": 40,
|
||||
""incomplete_results"": false,
|
||||
""items"": [
|
||||
{
|
||||
""id"": 3081286,
|
||||
""name"": ""Tetris"",
|
||||
""full_name"": ""dtrupenn/Tetris"",
|
||||
""owner"": {
|
||||
""login"": ""dtrupenn"",
|
||||
""id"": 872147,
|
||||
""avatar_url"": ""https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"",
|
||||
""gravatar_id"": """",
|
||||
""url"": ""https://api.github.com/users/dtrupenn"",
|
||||
""received_events_url"": ""https://api.github.com/users/dtrupenn/received_events"",
|
||||
""type"": ""User""
|
||||
},
|
||||
""private"": false,
|
||||
""html_url"": ""https://github.com/dtrupenn/Tetris"",
|
||||
""description"": ""A C implementation of Tetris using Pennsim through LC4"",
|
||||
""fork"": false,
|
||||
""url"": ""https://api.github.com/repos/dtrupenn/Tetris"",
|
||||
""created_at"": ""2012-01-01T00:31:50Z"",
|
||||
""updated_at"": ""2013-01-05T17:58:47Z"",
|
||||
""pushed_at"": ""2012-01-01T00:37:02Z"",
|
||||
""homepage"": """",
|
||||
""size"": 524,
|
||||
""stargazers_count"": 1,
|
||||
""watchers_count"": 1,
|
||||
""language"": ""Assembly"",
|
||||
""forks_count"": 0,
|
||||
""open_issues_count"": 0,
|
||||
""master_branch"": ""master"",
|
||||
""default_branch"": ""master"",
|
||||
""score"": 10.309712
|
||||
}
|
||||
]
|
||||
}";
|
||||
var serializer = new SimpleJsonSerializer();
|
||||
|
||||
var results = serializer.Deserialize<SearchRepositoryResult>(json);
|
||||
|
||||
Assert.Equal(40, results.TotalCount);
|
||||
Assert.False(results.IncompleteResults);
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,8 @@
|
||||
<Compile Include="Models\RequestParametersTests.cs" />
|
||||
<Compile Include="Models\SearchCodeRequestTests.cs" />
|
||||
<Compile Include="Models\SearchIssuesRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryResultTests.cs" />
|
||||
<Compile Include="Models\SearchUsersRequestTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Helpers\StringExtensionsTests.cs" />
|
||||
|
||||
@@ -138,6 +138,8 @@
|
||||
<Compile Include="Models\RequestParametersTests.cs" />
|
||||
<Compile Include="Models\SearchCodeRequestTests.cs" />
|
||||
<Compile Include="Models\SearchIssuesRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryResultTests.cs" />
|
||||
<Compile Include="Models\SearchUsersRequestTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Helpers\StringExtensionsTests.cs" />
|
||||
|
||||
@@ -152,6 +152,8 @@
|
||||
<Compile Include="Models\RepositoryUpdateTests.cs" />
|
||||
<Compile Include="Models\RequestParametersTests.cs" />
|
||||
<Compile Include="Models\SearchCodeRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryRequestTests.cs" />
|
||||
<Compile Include="Models\SearchRepositoryResultTests.cs" />
|
||||
<Compile Include="Models\SearchUsersRequestTests.cs" />
|
||||
<Compile Include="Models\SearchIssuesRequestTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -1,23 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class SearchCodeResult
|
||||
public class SearchCodeResult : SearchResult<SearchCode>
|
||||
{
|
||||
public int TotalCount { get; set; }
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public IReadOnlyList<SearchCode> Items { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class SearchIssuesResult
|
||||
public class SearchIssuesResult : SearchResult<Issue>
|
||||
{
|
||||
public int TotalCount { get; set; }
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public IReadOnlyList<Issue> Items { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class SearchRepositoryResult
|
||||
public class SearchRepositoryResult : SearchResult<Repository>
|
||||
{
|
||||
public int TotalCount { get; set; }
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public IReadOnlyList<Repository> Items { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
namespace Octokit.Internal
|
||||
{
|
||||
public abstract class SearchResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Total number of matching items.
|
||||
/// </summary>
|
||||
public int TotalCount { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the query timed out and it's possible that the results are incomplete.
|
||||
/// </summary>
|
||||
public bool IncompleteResults { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The found items. Up to 100 per page.
|
||||
/// </summary>
|
||||
public IReadOnlyList<T> Items { get; protected set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class SearchUsersResult
|
||||
public class SearchUsersResult : SearchResult<User>
|
||||
{
|
||||
public int TotalCount { get; set; }
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public IReadOnlyList<User> Items { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,6 +357,7 @@
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\SignatureResponse.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -369,6 +369,7 @@
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\SignatureResponse.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -364,7 +364,8 @@
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\SignatureResponse.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -355,6 +355,7 @@
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\SignatureResponse.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -359,6 +359,7 @@
|
||||
<Compile Include="Models\Response\CommitContent.cs" />
|
||||
<Compile Include="Models\Response\SignatureResponse.cs" />
|
||||
<Compile Include="Helpers\PropertyOrField.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
<Compile Include="Models\Response\SearchCodeResult.cs" />
|
||||
<Compile Include="Models\Response\SearchIssuesResult.cs" />
|
||||
<Compile Include="Models\Response\SearchRepositoryResult.cs" />
|
||||
<Compile Include="Models\Response\SearchResult.cs" />
|
||||
<Compile Include="Models\Response\SearchUsersResult.cs" />
|
||||
<Compile Include="Models\Response\Subscription.cs" />
|
||||
<Compile Include="Models\Response\ThreadSubscription.cs" />
|
||||
|
||||
Reference in New Issue
Block a user