|
| 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 | +} |
0 commit comments