Skip to content

Commit

Permalink
Added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akamsteeg committed Sep 4, 2017
1 parent 1c9553e commit d5e4bad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/AtleX.CommandLineArguments.Tests/CommandLineArgumentsTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using AtleX.CommandLineArguments.Tests.Mocks;
using NUnit.Framework;
using System;
using AtleX.CommandLineArguments.Validators;
using System.Collections.Generic;

namespace AtleX.CommandLineArguments.Tests
{
Expand All @@ -12,15 +10,33 @@ public class CommandLineArgumentsTests
[Test]
public void TryParse_ArgumentsNull_Throws()
{
Assert.Throws<ArgumentNullException>(() => CommandLineArguments.TryParse<TestArguments>(null, out TestArguments a));
Assert.Throws<ArgumentNullException>(() => CommandLineArguments.TryParse<TestArguments>(null, out _));
}

[Test]
public void TryParse_WithoutConfiguration_Throws()
{
var oldConfig = CommandLineArguments.Configuration;

CommandLineArguments.Configuration = null;

Assert.Throws<InvalidOperationException>(() => CommandLineArguments.TryParse<TestArguments>(new string[0], out TestArguments a));
Assert.Throws<InvalidOperationException>(() => CommandLineArguments.TryParse<TestArguments>(new string[0], out _));

CommandLineArguments.Configuration = oldConfig; // The beauty of static, we need to restore the configuration
}

[Test]
public void TryParse_WithEmptyArgumentsAndDefaultConfiguration_Succeeds()
{
Assert.DoesNotThrow(() => CommandLineArguments.TryParse<TestArguments>(new string[0], out _));
}

[Test]
public void TryParse_WithUnknownArgumentsAndDefaultConfiguration_Succeeds()
{
var cliArgs = new string[] { "lorem", "ipsum" };

Assert.DoesNotThrow(() => CommandLineArguments.TryParse<TestArguments>(cliArgs, out _));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using AtleX.CommandLineArguments.Validators;
using AtleX.CommandLineArguments.Parsers.TypeParsers;
using System.Linq;

namespace AtleX.CommandLineArguments.Tests.Parsers
{
Expand Down Expand Up @@ -60,8 +61,10 @@ public void CommandLineArgumentsTryParse_ValidArguments()

var arguments = CreateValidArguments();

var result = CommandLineArguments.TryParse<TestArguments>(arguments, out TestArguments parsedArguments);
var result = CommandLineArguments.TryParse<TestArguments>(arguments, out var parsedArguments, out var validationErrors);

Assert.IsTrue(result);
Assert.IsFalse(validationErrors.Any());
AssertValidArguments(parsedArguments);
}

Expand Down

0 comments on commit d5e4bad

Please sign in to comment.