Skip to content

Commit

Permalink
Merge master into dotnetcore (#1599)
Browse files Browse the repository at this point in the history
* bugfix - PUT should have a payload for Mark as Read (#1579)

* bugfix - PUT should have a payload for Mark as Read

* also fix the Observable client test

* add integration tests for MarkRead methods

* Fixup MarkReadForRepository methods to specify a body in the PUT request

* Fix unit tests for regular and observable client

* helps if the new files are included in the test project :)

* Cloning ApiInfo object should work when some fields are null (#1580)

* Adjust ApiInfo.Clone() to work even if some elements (eg ETag) are null

* Remove c# 6 language feature and do it the old school way

* Add a test for cloning ApiInfo when some fields are null

* The 3 lists can never be null anyway so remove some un-needed statements

* Add test for null RateLimit

* Remove Rx-Main dependency from samples
This resolves #1592 - LINQPad doesn't understand how to restore this unlisted package and it's not actually needed in the samples.

* Adding RemovedFromProject and other missing EventInfoState types. (#1591)

* Adding missing review types to event info.

* Fixing whitespace.

* Reword `BaseRefChanged` comment

* Adding missing event types.

* Change response models 'Url' properties from `Uri` to `string` (#1585)

* Add convention test to ensure 'Url' properties are of type string

Closes #1582

* Change 'Url' properties from Uri to string

Global Find/Replace FTW!

* fix compilation errors in the integration tests project

* Extend 'Url' properties type check to request models

* Stick to convention tests naming convention

* Remove unused using directives in models

Changing from `Uri` to `string` means the `using System;`
directive was not needed anymore in some files

* Update exception message wording

* empty commit to trigger a new build - hopefully Travis passes

* add convention test to ensure request models have Uri 'Url' properties

* make request models 'Url' properties Uri

fix typo in convention test name

* revert some request models 'Url' properties as `string`

see #1585 (comment)

* Change test so that all model types must have 'Url' properties of type string

 - Filter test input to only get types which have 'Url' properties
 - Merge response and request model types tests into one
 - Unparameterize the exception since we only check for the string type now

* Fix string.Format tokens

If this PR doesn't get rebased, it'll be my wall of shame FOREVER!

* and then it's even more embarrassing when the commit message says rebased but you really meant squashed

* Remove exclusion of `Release` from request models
  • Loading branch information
mderriey authored and ryangribble committed May 2, 2017
1 parent 11bbb2d commit 9c80b00
Show file tree
Hide file tree
Showing 56 changed files with 388 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Octokit.Tests.Conventions
{
public class InvalidUrlPropertyTypeException : Exception
{
public InvalidUrlPropertyTypeException(Type modelType, IEnumerable<PropertyInfo> propertiesWithInvalidType)
: base(CreateMessage(modelType, propertiesWithInvalidType))
{ }

static string CreateMessage(Type modelType, IEnumerable<PropertyInfo> propertiesWithInvalidType)
{
return string.Format("Model type '{0}' contains the following properties that are named or suffixed with 'Url' but are not of type String: {!}{2}",
modelType.FullName,
Environment.NewLine,
string.Join(Environment.NewLine, propertiesWithInvalidType.Select(x => x.Name)));
}
}
}
31 changes: 31 additions & 0 deletions Octokit.Tests.Conventions/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ public void ResponseModelsHaveReadOnlyCollections(Type modelType)
}
}

[Theory]
[MemberData("ModelTypesWithUrlProperties")]
public void ModelsHaveUrlPropertiesOfTypeString(Type modelType)
{
var propertiesWithInvalidType = modelType
.GetProperties()
.Where(IsUrlProperty)
.Where(x => x.PropertyType != typeof(string))
.ToList();

if (propertiesWithInvalidType.Count > 0)
{
throw new InvalidUrlPropertyTypeException(modelType, propertiesWithInvalidType);
}
}

public static IEnumerable<object[]> GetClientInterfaces()
{
return typeof(IGitHubClient)
Expand All @@ -123,6 +139,16 @@ public static IEnumerable<object[]> ModelTypes
get { return GetModelTypes(includeRequestModels: true).Select(type => new[] { type }); }
}

public static IEnumerable<object[]> ModelTypesWithUrlProperties
{
get
{
return GetModelTypes(includeRequestModels: true)
.Where(type => type.GetProperties().Any(IsUrlProperty))
.Select(type => new[] { type });
}
}

public static IEnumerable<object[]> ResponseModelTypes
{
get { return GetModelTypes(includeRequestModels: false).Select(type => new[] { type }); }
Expand Down Expand Up @@ -216,5 +242,10 @@ private static IEnumerable<Type> UnwrapGenericArguments(Type returnType)
yield return returnType;
}
}

private static bool IsUrlProperty(PropertyInfo property)
{
return property.Name.EndsWith("Url");
}
}
}
8 changes: 4 additions & 4 deletions Octokit.Tests.Integration/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,9 @@ public async Task CanAccessUrls()
var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

Assert.NotNull(issue.CommentsUrl);
Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments")), issue.CommentsUrl);
Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments"), issue.CommentsUrl);
Assert.NotNull(issue.EventsUrl);
Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl);
Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events"), issue.EventsUrl);
}

