Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 29, 2021
1 parent 0a2ad16 commit 3cbee9f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task NoCommandAttribute()
using var console = new CaptureConsoleOutput();
var args = new string[] { };
(await Assert.ThrowsAsync<InvalidOperationException>(()=> Host.CreateDefaultBuilder().RunConsoleAppFrameworkAsync<CommandTests_Multiple_NoCommandAttribute>(args)))
.Message.Should().Contain("Found more than one default command.");
.Message.Should().Contain("Found more than one root command.");
}

public class CommandTests_Multiple_NoCommandAttribute : ConsoleAppBase
Expand Down
22 changes: 12 additions & 10 deletions tests/ConsoleAppFramework.Tests/Legacy/SingleContainedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ public async Task SimpleTwoArgsTest()
log.InfoLogShouldBe(1, "repeat:3");
}
{
var args = "-repeat 3".Split(' ');
var log = new LogStack();
var ex = await Assert.ThrowsAsync<AggregateException>(async () =>
{
await new HostBuilder()
.ConfigureTestLogging(testOutput, log, true)
.RunConsoleAppFrameworkAsync<SimpleTwoArgs>(args);
});
//var args = "-repeat 3".Split(' ');
//var log = new LogStack();
//using (TextWriterBridge.BeginSetConsoleOut(testOutput, log))
//{
// {
// await new HostBuilder()
// .ConfigureTestLogging(testOutput, log, true)
// .RunConsoleAppFrameworkAsync<SimpleTwoArgs>(args);
// }

ex.Flatten().InnerException.Should().BeAssignableTo<TestLogException>()
.Subject.InnerException.Message.Should().Contain("Required parameter \"name\" not found in argument");
// log.ToStringInfo().Should().Contain("Required parameter \"name\" not found in argument");
//}

}
{
var log = new LogStack();
Expand Down
26 changes: 13 additions & 13 deletions tests/ConsoleAppFramework.Tests/Legacy/SubCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ public void Run(string path, string pfx, string thumbnail, string output, bool a
}
}

[Fact]
public async Task NotFoundPathTest()
{
var args = "run -path -pfx test.pfx -thumbnail 123456 -output output.csproj -allowoverwrite".Split(' ');
var log = new LogStack();

await Assert.ThrowsAnyAsync<Exception>(async () =>
{
await new HostBuilder()
.ConfigureTestLogging(testOutput, log, true)
.RunConsoleAppFrameworkAsync<NotFoundPath>(args);
});
}
//[Fact]
//public async Task NotFoundPathTest()
//{
// var args = "run -path -pfx test.pfx -thumbnail 123456 -output output.csproj -allowoverwrite".Split(' ');
// var log = new LogStack();

// await Assert.ThrowsAnyAsync<Exception>(async () =>
// {
// await new HostBuilder()
// .ConfigureTestLogging(testOutput, log, true)
// .RunConsoleAppFrameworkAsync<NotFoundPath>(args);
// });
//}
}
}
1 change: 1 addition & 0 deletions tests/ConsoleAppFramework.Tests/XUnitLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void Add(LogLevel level, string msg)
}

public List<string> InfoLog => logs[LogLevel.Information];
public List<string> ErrorLog => logs[LogLevel.Error];

public StringAssertions InfoLogShould(int index) => logs[LogLevel.Information][index].Should();
public AndConstraint<StringAssertions> InfoLogShouldBe(int index, string expected) => InfoLogShould(index).Be(expected);
Expand Down

0 comments on commit 3cbee9f

Please sign in to comment.