public async Task Puzzle_Solve_Returns_Correct_Value_Based_On_Args_Length() { // Arrange string[] args = new[] { "1" }; var cancellationToken = CancellationToken.None; var target = new MyPuzzle(2) { Logger = Logger, }; // Act and Assert await Assert.ThrowsAsync <PuzzleException>(() => target.SolveAsync(args, cancellationToken)); // Arrange args = Array.Empty <string>(); target = new MyPuzzle(1); // Act and Assert await Assert.ThrowsAsync <PuzzleException>(() => target.SolveAsync(args, cancellationToken)); // Arrange target = new MyPuzzle(0); // Act PuzzleResult actual = await target.SolveAsync(args, cancellationToken); // Assert actual.ShouldNotBeNull(); actual.Solutions.ShouldNotBeNull(); actual.Solutions.Count.ShouldBe(1); actual.Solutions[0].ShouldBe(42); target.Answer.ShouldBe(42); }
/// <summary> /// Solves the specified puzzle type with the specified arguments asynchronously. /// </summary> /// <typeparam name="T">The type of the puzzle to solve.</typeparam> /// <param name="args">The arguments to pass to the puzzle.</param> /// <returns> /// The solved puzzle of the type specified by <typeparamref name="T"/>. /// </returns> protected async Task <T> SolvePuzzleAsync <T>(params string[] args) where T : Puzzle, new() { // Arrange var puzzle = new T() { Logger = Logger, Verbose = true, }; using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90)); // Act PuzzleResult result = await puzzle.SolveAsync(args, cts.Token); // Assert result.ShouldNotBeNull(); result.Solutions.ShouldNotBeNull(); result.Solutions.Count.ShouldBeGreaterThan(0); return(puzzle); }