Skip to content

Instantly share code, notes, and snippets.

@Kevin-Bronsdijk
Created August 16, 2020 04:52
Show Gist options
  • Save Kevin-Bronsdijk/d9c189e5a9521e26fd42bba61c70af0b to your computer and use it in GitHub Desktop.
Save Kevin-Bronsdijk/d9c189e5a9521e26fd42bba61c70af0b to your computer and use it in GitHub Desktop.
[Test]
public void Example2_GetProducts_WhenPassingAValidCategory_ThenShouldReturnProducts()
{
// setup repository mock
var products = new List<Product>
{
new Product { Id = 1, Name = "Product 1" },
new Product { Id = 2, Name = "Product 2" }
};
IProductCatalogRepository repository = Substitute.For<IProductCatalogRepository>();
repository.GetProducts(Arg.Is("ElectronicDevices")).Returns(products);
// create object under test
var testSubject = new ProductCatalogService(repository);
// assert
var result = testSubject.GetProducts(Category.ElectronicDevices);
Assert.IsNotNull(result);
Assert.IsTrue(result.ToList().Count != 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment