Skip to content

Commit 543c738

Browse files
committed
Refactored the tests, again
Added TinySpec.NUnit back - made my mind up this time. Removed the test for the logging - pretty pointless now.
1 parent 94b53bb commit 543c738

7 files changed

Lines changed: 149 additions & 71 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace csharp_github_api.IntegrationTests.Ext
2+
{
3+
public abstract class TestsSpecBase : TinySpec
4+
{
5+
protected const string GitHubUrl = @"https://api.github.com";
6+
}
7+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ==============================================================================
2+
//
3+
// Fervent Coder Copyright © 2011 - Released under the Apache 2.0 License
4+
//
5+
// Copyright 2007-2008 The Apache Software Foundation.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
8+
// this file except in compliance with the License. You may obtain a copy of the
9+
// License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software distributed
14+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
15+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations under the License.
17+
// ==============================================================================
18+
19+
namespace csharp_github_api.IntegrationTests.Ext
20+
{
21+
using System;
22+
using NUnit.Framework;
23+
24+
[TestFixture]
25+
public abstract class TinySpec
26+
{
27+
[TestFixtureSetUp]
28+
public void Setup()
29+
{
30+
Context();
31+
Because();
32+
}
33+
34+
public abstract void Context();
35+
36+
public abstract void Because();
37+
38+
[TestFixtureTearDown]
39+
public void TearDown()
40+
{
41+
AfterObservations();
42+
}
43+
44+
public virtual void AfterObservations() {}
45+
}
46+
47+
public class ObservationAttribute : TestAttribute {}
48+
public class FactAttribute : TestAttribute {}
49+
50+
public class ConcernForAttribute : Attribute
51+
{
52+
public string Name { get; set; }
53+
54+
public ConcernForAttribute(string name)
55+
{
56+
Name = name;
57+
}
58+
}
59+
60+
}

csharp-github-api.IntegrationTests/HeaderProviderTests.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,45 @@
55
using System.Linq;
66
using System.Text;
77
using csharp_github_api.Core;
8+
using csharp_github_api.IntegrationTests.Ext;
89

910
namespace csharp_github_api.IntegrationTests
1011
{
11-
[TestFixture]
1212
public class HeaderProviderTests
1313
{
14-
[Test]
15-
[Ignore("Not sure what default headers to provide yet.")]
16-
public void should_provide_default_headers()
14+
public abstract class HeaderProviderTestsBase : TinySpec
1715
{
18-
var provider = new HeaderProvider();
16+
protected HeaderProvider HeaderProvider;
1917

20-
var headers = provider.Headers;
21-
22-
headers.Should().NotBeEmpty("Default headers should be provided.");
18+
public override void Context()
19+
{
20+
HeaderProvider = new HeaderProvider();
21+
}
2322
}
2423

25-
[Test]
26-
public void addheader_should_add_to_default_headers()
24+
public class when_new_object_instance_instantiated : HeaderProviderTestsBase
2725
{
28-
var provider = new HeaderProvider();
29-
var header = new Header("name", "value");
30-
provider.AddHeader(header);
26+
public override void Because()
27+
{
28+
}
29+
30+
[Fact]
31+
[Ignore("Not sure what default headers to provide yet.")]
32+
public void should_provide_default_headers()
33+
{
34+
var headers = HeaderProvider.Headers;
35+
36+
headers.Should().NotBeEmpty("Default headers should be provided.");
37+
}
38+
39+
[Fact]
40+
public void should_be_able_to_add_to_default_headers()
41+
{
42+
var header = new Header("name", "value");
43+
HeaderProvider.AddHeader(header);
3144

32-
provider.Headers.Contains(header).Should().BeTrue();
45+
HeaderProvider.Headers.Contains(header).Should().BeTrue();
46+
}
3347
}
3448
}
3549
}

csharp-github-api.IntegrationTests/TestLogging.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

csharp-github-api.IntegrationTests/UsersTestsUnAuthenticated.cs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
1+
using FluentAssertions;
12
using LoggingExtensions.log4net;
23
using NUnit.Framework;
4+
using csharp_github_api.IntegrationTests.Ext;
5+
using csharp_github_api.Models;
36

47
namespace csharp_github_api.IntegrationTests
58
{
6-
[TestFixture]
7-
public class UsersTestsUnAuthenticated
9+
public class UsersTest
810
{
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
1412
{
15-
_github = new Github(GitHubUrl).WithLogger<Log4NetLog>();
16-
}
13+
protected Github Github;
1714

18-
[Test]
19-
public void GetUser_shouldReturnDeserialisedUserObject()
20-
{
21-
var response = _github.User().Get("sgrassie");
15+
protected string User;
2216

23-
Assert.That(response.Dynamic().login, Is.StringMatching("sgrassie"));
17+
public override void Context()
18+
{
19+
Github = new Github(GitHubUrl);
20+
}
2421
}
2522

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+
}
4255

4356
//[Test]
4457
//public void WithAuthenticationCallToMethodRequiringAuthenticationShouldBeSuccessful()

csharp-github-api.IntegrationTests/csharp-github-api.IntegrationTests.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<SpecificVersion>False</SpecificVersion>
6060
<HintPath>..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
6161
</Reference>
62+
<Reference Include="Should">
63+
<HintPath>..\packages\Should.1.1.12.0\lib\Should.dll</HintPath>
64+
</Reference>
6265
<Reference Include="StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
6366
<SpecificVersion>False</SpecificVersion>
6467
<HintPath>..\packages\structuremap.2.6.4.1\lib\net40\StructureMap.dll</HintPath>
@@ -93,11 +96,16 @@
9396
<DesignTime>True</DesignTime>
9497
<DependentUpon>TestResources.resx</DependentUpon>
9598
</Compile>
96-
<Compile Include="TestLogging.cs" />
99+
<Compile Include="Ext\TinySpec.cs" />
100+
<Compile Include="Ext\TestsSpecBase.cs" />
97101
<Compile Include="UsersTestsUnAuthenticated.cs" />
98102
<Compile Include="UsersTestsAuthenticated.cs" />
99103
</ItemGroup>
100104
<ItemGroup>
105+
<ProjectReference Include="..\csharp-github-api.Models\csharp-github-api.Models.csproj">
106+
<Project>{81AC5037-2479-4AFC-A159-095265306A66}</Project>
107+
<Name>csharp-github-api.Models</Name>
108+
</ProjectReference>
101109
<ProjectReference Include="..\csharp-github-api\csharp-github-api.csproj">
102110
<Project>{AC8795CC-BDFF-4D37-85EE-E17A7D5A8A59}</Project>
103111
<Name>csharp-github-api</Name>

csharp-github-api.IntegrationTests/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<package id="log4net" version="1.2.10" targetFramework="net40" />
66
<package id="NUnit" version="2.6.2" targetFramework="net40" />
77
<package id="RestSharp" version="104.1" targetFramework="net40" />
8+
<package id="Should" version="1.1.12.0" targetFramework="net40" />
89
<package id="structuremap" version="2.6.4.1" targetFramework="net40" />
910
<package id="this.Log" version="0.0.2.0" targetFramework="net40" />
1011
<package id="this.Log-log4net" version="0.0.2.0" targetFramework="net40" />
12+
<package id="TinySpec.NUnit" version="0.9.5" targetFramework="net40" />
1113
</packages>

0 commit comments

Comments
 (0)