Skip to content

Commit 2b89752

Browse files
committed
Check exceptions
1 parent 5b3233f commit 2b89752

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
namespace ServiceControlInstaller.Engine.UnitTests.Setup;
22

3+
using System;
34
using Engine.Setup;
45
using NUnit.Framework;
56

67
[TestFixture]
78
public class SetupInstanceTests
89
{
910
[Test]
10-
public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", false));
11+
public void Should_not_throw_on_0_exit_code() => Assert.DoesNotThrow(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", ""));
12+
13+
[Test]
14+
public void Should_capture_and_rethrow_failures()
15+
{
16+
var ex = Assert.Throws<Exception>(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "fail"));
17+
18+
Assert.That(ex.Message, Does.Contain("Fake exception"));
19+
}
1120
}

src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void Run(IMonitoringInstance instance) =>
2525
instance.Name,
2626
instance.SkipQueueCreation);
2727

28-
internal static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation)
28+
static void Run(string installPath, string exeName, string instanceName, bool skipQueueCreation)
2929
{
3030
var args = $"--setup";
3131

@@ -34,6 +34,11 @@ internal static void Run(string installPath, string exeName, string instanceName
3434
args += " --skip-queue-creation";
3535
}
3636

37+
Run(installPath, exeName, instanceName, args);
38+
}
39+
40+
internal static void Run(string installPath, string exeName, string instanceName, string args)
41+
{
3742
var processStartupInfo = new ProcessStartInfo
3843
{
3944
CreateNoWindow = true,

src/SetupProcessFake/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
Console.WriteLine("Hello, World!");
1+
if (args.Any(a => a == "fail"))
2+
{
3+
throw new Exception("Fake exception");
4+
}

0 commit comments

Comments
 (0)