Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit fc55a67

Browse files
committed
Add unit tests for SimpleApiClientFactory
1 parent 56ef142 commit fc55a67

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using GitHub.Api;
3+
using GitHub.Primitives;
4+
using GitHub.Services;
5+
using GitHub.VisualStudio;
6+
using NSubstitute;
7+
using Xunit;
8+
9+
public class SimpleApiClientFactoryTests
10+
{
11+
public class TheCreateMethod
12+
{
13+
[Fact]
14+
public void CreatesNewInstanceOfSimpleApiClient()
15+
{
16+
var program = new Program();
17+
var enterpriseProbe = Substitute.For<IEnterpriseProbeTask>();
18+
var wikiProbe = Substitute.For<IWikiProbe>();
19+
var factory = new SimpleApiClientFactory(
20+
program,
21+
new Lazy<IEnterpriseProbeTask>(() => enterpriseProbe),
22+
new Lazy<IWikiProbe>(() => wikiProbe));
23+
24+
var client = factory.Create("https://github.com/github/visualstudio");
25+
26+
Assert.Equal("https://github.com/github/visualstudio", client.OriginalUrl);
27+
Assert.Equal(HostAddress.GitHubDotComHostAddress, client.HostAddress);
28+
Assert.Same(client, factory.Create("https://github.com/github/visualstudio")); // Tests caching.
29+
}
30+
}
31+
32+
public class TheClearFromCacheMethod
33+
{
34+
[Fact]
35+
public void RemovesClientFromCache()
36+
{
37+
var program = new Program();
38+
var enterpriseProbe = Substitute.For<IEnterpriseProbeTask>();
39+
var wikiProbe = Substitute.For<IWikiProbe>();
40+
var factory = new SimpleApiClientFactory(
41+
program,
42+
new Lazy<IEnterpriseProbeTask>(() => enterpriseProbe),
43+
new Lazy<IWikiProbe>(() => wikiProbe));
44+
45+
var client = factory.Create("https://github.com/github/visualstudio");
46+
factory.ClearFromCache(client);
47+
48+
Assert.NotSame(client, factory.Create("https://github.com/github/visualstudio"));
49+
}
50+
}
51+
}

src/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
</ItemGroup>
136136
<ItemGroup>
137137
<Compile Include="Args.cs" />
138+
<Compile Include="GitHub.App\Api\SimpleApiClientFactoryTests.cs" />
138139
<Compile Include="GitHub.App\Api\SimpleApiClientTests.cs" />
139140
<Compile Include="GitHub.App\Caches\ImageCacheTests.cs" />
140141
<Compile Include="GitHub.App\Models\ModelServiceTests.cs" />

0 commit comments

Comments
 (0)