Skip to content

Commit

Permalink
add integration test for addprouct endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
omid-ahmadpour committed Nov 27, 2022
1 parent 8456cf5 commit f1c9188
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/Api.Test/ProductControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,35 @@ public async Task GetByIdEndpoint_Should_ReturnOk(string url)
// Assert
Assert.True(response.IsSuccessStatusCode);
}

[Theory, ClassData(typeof(AddProductTestData))]
public async Task AddEndpoint_Should_ReturnOk(string name, decimal price)
{
// Arrange
var client = _factory.CreateClient();
var url = "/api/v1/Product";
var request = new AddProductRequest { Name = name, Price = price };
var json = JsonConvert.SerializeObject(request);
var data = new StringContent(json, Encoding.UTF8, "application/json");

// Act
var response = await client.PostAsync(url, data);

// Assert
Assert.True(response.IsSuccessStatusCode);
}

public class AddProductTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { "sampe product name", 1000 };
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
}

0 comments on commit f1c9188

Please sign in to comment.