Skip to content

Commit

Permalink
Add EFCore9 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjh37 committed Jan 28, 2025
1 parent 616f3b1 commit 0b471e0
Show file tree
Hide file tree
Showing 18 changed files with 40,192 additions and 0 deletions.
18 changes: 18 additions & 0 deletions EF.Reverse.POCO.GeneratorV3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Integration.EFCore7"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Integration.EFCore8", "Tester.Integration.EFCore8\Tester.Integration.EFCore8.csproj", "{55A7975C-9972-497C-86D5-9E92632DB32F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester.Integration.EFCore9", "Tester.Integration.EFCore9\Tester.Integration.EFCore9.csproj", "{95983923-D8F1-4581-826E-618C75EE9D3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -286,6 +288,22 @@ Global
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|x86.ActiveCfg = Release|Any CPU
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|x86.Build.0 = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|ARM64.Build.0 = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|x86.ActiveCfg = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|x86.Build.0 = Debug|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Any CPU.Build.0 = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|ARM64.ActiveCfg = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|ARM64.Build.0 = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|x86.ActiveCfg = Release|Any CPU
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1,185 changes: 1,185 additions & 0 deletions Tester.Integration.EFCore9/Azure.cs

Large diffs are not rendered by default.

720 changes: 720 additions & 0 deletions Tester.Integration.EFCore9/Azure.tt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Tester.Integration.EFCore9/AzureAudit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file contains a list of the files generated by the Azure.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 = 28/01/2025 15:25:38
# Time end = 28/01/2025 15:25:47, duration = 8.78 seconds.
147 changes: 147 additions & 0 deletions Tester.Integration.EFCore9/CustomersRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using EntityFramework_Reverse_POCO_Generator;
using Generator.Tests.Common;
using NUnit.Framework;
using Tester.BusinessLogic;

namespace Tester.Integration.EFCore9
{
[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);
}
}
}
Loading

0 comments on commit 0b471e0

Please sign in to comment.