public void GetCustomers_Should_Throw_Exception_If_Status_Not_Ok() { var client = new Mock <ICustomerBetClient>(); client.Setup(t => t.GetAsync("api/GetCustomers?code=code123&name=user123")) .ReturnsAsync(GenerateResponse <IEnumerable <CustomerDto> >(null, HttpStatusCode.NotFound)); var target = new CustomerBetService(client.Object, _settings.Object); var ex = Assert.ThrowsAsync <Exception>(() => target.GetCustomersAsync()); Assert.That(ex.Message, Is.EqualTo("Failed to get the customers")); }
public async Task GetCustomers_Can_Get_All_Customers() { var client = new Mock <ICustomerBetClient>(); client.Setup(t => t.GetAsync("api/GetCustomers?code=code123&name=user123")) .ReturnsAsync(GenerateResponse <IEnumerable <CustomerDto> >(new[] { new CustomerDto { Id = 1, Name = "Bob" }, new CustomerDto { Id = 2, Name = "Rodger" }, }, HttpStatusCode.OK)); var target = new CustomerBetService(client.Object, _settings.Object); var result = (await target.GetCustomersAsync()).ToArray(); Assert.That(result.Length, Is.EqualTo(2)); Assert.That(result[0].Name, Is.EqualTo("Bob")); Assert.That(result[1].Name, Is.EqualTo("Rodger")); }