|
7 | 7 |
|
8 | 8 | namespace LibGit2Sharp.Tests
|
9 | 9 | {
|
10 |
| - // This fixture shows how one can mock the IRepository when writing an application against LibGit2Sharp. |
11 |
| - // The application we want to test is simulated by the CommitCounter class (see below), which takes an IRepository, |
12 |
| - // and whose role is to compute and return the number of commits in the given repository. |
13 |
| - public class MockedRepositoryFixture : BaseFixture |
| 10 | + // This fixture shows how one can mock various LibGit2Sharp APIs. |
| 11 | + public class MockingFixture : BaseFixture |
14 | 12 | {
|
| 13 | + // The application we want to test is simulated by the CommitCounter class (see below), which takes an IRepository, |
| 14 | + // and whose role is to compute and return the number of commits in the given repository. |
| 15 | + |
15 | 16 | // In this test, we pass to CommitCounter a concrete instance of the Repository. It means we will end up calling the concrete Repository
|
16 | 17 | // during the test run.
|
17 | 18 | [Fact]
|
@@ -67,5 +68,42 @@ public int NumberOfCommits
|
67 | 68 | get { return repo.Commits.Count(); }
|
68 | 69 | }
|
69 | 70 | }
|
| 71 | + |
| 72 | + [Fact] |
| 73 | + public void CanFakeConfigurationBuildSignature() |
| 74 | + { |
| 75 | + var name = "name"; |
| 76 | + var email = "email"; |
| 77 | + var now = DateTimeOffset.UtcNow; |
| 78 | + |
| 79 | + var fakeConfig = new Mock<Configuration>(); |
| 80 | + fakeConfig.Setup(c => c.BuildSignature(now)) |
| 81 | + .Returns<DateTimeOffset>(t => new Signature(name, email, t)); |
| 82 | + |
| 83 | + var sig = fakeConfig.Object.BuildSignature(now); |
| 84 | + Assert.Equal(name, sig.Name); |
| 85 | + Assert.Equal(email, sig.Email); |
| 86 | + Assert.Equal(now, sig.When); |
| 87 | + } |
| 88 | + |
| 89 | + [Fact] |
| 90 | + public void CanFakeEnumerationOfConfiguration() |
| 91 | + { |
| 92 | + var fakeConfig = new Mock<Configuration>(); |
| 93 | + fakeConfig.Setup(c => c.GetEnumerator()).Returns(FakeEntries); |
| 94 | + |
| 95 | + Assert.Equal(2, fakeConfig.Object.Count()); |
| 96 | + } |
| 97 | + |
| 98 | + private static IEnumerator<ConfigurationEntry<string>> FakeEntries() |
| 99 | + { |
| 100 | + yield return FakeConfigurationEntry("foo", "bar", ConfigurationLevel.Local); |
| 101 | + yield return FakeConfigurationEntry("baz", "quux", ConfigurationLevel.Global); |
| 102 | + } |
| 103 | + |
| 104 | + private static ConfigurationEntry<string> FakeConfigurationEntry(string key, string value, ConfigurationLevel level) |
| 105 | + { |
| 106 | + return new Mock<ConfigurationEntry<string>>(key, value, level).Object; |
| 107 | + } |
70 | 108 | }
|
71 | 109 | }
|
0 commit comments