public async Task ExchangeService_CanConstructClient() { var InvalidData = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now, }; var externalServiceData = new ExternalServiceData() { Type = ExchangeService.ExchangeServiceType, Name = "something" }; externalServiceData.Set(InvalidData); var exchangeService = GetExternalService(externalServiceData); await Assert.ThrowsAnyAsync <Exception>(async() => await exchangeService.ConstructClient()); var validData = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now, ExchangeName = "Binance", PrivateKey = "aa" }; externalServiceData.Set(validData); Assert.NotNull(exchangeService.ConstructClient()); }
public async Task AsyncThrowsExceptionAssignableToStaticType() { async Task a() { await Task.Delay(1); throw new InvalidOperationException("Operation is invalid."); } Func <Task> action = a; ArgumentException ae; // MSTest does not support this case. // NUnit does not support this case. // XUnit ae = await XUnitAssert.ThrowsAnyAsync <ArgumentException>(action); // Assert.Throws() Failure // Expected: typeof(System.ArgumentException) // Actual: typeof(System.InvalidOperationException): Operation is invalid. // ---- System.InvalidOperationException: Operation is invalid. // Fluent ae = action.Should().Throw <ArgumentException>("SOME REASONS").Which; // Expected System.ArgumentException because SOME REASONS, but found (aggregated) System.InvalidOperationException with message "Operation is invalid." // at... // Shouldly ae = await action.ShouldThrowAsync <ArgumentException>("Some context"); // Shouldly uses your source code to generate its great error messages, build your test project with full debug information to get better error messages // The provided expression // handle aggregate exception // System.ArgumentException // but was // System.InvalidOperationException // // Additional Info: // Some context }