Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
470 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using System; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Web; | ||
using Kudu.Contracts.Settings; | ||
using Kudu.Contracts.Tracing; | ||
using Kudu.Core.SourceControl; | ||
using Kudu.Core.Tracing; | ||
using Moq; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Kudu.Core.Test | ||
{ | ||
public class NullRepositoryFacts | ||
{ | ||
[Theory] | ||
[InlineData("wwwroot", null, "1")] | ||
[InlineData("repository", null, "0")] | ||
[InlineData("dummy", "dummy", "1")] | ||
[InlineData("dummy", "dummy", null)] | ||
public void NullRepositoryPathTests(string expected, string repositoryPath, string noRepository) | ||
{ | ||
// arrange | ||
var settings = MockSettings(repositoryPath, noRepository); | ||
|
||
// Assert | ||
Assert.Equal(expected, settings.Object.GetRepositoryPath()); | ||
} | ||
|
||
[Fact] | ||
public void NullRepositoryCommitTests() | ||
{ | ||
// arrange | ||
var settings = MockSettings(); | ||
var environment = MockEnviroment(@"x:\site", settings.Object); | ||
var traceFactory = MockTraceFactory(); | ||
var httpContext = MockHttpContext(); | ||
|
||
// test | ||
var repository = new NullRepository(environment.Object, traceFactory.Object, httpContext.Object); | ||
|
||
// Assert | ||
Assert.Equal(RepositoryType.None, repository.RepositoryType); | ||
Assert.Equal(environment.Object.RepositoryPath, repository.RepositoryPath); | ||
Assert.Null(repository.CurrentId); | ||
Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("dummy")); | ||
Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("master")); | ||
|
||
// Simple commit | ||
var message = "this is testing"; | ||
var author = "john doe"; | ||
var email = "john.doe@live.com"; | ||
var success = repository.Commit(message, author + " <" + email + ">"); | ||
|
||
// Assert | ||
Assert.True(success); | ||
Assert.NotNull(repository.CurrentId); | ||
|
||
// Validate changeset | ||
var changeSet = repository.GetChangeSet(repository.CurrentId); | ||
|
||
// Assert | ||
Assert.NotNull(changeSet); | ||
Assert.Equal(message, changeSet.Message); | ||
Assert.Equal(author, changeSet.AuthorName); | ||
Assert.Equal(email, changeSet.AuthorEmail); | ||
Assert.True(changeSet.IsReadOnly); | ||
Assert.Equal(repository.CurrentId, changeSet.Id); | ||
Assert.Throws<InvalidOperationException>(() => repository.GetChangeSet("dummy")); | ||
Assert.Same(changeSet, repository.GetChangeSet("master")); | ||
Assert.Same(changeSet, repository.GetChangeSet(repository.CurrentId)); | ||
} | ||
|
||
private Mock<IDeploymentSettingsManager> MockSettings(string repositoryPath = null, string noRepository = "1") | ||
{ | ||
var settings = new Mock<IDeploymentSettingsManager>(MockBehavior.Strict); | ||
|
||
// setup | ||
settings.Setup(s => s.GetValue(SettingsKeys.RepositoryPath, false)) | ||
.Returns(repositoryPath); | ||
settings.Setup(s => s.GetValue(SettingsKeys.NoRepository, false)) | ||
.Returns(noRepository); | ||
|
||
return settings; | ||
} | ||
|
||
private Mock<IEnvironment> MockEnviroment(string sitePath, IDeploymentSettingsManager settings) | ||
{ | ||
var environment = new Mock<IEnvironment>(MockBehavior.Strict); | ||
|
||
// setup | ||
environment.SetupGet(e => e.RepositoryPath) | ||
.Returns(() => Path.Combine(sitePath, settings.GetRepositoryPath())); | ||
|
||
return environment; | ||
} | ||
|
||
private Mock<ITraceFactory> MockTraceFactory() | ||
{ | ||
var traceFactory = new Mock<ITraceFactory>(MockBehavior.Strict); | ||
|
||
// setup | ||
traceFactory.Setup(t => t.GetTracer()) | ||
.Returns(Mock.Of<ITracer>()); | ||
|
||
return traceFactory; | ||
} | ||
|
||
private Mock<HttpContextBase> MockHttpContext() | ||
{ | ||
var httpContext = new Mock<HttpContextBase>(MockBehavior.Strict); | ||
|
||
// setup | ||
httpContext.SetupGet(c => c.Items) | ||
.Returns(new Hashtable()); | ||
|
||
return httpContext; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
using System; | ||
using System.Web; | ||
using Kudu.Contracts.Settings; | ||
using Kudu.Core.SourceControl; | ||
using Kudu.Core.SSHKey; | ||
using Kudu.Core.Tracing; | ||
using Moq; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Kudu.Core.Test | ||
{ | ||
public class RepositoryFactoryFacts | ||
{ | ||
[Theory] | ||
[InlineData(RepositoryType.Git, false, true, "Expected a 'Git' repository but found a 'Mercurial' repository at path ''.")] | ||
[InlineData(RepositoryType.Mercurial, true, false, "Expected a 'Mercurial' repository but found a 'Git' repository at path ''.")] | ||
public void EnsuringGitRepositoryThrowsIfDifferentRepositoryAlreadyExists(RepositoryType repoType, bool isGit, bool isMercurial, string message) | ||
[Fact] | ||
public void EnsuringGitRepositoryThrowsIfDifferentRepositoryAlreadyExists() | ||
{ | ||
// Arrange | ||
var repoFactory = new Mock<RepositoryFactory>(Mock.Of<IEnvironment>(), Mock.Of<IDeploymentSettingsManager>(), Mock.Of<ITraceFactory>()) { CallBase = true }; | ||
repoFactory.SetupGet(f => f.IsGitRepository) | ||
.Returns(isGit); | ||
repoFactory.SetupGet(f => f.IsHgRepository) | ||
.Returns(isMercurial); | ||
|
||
// Act and Assert | ||
var ex = Assert.Throws<InvalidOperationException>(() => repoFactory.Object.EnsureRepository(repoType)); | ||
foreach (RepositoryType repoType in Enum.GetValues(typeof(RepositoryType))) | ||
{ | ||
foreach (RepositoryType currentType in Enum.GetValues(typeof(RepositoryType))) | ||
{ | ||
if (repoType == currentType) | ||
{ | ||
continue; | ||
} | ||
|
||
Assert.Equal(message, ex.Message); | ||
// Arrange | ||
var repoFactory = new Mock<RepositoryFactory>(Mock.Of<IEnvironment>(), Mock.Of<IDeploymentSettingsManager>(), Mock.Of<ITraceFactory>(), Mock.Of<HttpContextBase>()) { CallBase = true }; | ||
repoFactory.SetupGet(f => f.IsNullRepository) | ||
.Returns(currentType == RepositoryType.None); | ||
repoFactory.SetupGet(f => f.IsGitRepository) | ||
.Returns(currentType == RepositoryType.Git); | ||
repoFactory.SetupGet(f => f.IsHgRepository) | ||
.Returns(currentType == RepositoryType.Mercurial); | ||
|
||
// Act and Assert | ||
var ex = Assert.Throws<InvalidOperationException>(() => repoFactory.Object.EnsureRepository(repoType)); | ||
|
||
Assert.Equal(String.Format("Expected a '{0}' repository but found a '{1}' repository at path ''.", repoType, currentType), ex.Message); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.