This commit is contained in:
Keith Dahlby 2013-11-20 15:52:21 -06:00
Родитель e3108d4153
Коммит b8dc66023e
4 изменённых файлов: 49 добавлений и 7 удалений

Просмотреть файл

@ -80,7 +80,7 @@
<Compile Include="CleanFixture.cs" />
<Compile Include="CurrentOperationFixture.cs" />
<Compile Include="MetaFixture.cs" />
<Compile Include="MockedRepositoryFixture.cs" />
<Compile Include="MockingFixture.cs" />
<Compile Include="ConfigurationFixture.cs" />
<Compile Include="AttributesFixture.cs" />
<Compile Include="CommitAncestorFixture.cs" />

Просмотреть файл

@ -7,11 +7,12 @@ using Xunit;
namespace LibGit2Sharp.Tests
{
// This fixture shows how one can mock the IRepository when writing an application against LibGit2Sharp.
// The application we want to test is simulated by the CommitCounter class (see below), which takes an IRepository,
// and whose role is to compute and return the number of commits in the given repository.
public class MockedRepositoryFixture : BaseFixture
// This fixture shows how one can mock various LibGit2Sharp APIs.
public class MockingFixture : BaseFixture
{
// The application we want to test is simulated by the CommitCounter class (see below), which takes an IRepository,
// and whose role is to compute and return the number of commits in the given repository.
// In this test, we pass to CommitCounter a concrete instance of the Repository. It means we will end up calling the concrete Repository
// during the test run.
[Fact]
@ -67,5 +68,42 @@ namespace LibGit2Sharp.Tests
get { return repo.Commits.Count(); }
}
}
[Fact]
public void CanFakeConfigurationBuildSignature()
{
var name = "name";
var email = "email";
var now = DateTimeOffset.UtcNow;
var fakeConfig = new Mock<Configuration>();
fakeConfig.Setup(c => c.BuildSignature(now))
.Returns<DateTimeOffset>(t => new Signature(name, email, t));
var sig = fakeConfig.Object.BuildSignature(now);
Assert.Equal(name, sig.Name);
Assert.Equal(email, sig.Email);
Assert.Equal(now, sig.When);
}
[Fact]
public void CanFakeEnumerationOfConfiguration()
{
var fakeConfig = new Mock<Configuration>();
fakeConfig.Setup(c => c.GetEnumerator()).Returns(FakeEntries);
Assert.Equal(2, fakeConfig.Object.Count());
}
private static IEnumerator<ConfigurationEntry<string>> FakeEntries()
{
yield return FakeConfigurationEntry("foo", "bar", ConfigurationLevel.Local);
yield return FakeConfigurationEntry("baz", "quux", ConfigurationLevel.Global);
}
private static ConfigurationEntry<string> FakeConfigurationEntry(string key, string value, ConfigurationLevel level)
{
return new Mock<ConfigurationEntry<string>>(key, value, level).Object;
}
}
}

Просмотреть файл

@ -284,7 +284,11 @@ namespace LibGit2Sharp
{ typeof(string), GetUpdater<string>(Proxy.git_config_set_string) },
};
IEnumerator<ConfigurationEntry<string>> IEnumerable<ConfigurationEntry<String>>.GetEnumerator()
/// <summary>
/// Returns an enumerator that iterates through the configuration entries.
/// </summary>
/// <returns>An <see cref="IEnumerator{T}"/> object that can be used to iterate through the configuration entries.</returns>
public virtual IEnumerator<ConfigurationEntry<string>> GetEnumerator()
{
return BuildConfigEntries().GetEnumerator();
}

Просмотреть файл

@ -37,7 +37,7 @@ namespace LibGit2Sharp
/// <param name="key">The option name</param>
/// <param name="value">The option value</param>
/// <param name="level">The origin store</param>
internal ConfigurationEntry(string key, T value, ConfigurationLevel level)
protected internal ConfigurationEntry(string key, T value, ConfigurationLevel level)
{
Key = key;
Value = value;