Last active
April 5, 2019 20:31
-
-
Save efeozyer/e776a7931cd5a4a5a4fb97e980d0f548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class ProductRepositoryFixture | |
{ | |
public ProductRepositoryFixture() | |
{ | |
var builder = new SqlConnectionStringBuilder("Database connection string here!"); | |
var dbContext = new DbContext(builder.ToString()); | |
_prdocutRepository = new ProductRepository(dbContext); | |
} | |
[SetUp] | |
public void SetUp() | |
{ | |
// This time we don't need to setUp method. | |
// We'll use same database connection for each test. | |
} | |
[Test] | |
public void Should_Insert_Product() | |
{ | |
// Arrange | |
var product = CreateEntity(); | |
// Act | |
_productRepository.Add(product); | |
// Assert | |
var products = _productRepository.GetAll(); | |
products.Count() | |
.Should() | |
.Be(1); | |
} | |
[Test] | |
public void Should_Delete_Product() | |
{ | |
// Arrange | |
_productRepository.Add(CreateEntity()); | |
var product = _productRepository.GetAll().First(); | |
// Act | |
_productRepository.Delete(product.Id); | |
// Assert | |
var products = _productRepository.GetAll(); | |
products.Count() | |
.Should() | |
.Be(0); | |
} | |
[Test] | |
public void Should_GetAll_Products() | |
{ | |
// Arrange | |
_productRepository.Add(CreateEntity()); | |
_productRepository.Add(CreateEntity()); | |
// Act | |
var products = _productRepository.GetAll(); | |
// Assert | |
products.Count() | |
.Should() | |
.Be(2); | |
} | |
[Test] | |
public void Should_DeleteAll_Products() | |
{ | |
// Arrange | |
_productRepository.Add(CreateEntity()); | |
_productRepository.Add(CreateEntity()); | |
// Act | |
_productRepository.DeleteAll(); | |
// Assert | |
var products = _productRepository.GetAll(); | |
products.Count() | |
.Should() | |
.Be(0); | |
} | |
private Product CreateEntity() { | |
return new Product { | |
Name = "First Product", | |
Price = 10, | |
IsActive = true | |
}; | |
} | |
[Teardown] | |
public void Teardown() | |
{ | |
_repository.DeleteAll(); | |
} | |
private IProductRepository _productRepository; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment