|
1 | | -using System; |
| 1 | +using System.Threading.Tasks; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using GitHub.Models; |
3 | | -using GitHub.VisualStudio; |
4 | | -using LibGit2Sharp; |
| 4 | +using GitHub.Exports; |
| 5 | +using GitHub.Services; |
| 6 | +using GitHub.Primitives; |
5 | 7 | using NSubstitute; |
6 | | -using UnitTests; |
| 8 | +using LibGit2Sharp; |
7 | 9 | using NUnit.Framework; |
8 | | -using GitHub.Primitives; |
9 | | -using System.Collections.Generic; |
10 | | -using System.Threading.Tasks; |
11 | | -using GitHub.Exports; |
12 | 10 |
|
13 | | -//[Collection("PackageServiceProvider global data tests")] |
14 | 11 | public class LocalRepositoryModelTests : TestBaseClass |
15 | 12 | { |
16 | | - /**ITestOutputHelper output; |
17 | | -
|
18 | | - public LocalRepositoryModelTests(ITestOutputHelper output) |
19 | | - { |
20 | | - this.output = output; |
21 | | - }**/ |
22 | | - |
23 | | - static void SetupRepository(string sha) |
24 | | - { |
25 | | - var provider = Substitutes.ServiceProvider; |
26 | | - var gitservice = provider.GetGitService(); |
27 | | - var repo = Substitute.For<IRepository>(); |
28 | | - gitservice.GetRepository(Args.String).Returns(repo); |
29 | | - gitservice.GetLatestPushedSha(Args.String).Returns(Task.FromResult(sha)); |
30 | | - if (!String.IsNullOrEmpty(sha)) |
31 | | - { |
32 | | - var refs = Substitute.For<ReferenceCollection>(); |
33 | | - var refrence = Substitute.For<Reference>(); |
34 | | - refs.ReachableFrom(Arg.Any<IEnumerable<Reference>>(), Arg.Any<IEnumerable<Commit>>()).Returns(new Reference[] { refrence }); |
35 | | - repo.Refs.Returns(refs); |
36 | | - var commit = Substitute.For<Commit>(); |
37 | | - commit.Sha.Returns(sha); |
38 | | - repo.Commits.Returns(new FakeCommitLog { commit }); |
39 | | - } |
40 | | - } |
41 | | - |
42 | 13 | [TestCase(1, LinkType.Blob, false, "https://github.com/foo/bar", "123123", @"src\dir\file1.cs", -1, -1, "https://github.com/foo/bar/blob/123123/src/dir/file1.cs")] |
43 | 14 | [TestCase(2, LinkType.Blob, false, "https://github.com/foo/bar", "123123", @"src\dir\file1.cs", 1, -1, "https://github.com/foo/bar/blob/123123/src/dir/file1.cs#L1")] |
44 | 15 | [TestCase(3, LinkType.Blob, false, "https://github.com/foo/bar", "123123", @"src\dir\file1.cs", 1, 1, "https://github.com/foo/bar/blob/123123/src/dir/file1.cs#L1")] |
@@ -71,18 +42,38 @@ public async Task GenerateUrl(int testid, LinkType linkType, bool createRootedPa |
71 | 42 | { |
72 | 43 | using (var temp = new TempDirectory()) |
73 | 44 | { |
74 | | - SetupRepository(sha); |
| 45 | + var gitService = CreateGitService(sha); |
75 | 46 |
|
76 | 47 | var basePath = temp.Directory.CreateSubdirectory("generate-url-test1-" + testid); |
77 | 48 | if (createRootedPath && path != null) |
78 | 49 | path = System.IO.Path.Combine(basePath.FullName, path); |
79 | 50 | ILocalRepositoryModel model = null; |
80 | | - if (!String.IsNullOrEmpty(baseUrl)) |
81 | | - model = new LocalRepositoryModel("bar", new UriString(baseUrl), basePath.FullName); |
| 51 | + if (!string.IsNullOrEmpty(baseUrl)) |
| 52 | + model = new LocalRepositoryModel("bar", new UriString(baseUrl), basePath.FullName, gitService); |
82 | 53 | else |
83 | | - model = new LocalRepositoryModel(basePath.FullName); |
| 54 | + model = new LocalRepositoryModel(basePath.FullName, gitService); |
84 | 55 | var result = await model.GenerateUrl(linkType, path, startLine, endLine); |
85 | 56 | Assert.That(expected, Is.EqualTo(result?.ToString())); |
86 | 57 | } |
87 | 58 | } |
| 59 | + |
| 60 | + static IGitService CreateGitService(string sha) |
| 61 | + { |
| 62 | + var gitservice = Substitute.For<IGitService>(); |
| 63 | + var repo = Substitute.For<IRepository>(); |
| 64 | + gitservice.GetRepository(Args.String).Returns(repo); |
| 65 | + gitservice.GetLatestPushedSha(Args.String).Returns(Task.FromResult(sha)); |
| 66 | + if (!string.IsNullOrEmpty(sha)) |
| 67 | + { |
| 68 | + var refs = Substitute.For<ReferenceCollection>(); |
| 69 | + var refrence = Substitute.For<Reference>(); |
| 70 | + refs.ReachableFrom(Arg.Any<IEnumerable<Reference>>(), Arg.Any<IEnumerable<Commit>>()).Returns(new Reference[] { refrence }); |
| 71 | + repo.Refs.Returns(refs); |
| 72 | + var commit = Substitute.For<Commit>(); |
| 73 | + commit.Sha.Returns(sha); |
| 74 | + repo.Commits.Returns(new FakeCommitLog { commit }); |
| 75 | + } |
| 76 | + |
| 77 | + return gitservice; |
| 78 | + } |
88 | 79 | } |
0 commit comments