Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegrationTests\UpdateVerb #193

Open
wants to merge 6 commits into
base: release/v0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions GitDepend.IntegrationTests/GitDepend.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<Name>GitDepend</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="TestData\NewStringUtils.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
77 changes: 65 additions & 12 deletions GitDepend.IntegrationTests/Scenarios/HelpPageScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ namespace GitDepend.IntegrationTests.Scenarios
/// </summary>
public class HelpPageScenario : TestFixtureBase
{
private string _path;
private string _lib2Dir;
private string _lib1Dir;

[TestFixtureSetUp]
public void CloneLib2Repo()
{
_path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

//Clone Repo
_lib2Dir = Path.Combine(_path, Lib2Name);
_lib1Dir = Path.Combine(_path, Lib1Name);
Clone(Lib2Url, _lib2Dir);
}

[TearDown]
public void CleanUpLib1Directory()
{
SafeDeleteDirectory(_lib1Dir);
}

[TestFixtureTearDown]
public void CleanUpDirectory()
{
SafeDeleteDirectory(_path);
}

[Test]
public void HelpVerb_Returns_Success()
{
Expand All @@ -30,21 +57,47 @@ public void InvalidVerb_Returns_InvalidCommand()
[Test]
public void CloneVerb_ShouldCloneAllRepos()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all in the HelpPageScenario, which should focus only on Help page work flows. You should create a new Scenario file for Cloning.

{
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var lib2Dir = Path.Combine(path, Lib2Name);
var lib1Dir = Path.Combine(path, Lib2Name);
Clone(Lib2Url, lib2Dir);
var info = GitDepend("clone", _lib2Dir);

var info = GitDepend("clone", lib2Dir);
var lib1Exists = Directory.Exists(_lib1Dir);
var lib2Exists = Directory.Exists(_lib2Dir);

var lib1Exists = Directory.Exists(lib1Dir);
var lib2Exists = Directory.Exists(lib2Dir);

SafeDeleteDirectory(path);
Assert.AreEqual(ReturnCode.Success, info.ReturnCode, "Return Code was Wrong");
Assert.IsTrue(lib1Exists, "Lib1 Doesn't Exists");
Assert.IsTrue(lib2Exists, "Lib2 Doesn't Exists");
}

Assert.AreEqual(ReturnCode.Success, info.ReturnCode);
Assert.IsTrue(lib1Exists);
Assert.IsTrue(lib2Exists);

[Test]
public void UpdateVerb_CloneReposChangeLib1_ShouldUpdateArtifacts()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all in the HelpPageScenario, which should focus only on Help page work flows. You should create a new Scenario file for Updating.

{
//Clone Verb
var cloneVerbInfo = GitDepend("clone", _lib2Dir);

var lib1Exists = Directory.Exists(_lib1Dir);
var lib2Exists = Directory.Exists(_lib2Dir);

Assert.AreEqual(ReturnCode.Success, cloneVerbInfo.ReturnCode, $"Return Code was Wrong - Error: {cloneVerbInfo.StandardError}");
Assert.IsTrue(lib1Exists, "Lib1 Doesn't Exists");
Assert.IsTrue(lib2Exists, "Lib2 Doesn't Exists");

//Change Lib1
var updated = UpdateFile(_lib1Dir, $"{Lib1Name}\\StringUtils.cs", "TestData\\NewStringUtils.txt");

//Update Verb
var updateVerbInfo = GitDepend("update", _lib2Dir);

//Check For new Artifacts from Lib1
var lib1ArtifactsExists = File.Exists(Path.Combine(_lib1Dir, "artifacts/NuGet/Debug/Lib1.0.1.0.nupkg"));

//Clean up
SafeDeleteDirectory(_lib1Dir);

Assert.IsTrue(updated, "Unable to update file");
Assert.AreEqual(ReturnCode.Success, updateVerbInfo.ReturnCode, $"Return Code was Wrong - Error: {updateVerbInfo.StandardError}");
Assert.IsTrue(lib1ArtifactsExists, "Artifacts don't exists");
}

}
}
}
26 changes: 26 additions & 0 deletions GitDepend.IntegrationTests/TestData/NewStringUtils.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lib1
{
public class StringUtils
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indentation change intentional? If this is the change, I would prefer something else. This kind of indentation stuff is a pet peeve.

{
public static string Trim(string str)
{
return str.Trim();
}

public static string TrimEnd(string str)
{
return str.TrimEnd();
}

public static string TrimStart(string str)
{
return str.TrimStart();
}
}
}
21 changes: 21 additions & 0 deletions GitDepend.IntegrationTests/TestFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,26 @@ protected void SafeDeleteDirectory(string path)
// ignored
}
}

/// <summary>
/// Writes the text from ReplaceFile into SourceFile
/// </summary>
/// <param name="workdirPath"></param>
/// <param name="sourcefile"></param>
/// <param name="replaceFile"></param>
/// <returns>Update File was successful</returns>
protected bool UpdateFile(string workdirPath, string sourcefile, string replaceFile)
{
if (!Directory.Exists(workdirPath))
return false;

if (!File.Exists(Path.Combine(workdirPath, sourcefile)))
return false;

var path = Path.Combine(workdirPath, sourcefile);
File.WriteAllText(path, File.ReadAllText(replaceFile));

return true;
}
}
}