Skip to content

Commit e9662c6

Browse files
sergiorykovJakeGinnivan
authored andcommitted
Test ThrowsExceptionOnAmbigousConfigFileLocation verifies WarningException contains expected message
1 parent ed678e4 commit e9662c6

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
using GitVersion;
2+
using GitVersion.Helpers;
3+
using NUnit.Framework;
4+
using Shouldly;
15
using System;
26
using System.ComponentModel;
37
using System.IO;
48
using System.Linq;
59
using System.Reflection;
610
using System.Runtime.CompilerServices;
7-
using GitVersion;
8-
using GitVersion.Helpers;
9-
using NUnit.Framework;
10-
using Shouldly;
1111
using YamlDotNet.Serialization;
1212

1313
[TestFixture]
@@ -118,7 +118,7 @@ public void CanProvideConfigForNewBranch()
118118
tag: bugfix";
119119
SetupConfigFileContent(text);
120120
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
121-
121+
122122
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
123123
}
124124

@@ -151,7 +151,7 @@ public void NextVersionCanHavePatch()
151151

152152
config.NextVersion.ShouldBe("2.12.654651698");
153153
}
154-
154+
155155
[Test]
156156
[NUnit.Framework.Category("NoMono")]
157157
[NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
@@ -273,12 +273,13 @@ public void WarnOnAmbigousConfigFilesAtTheSameProjectRootDirectory(string path)
273273
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
274274
public void ThrowsExceptionOnAmbigousConfigFileLocation(string repoConfigFile, string workingConfigFile)
275275
{
276-
SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
277-
SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);
276+
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
277+
var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);
278+
279+
WarningException exception = Should.Throw<WarningException>(() => { ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); });
278280

279-
Should.Throw<WarningException>(() => {
280-
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);
281-
});
281+
var expecedMessage = string.Format("Ambigous config file selection from '{0}' and '{1}'", workingDirectoryConfigFilePath, repositoryConfigFilePath);
282+
exception.Message.ShouldBe(expecedMessage);
282283
}
283284

284285
[Test]
@@ -295,13 +296,16 @@ public void NoWarnOnGitVersionYmlFile()
295296
s.Length.ShouldBe(0);
296297
}
297298

298-
void SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName)
299+
string SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName)
299300
{
300-
SetupConfigFileContent(text, fileName, repoPath);
301+
return SetupConfigFileContent(text, fileName, repoPath);
301302
}
302303

303-
void SetupConfigFileContent(string text, string fileName, string path)
304+
string SetupConfigFileContent(string text, string fileName, string path)
304305
{
305-
fileSystem.WriteAllText(Path.Combine(path, fileName), text);
306+
var fullPath = Path.Combine(path, fileName);
307+
fileSystem.WriteAllText(fullPath, text);
308+
309+
return fullPath;
306310
}
307-
}
311+
}

0 commit comments

Comments
 (0)