-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
429 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using EntityFramework_Reverse_POCO_Generator; | ||
using Generator.Tests.Common; | ||
using NUnit.Framework; | ||
using Tester.BusinessLogic; | ||
|
||
namespace Tester.Integration.EFCore8 | ||
{ | ||
[TestFixture] | ||
[Category(Constants.Integration)] | ||
[Category(Constants.DbType.SqlServer)] | ||
public class CustomersRepositoryTests | ||
{ | ||
private MyDbContext _db = null!; | ||
private Dictionary<string, string> _dictionary = null!; | ||
//private IConfiguration _configuration; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetUp() | ||
{ | ||
_dictionary = new Dictionary<string, string> | ||
{ | ||
{ "ALFKI", "Alfreds Futterkiste" }, | ||
{ "ANATR", "Ana Trujillo Emparedados y helados" }, | ||
{ "ANTON", "Antonio Moreno Taquería" }, | ||
{ "AROUT", "Around the Horn" }, | ||
{ "BERGS", "Berglunds snabbköp" }, | ||
{ "BLAUS", "Blauer See Delikatessen" }, | ||
{ "BLONP", "Blondesddsl père et fils" }, | ||
{ "BOLID", "Bólido Comidas preparadas" }, | ||
{ "BONAP", "Bon app'" }, | ||
{ "BOTTM", "Bottom-Dollar Markets"} | ||
}; | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void OneTimeTearDown() | ||
{ | ||
var customer = _db.Customers.FirstOrDefault(x => x.CustomerId == "TEST."); | ||
if (customer == null) | ||
return; | ||
_db.Customers.Remove(customer); | ||
_db.SaveChanges(); | ||
} | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
//_configuration = new ConfigurationBuilder() | ||
// .AddJsonFile("appsettings.json", false, false) | ||
// .Build(); | ||
|
||
//_db = new MyDbContext(_configuration); | ||
_db = new MyDbContext(); | ||
} | ||
|
||
[Test] | ||
public void UseEfDirectly() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var data = _db.Customers.Take(10).OrderBy(x => x.CustomerId).ToList(); | ||
|
||
// Assert | ||
AssertCustomerData(data); | ||
} | ||
|
||
[Test] | ||
public void UseEfViaRepository() | ||
{ | ||
// Arrange | ||
var customersRepository = new CustomersRepository(_db); | ||
|
||
// Act | ||
var data = customersRepository.GetTop10().ToList(); | ||
|
||
// Assert | ||
AssertCustomerData(data); | ||
} | ||
|
||
private void AssertCustomerData(List<EntityFramework_Reverse_POCO_Generator.Customer> data) | ||
{ | ||
Assert.AreEqual(_dictionary.Count, data.Count); | ||
foreach (var customer in data) | ||
{ | ||
Assert.IsTrue(_dictionary.ContainsKey(customer.CustomerId)); | ||
Assert.AreEqual(_dictionary[customer.CustomerId], customer.CompanyName); | ||
} | ||
} | ||
|
||
[Test] | ||
public void InsertAndDeleteTestRecordSuccessfullyViaFindById() | ||
{ | ||
// Arrange | ||
var db2 = new MyDbContext(); | ||
var db3 = new MyDbContext(); | ||
var customersRepository1 = new CustomersRepository(_db); | ||
var customersRepository2 = new CustomersRepository(db2); | ||
var customersRepository3 = new CustomersRepository(db3); | ||
var customer = new EntityFramework_Reverse_POCO_Generator.Customer | ||
{ | ||
CustomerId = "TEST.", | ||
CompanyName = "Integration testing" | ||
}; | ||
|
||
// Act | ||
customersRepository1.AddCustomer(customer); | ||
var customer2 = customersRepository2.FindById(customer.CustomerId); | ||
customersRepository2.DeleteCustomer(customer2); | ||
var customer3 = customersRepository3.FindById(customer.CustomerId); // Should not be found | ||
|
||
// Assert | ||
Assert.IsNotNull(customer2); | ||
Assert.AreEqual(customer.CustomerId, customer2.CustomerId); | ||
Assert.AreEqual(customer.CompanyName, customer2.CompanyName); | ||
Assert.IsNull(customer3); | ||
} | ||
|
||
[Test] | ||
public void InsertAndDeleteTestRecordSuccessfullyViaFind() | ||
{ | ||
// Arrange | ||
var db2 = new MyDbContext(); | ||
var db3 = new MyDbContext(); | ||
var customersRepository1 = new CustomersRepository(_db); | ||
var customersRepository2 = new CustomersRepository(db2); | ||
var customersRepository3 = new CustomersRepository(db3); | ||
var customer = new EntityFramework_Reverse_POCO_Generator.Customer | ||
{ | ||
CustomerId = "TEST.", | ||
CompanyName = "Integration testing" | ||
}; | ||
|
||
// Act | ||
customersRepository1.AddCustomer(customer); | ||
var customer2 = customersRepository2.Find(customer.CustomerId); | ||
customersRepository2.DeleteCustomer(customer2); | ||
var customer3 = customersRepository3.Find(customer.CustomerId); // Should not be found | ||
|
||
// Assert | ||
Assert.IsNotNull(customer2); | ||
Assert.AreEqual(customer.CustomerId, customer2.CustomerId); | ||
Assert.AreEqual(customer.CompanyName, customer2.CompanyName); | ||
Assert.IsNull(customer3); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# This file contains a list of the files generated by the EfrpgTest.tt file. | ||
# Please do not edit this file. It is used to delete files that may get filtered out during the next run. | ||
# Time start = 19/11/2023 15:11:46 | ||
# Time end = 19/11/2023 15:11:47, duration = 1.29 seconds. | ||
# Time start = 19/11/2023 21:21:32 | ||
# Time end = 19/11/2023 21:21:33, duration = 1.26 seconds. |
Oops, something went wrong.