public async Task ShouldThrowExceptionWhenCallbackIsNotSet() { string json = JsonSerializer.Serialize(new { Status = 100, Authority = "000000000000000000000000000000012345" }); var mockHttp = new MockHttpMessageHandler(); mockHttp.When("*") .Respond("application/json", json); var httpClient = mockHttp.ToHttpClient(); var options = new ZarinPalOptions { DefaultCallbackUri = null, MerchantId = "something-that-does-not-matter", IsDevelopment = true }; var service = new ZarinPalService(httpClient, Options.Create(options)); await Assert.ThrowsAsync <ArgumentException>("callbackUri", async() => { await service.RequestPaymentAsync(1000, "From tests", callbackUri: null); }); }
/// <summary> /// Initializes a new instance of the <see cref="ZarinPalService"/> class. /// </summary> /// <param name="httpClient">An instance of <see cref="HttpClient"/>.</param> /// <param name="options">An instance of <see cref="ZarinPalOptions"/>.</param> public ZarinPalService(HttpClient httpClient, IOptions <ZarinPalOptions> options) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); if (string.IsNullOrWhiteSpace(options.Value.MerchantId)) { throw new ArgumentException($"'{nameof(options.Value.MerchantId)}' has not been configured.", nameof(options)); } }