mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
* 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 https://github.com/octokit/octokit.net/pull/1585#issuecomment-297186728 * 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
185 lines
8.1 KiB
C#
185 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Octokit.Tests.Http
|
|
{
|
|
public class ApiInfoTests
|
|
{
|
|
public class TheMethods
|
|
{
|
|
[Fact]
|
|
public void CanClone()
|
|
{
|
|
var original = new ApiInfo(
|
|
new Dictionary<string, Uri>
|
|
{
|
|
{
|
|
"next",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5")
|
|
},
|
|
{
|
|
"last",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5")
|
|
},
|
|
{
|
|
"first",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5")
|
|
},
|
|
{
|
|
"prev",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5")
|
|
}
|
|
},
|
|
new List<string>
|
|
{
|
|
"user"
|
|
},
|
|
new List<string>
|
|
{
|
|
"user",
|
|
"public_repo",
|
|
"repo",
|
|
"gist"
|
|
},
|
|
"5634b0b187fd2e91e3126a75006cc4fa",
|
|
new RateLimit(100, 75, 1372700873)
|
|
);
|
|
|
|
var clone = original.Clone();
|
|
|
|
// Note the use of Assert.NotSame tests for value types - this should continue to test should the underlying
|
|
// model are changed to Object types
|
|
Assert.NotSame(original, clone);
|
|
|
|
Assert.Equal(original.Etag, clone.Etag);
|
|
Assert.NotSame(original.Etag, clone.Etag);
|
|
|
|
Assert.Equal(original.AcceptedOauthScopes.Count, clone.AcceptedOauthScopes.Count);
|
|
Assert.NotSame(original.AcceptedOauthScopes, clone.AcceptedOauthScopes);
|
|
for (int i = 0; i < original.AcceptedOauthScopes.Count; i++)
|
|
{
|
|
Assert.Equal(original.AcceptedOauthScopes[i], clone.AcceptedOauthScopes[i]);
|
|
Assert.NotSame(original.AcceptedOauthScopes[i], clone.AcceptedOauthScopes[i]);
|
|
}
|
|
|
|
Assert.Equal(original.Links.Count, clone.Links.Count);
|
|
Assert.NotSame(original.Links, clone.Links);
|
|
for (int i = 0; i < original.Links.Count; i++)
|
|
{
|
|
Assert.Equal(original.Links.Keys.ToArray()[i], clone.Links.Keys.ToArray()[i]);
|
|
Assert.NotSame(original.Links.Keys.ToArray()[i], clone.Links.Keys.ToArray()[i]);
|
|
Assert.Equal(original.Links.Values.ToArray()[i].ToString(), clone.Links.Values.ToArray()[i].ToString());
|
|
Assert.NotSame(original.Links.Values.ToArray()[i], clone.Links.Values.ToArray()[i]);
|
|
}
|
|
|
|
Assert.Equal(original.OauthScopes.Count, clone.OauthScopes.Count);
|
|
Assert.NotSame(original.OauthScopes, clone.OauthScopes);
|
|
for (int i = 0; i < original.OauthScopes.Count; i++)
|
|
{
|
|
Assert.Equal(original.OauthScopes[i], clone.OauthScopes[i]);
|
|
Assert.NotSame(original.OauthScopes[i], clone.OauthScopes[i]);
|
|
}
|
|
|
|
Assert.NotSame(original.RateLimit, clone.RateLimit);
|
|
Assert.Equal(original.RateLimit.Limit, clone.RateLimit.Limit);
|
|
Assert.NotSame(original.RateLimit.Limit, clone.RateLimit.Limit);
|
|
Assert.Equal(original.RateLimit.Remaining, clone.RateLimit.Remaining);
|
|
Assert.NotSame(original.RateLimit.Remaining, clone.RateLimit.Remaining);
|
|
Assert.Equal(original.RateLimit.ResetAsUtcEpochSeconds, clone.RateLimit.ResetAsUtcEpochSeconds);
|
|
Assert.NotSame(original.RateLimit.ResetAsUtcEpochSeconds, clone.RateLimit.ResetAsUtcEpochSeconds);
|
|
Assert.Equal(original.RateLimit.Reset, clone.RateLimit.Reset);
|
|
Assert.NotSame(original.RateLimit.Reset, clone.RateLimit.Reset);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanCloneWithNullETag()
|
|
{
|
|
var original = new ApiInfo(
|
|
new Dictionary<string, Uri>
|
|
{
|
|
{
|
|
"next",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5")
|
|
},
|
|
{
|
|
"last",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5")
|
|
},
|
|
{
|
|
"first",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5")
|
|
},
|
|
{
|
|
"prev",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5")
|
|
}
|
|
},
|
|
new List<string>
|
|
{
|
|
"user"
|
|
},
|
|
new List<string>(),
|
|
null,
|
|
new RateLimit(100, 75, 1372700873)
|
|
);
|
|
|
|
var clone = original.Clone();
|
|
|
|
Assert.NotNull(clone);
|
|
Assert.Equal(4, clone.Links.Count);
|
|
Assert.Equal(1, clone.OauthScopes.Count);
|
|
Assert.Equal(0, clone.AcceptedOauthScopes.Count);
|
|
Assert.Null(clone.Etag);
|
|
Assert.Equal(100, clone.RateLimit.Limit);
|
|
Assert.Equal(75, clone.RateLimit.Remaining);
|
|
Assert.Equal(1372700873, clone.RateLimit.ResetAsUtcEpochSeconds);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanCloneWithNullRateLimit()
|
|
{
|
|
var original = new ApiInfo(
|
|
new Dictionary<string, Uri>
|
|
{
|
|
{
|
|
"next",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5")
|
|
},
|
|
{
|
|
"last",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5")
|
|
},
|
|
{
|
|
"first",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5")
|
|
},
|
|
{
|
|
"prev",
|
|
new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5")
|
|
}
|
|
},
|
|
new List<string>
|
|
{
|
|
"user"
|
|
},
|
|
new List<string>(),
|
|
"123abc",
|
|
null
|
|
);
|
|
|
|
var clone = original.Clone();
|
|
|
|
Assert.NotNull(clone);
|
|
Assert.Equal(4, clone.Links.Count);
|
|
Assert.Equal(1, clone.OauthScopes.Count);
|
|
Assert.Equal(0, clone.AcceptedOauthScopes.Count);
|
|
Assert.Equal("123abc", clone.Etag);
|
|
Assert.Null(clone.RateLimit);
|
|
}
|
|
}
|
|
}
|
|
} |