[IntegrationTest]
Expand All @@ -1246,9 +1246,9 @@ public async Task CanAccessUrlsWithRepositoryId()
var issue = await _issuesClient.Create(_context.Repository.Id, newIssue);

Assert.NotNull(issue.CommentsUrl);
Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments")), issue.CommentsUrl);
Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments"), issue.CommentsUrl);
Assert.NotNull(issue.EventsUrl);
Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl);
Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events"), issue.EventsUrl);
}

[IntegrationTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public async Task CanDeserializeMergedEvent()
Assert.NotNull(issueEvent);
Assert.Equal(EventInfoState.Merged, issueEvent.Event);
Assert.Equal("0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitId);
Assert.Equal(new Uri("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e"), issueEvent.CommitUrl);
Assert.Equal("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitUrl);
}

public void Dispose()
Expand Down
41 changes: 41 additions & 0 deletions Octokit.Tests.Integration/Clients/NotificationsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;
using Octokit.Tests.Integration;
using Xunit;

public class NotificationsClientTests
{
public class TheMarkAsReadMethod
{
[IntegrationTest]
public async Task MarksNotificationsRead()
{
var github = Helper.GetAuthenticatedClient();

await github.Activity.Notifications.MarkAsRead();
}
}

public class TheMarkAsReadForRepositoryMethod
{
[IntegrationTest]
public async Task MarksNotificationsRead()
{
var owner = "octokit";
var repo = "octokit.net";

var github = Helper.GetAuthenticatedClient();

await github.Activity.Notifications.MarkAsReadForRepository(owner, repo);
}

[IntegrationTest]
public async Task MarksNotificationsReadForRepositoryId()
{
var repositoryId = 7528679;

var github = Helper.GetAuthenticatedClient();

await github.Activity.Notifications.MarkAsReadForRepository(repositoryId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task GetsFileContent()

Assert.Equal(1, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand All @@ -88,7 +88,7 @@ public async Task GetsFileContentWithRepositoryId()

Assert.Equal(1, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task GetsFileContentWholeRepo()

Assert.Equal(3, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand All @@ -146,7 +146,7 @@ public async Task GetsFileContentWholeRepoWithRepositoryId()

Assert.Equal(3, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task GetsFileContent()

Assert.Equal(1, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand All @@ -205,7 +205,7 @@ public async Task GetsFileContentWithRepositoryId()

Assert.Equal(1, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand Down Expand Up @@ -248,7 +248,7 @@ public async Task GetsFileContentWholeRepo()

Assert.Equal(3, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand All @@ -263,7 +263,7 @@ public async Task GetsFileContentWholeRepoWithRepositoryId()

Assert.Equal(3, contents.Count);
Assert.Equal(ContentType.File, contents.First().Type);
Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl);
Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl);
}

[IntegrationTest]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Octokit.Tests.Integration;
using Xunit;

public class ObservableNotificationsClientTests
{
public class TheMarkAsReadMethod
{
[IntegrationTest]
public async Task MarksNotificationsRead()
{
var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient());

await client.Activity.Notifications.MarkAsRead();
}
}

public class TheMarkAsReadForRepositoryMethod
{
[IntegrationTest]
public async Task MarksNotificationsRead()
{
var owner = "octokit";
var repo = "octokit.net";

var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient());

await client.Activity.Notifications.MarkAsReadForRepository(owner, repo);
}

[IntegrationTest]
public async Task MarksNotificationsReadForRepositoryId()
{
var repositoryId = 7528679;

var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient());

await client.Activity.Notifications.MarkAsReadForRepository(repositoryId);
}
}
}
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/RedirectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task CanCreateIssueOnRedirectedRepository()
var issue = await client.Issue.Create(owner, oldRepoName, newIssue);
Assert.NotNull(issue);

Assert.True(issue.Url.AbsoluteUri.Contains("repository-after-rename"));
Assert.True(issue.Url.Contains("repository-after-rename"));

var resolvedIssue = await client.Issue.Get(owner, newRepoName, issue.Number);

Expand Down
8 changes: 4 additions & 4 deletions Octokit.Tests/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,10 @@ public void CanDeserializeIssue()

Assert.Equal(1, response.Body.Number);

Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.Url);
Assert.Equal(new Uri("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.HtmlUrl);
Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/comments"), response.Body.CommentsUrl);
Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events"), response.Body.EventsUrl);
Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1", response.Body.Url);
Assert.Equal("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1", response.Body.HtmlUrl);
Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/comments", response.Body.CommentsUrl);
Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events", response.Body.EventsUrl);
}
}
}
6 changes: 3 additions & 3 deletions Octokit.Tests/Clients/NotificationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void RequestsCorrectUrl()

client.MarkAsRead();

connection.Received().Put(endpoint);
connection.Received().Put<object>(endpoint, Args.Object);
}
}

Expand All @@ -299,7 +299,7 @@ public void RequestsCorrectUrl()

client.MarkAsReadForRepository("banana", "split");

connection.Received().Put(endpoint);
connection.Received().Put<object>(endpoint, Args.Object);
}

[Fact]
Expand All @@ -311,7 +311,7 @@ public void RequestsCorrectUrlWithRepositoryId()

client.MarkAsReadForRepository(1);

connection.Received().Put(endpoint);
connection.Received().Put<object>(endpoint, Args.Object);
}

[Fact]
Expand Down
Loading

0 comments on commit 9c80b00

Please sign in to comment.