public async Task ExecuteAsync_MethodReturnsAsyncInt_ReturnCodeIsCorrect() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var executor = new CliActionExecutor(serviceProvider); var context = CreateTestContext(nameof(ActionExecutorTestClass.ExecuteWithIntAsync)); // Act await executor.ExecuteAsync(context); // Assert context.ReturnCode .Should() .Be(ActionExecutorTestClass.AsyncIntReturnCode); }
public async Task ExecuteAsync_MethodReturnsNull_ThrowsException() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var executor = new CliActionExecutor(serviceProvider); var context = CreateTestContext(nameof(ActionExecutorTestClass.ExecuteNull)); // Act Func <Task> act = async() => await executor.ExecuteAsync(context); // Assert await act .Should() .ThrowAsync <ActionReturnValueNullException>(); }
public async Task ExecuteAsync_MethodReturnsInvalidResult_ThrowsException() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var executor = new CliActionExecutor(serviceProvider); var context = CreateTestContext(nameof(ActionExecutorTestClass.ExecuteInvalidReturnType)); // Act Func <Task> act = async() => await executor.ExecuteAsync(context); // Assert (await act .Should() .ThrowAsync <ActionReturnTypeNotSupportedException>()) .Which.ReturnType .Should() .Be <string>(); }
public async Task ExecuteAsync_MethodReturnsVoid_ReturnCodeIsCorrect() { const int expectedReturnCode = 8765; var serviceProvider = new ServiceCollection().BuildServiceProvider(); var executor = new CliActionExecutor(serviceProvider); var context = CreateTestContext(nameof(ActionExecutorTestClass.Execute)); context.ReturnCode = expectedReturnCode; // Act await executor.ExecuteAsync(context); // Assert context.ReturnCode .Should() .Be(expectedReturnCode); }