|
| 1 | +using FluentAssertions; |
1 | 2 | using LoggingExtensions.log4net; |
2 | 3 | using NUnit.Framework; |
| 4 | +using csharp_github_api.IntegrationTests.Ext; |
| 5 | +using csharp_github_api.Models; |
3 | 6 |
|
4 | 7 | namespace csharp_github_api.IntegrationTests |
5 | 8 | { |
6 | | - [TestFixture] |
7 | | - public class UsersTestsUnAuthenticated |
| 9 | + public class UsersTest |
8 | 10 | { |
9 | | - private Github _github; |
10 | | - private const string GitHubUrl = @"https://api.github.com"; |
11 | | - |
12 | | - [TestFixtureSetUp] |
13 | | - public void Setup() |
| 11 | + public abstract class UsersTestsBase : TestsSpecBase |
14 | 12 | { |
15 | | - _github = new Github(GitHubUrl).WithLogger<Log4NetLog>(); |
16 | | - } |
| 13 | + protected Github Github; |
17 | 14 |
|
18 | | - [Test] |
19 | | - public void GetUser_shouldReturnDeserialisedUserObject() |
20 | | - { |
21 | | - var response = _github.User().Get("sgrassie"); |
| 15 | + protected string User; |
22 | 16 |
|
23 | | - Assert.That(response.Dynamic().login, Is.StringMatching("sgrassie")); |
| 17 | + public override void Context() |
| 18 | + { |
| 19 | + Github = new Github(GitHubUrl); |
| 20 | + } |
24 | 21 | } |
25 | 22 |
|
26 | | - //[Test] |
27 | | - //public void GetUser_returns_validUserObject() |
28 | | - //{ |
29 | | - // var user = _github.User.Get("defunkt"); |
30 | | - |
31 | | - // Assert.That(user.Name, Is.StringMatching("Chris Wanstrath")); |
32 | | - //} |
33 | | - |
34 | | - //[Test] |
35 | | - //public void UnAuthenticatedCallShouldFail() |
36 | | - //{ |
37 | | - // var api = new UserApi(GitHubUrl); |
38 | | - // var user = api.Get("sgrassie"); |
39 | | - |
40 | | - // Assert.That(user.DiskUsage, Is.EqualTo(0)); |
41 | | - //} |
| 23 | + public class when_retrieving_unauthenticated_user : UsersTestsBase |
| 24 | + { |
| 25 | + public override void Because() |
| 26 | + { |
| 27 | + User = "sgrassie"; |
| 28 | + } |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public void then_response_data_with_model_should_contain_expected_user() |
| 32 | + { |
| 33 | + var response = Github.User().Get<User>("sgrassie"); |
| 34 | + |
| 35 | + response.Data.Login.Should().Be(User, "The response should be for the specified user."); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void then_response_dynamic_should_have_login_property_with_expected_user() |
| 40 | + { |
| 41 | + var response = Github.User().Get("sgrassie"); |
| 42 | + |
| 43 | + Assert.That(response.Dynamic().login, Is.StringMatching(User)); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void then_response_data_with_model_should_not_contain_private_data() |
| 48 | + { |
| 49 | + var userApi = Github.User(); |
| 50 | + var user = userApi.Get<User>("sgrassie"); |
| 51 | + |
| 52 | + user.Data.DiskUsage.Should().Be(0); |
| 53 | + } |
| 54 | + } |
42 | 55 |
|
43 | 56 | //[Test] |
44 | 57 | //public void WithAuthenticationCallToMethodRequiringAuthenticationShouldBeSuccessful() |
|
0 commit comments