Skip to content

Commit 0b471e0

Browse files
committed
Add EFCore9 unit tests
1 parent 616f3b1 commit 0b471e0

18 files changed

+40192
-0
lines changed

EF.Reverse.POCO.GeneratorV3.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Integration.EFCore7"
6161
EndProject
6262
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester.Integration.EFCore8", "Tester.Integration.EFCore8\Tester.Integration.EFCore8.csproj", "{55A7975C-9972-497C-86D5-9E92632DB32F}"
6363
EndProject
64+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester.Integration.EFCore9", "Tester.Integration.EFCore9\Tester.Integration.EFCore9.csproj", "{95983923-D8F1-4581-826E-618C75EE9D3F}"
65+
EndProject
6466
Global
6567
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6668
Debug|Any CPU = Debug|Any CPU
@@ -286,6 +288,22 @@ Global
286288
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
287289
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|x86.ActiveCfg = Release|Any CPU
288290
{55A7975C-9972-497C-86D5-9E92632DB32F}.Release|x86.Build.0 = Release|Any CPU
291+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
292+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
293+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
294+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|ARM64.Build.0 = Debug|Any CPU
295+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
296+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
297+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|x86.ActiveCfg = Debug|Any CPU
298+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Debug|x86.Build.0 = Debug|Any CPU
299+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
300+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Any CPU.Build.0 = Release|Any CPU
301+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|ARM64.ActiveCfg = Release|Any CPU
302+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|ARM64.Build.0 = Release|Any CPU
303+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
304+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
305+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|x86.ActiveCfg = Release|Any CPU
306+
{95983923-D8F1-4581-826E-618C75EE9D3F}.Release|x86.Build.0 = Release|Any CPU
289307
EndGlobalSection
290308
GlobalSection(SolutionProperties) = preSolution
291309
HideSolutionNode = FALSE

Tester.Integration.EFCore9/Azure.cs

Lines changed: 1185 additions & 0 deletions
Large diffs are not rendered by default.

Tester.Integration.EFCore9/Azure.tt

Lines changed: 720 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file contains a list of the files generated by the Azure.tt file.
2+
# Please do not edit this file. It is used to delete files that may get filtered out during the next run.
3+
# Time start = 28/01/2025 15:25:38
4+
# Time end = 28/01/2025 15:25:47, duration = 8.78 seconds.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using EntityFramework_Reverse_POCO_Generator;
2+
using Generator.Tests.Common;
3+
using NUnit.Framework;
4+
using Tester.BusinessLogic;
5+
6+
namespace Tester.Integration.EFCore9
7+
{
8+
[TestFixture]
9+
[Category(Constants.Integration)]
10+
[Category(Constants.DbType.SqlServer)]
11+
public class CustomersRepositoryTests
12+
{
13+
private MyDbContext _db = null!;
14+
private Dictionary<string, string> _dictionary = null!;
15+
//private IConfiguration _configuration;
16+
17+
[OneTimeSetUp]
18+
public void OneTimeSetUp()
19+
{
20+
_dictionary = new Dictionary<string, string>
21+
{
22+
{ "ALFKI", "Alfreds Futterkiste" },
23+
{ "ANATR", "Ana Trujillo Emparedados y helados" },
24+
{ "ANTON", "Antonio Moreno Taquería" },
25+
{ "AROUT", "Around the Horn" },
26+
{ "BERGS", "Berglunds snabbköp" },
27+
{ "BLAUS", "Blauer See Delikatessen" },
28+
{ "BLONP", "Blondesddsl père et fils" },
29+
{ "BOLID", "Bólido Comidas preparadas" },
30+
{ "BONAP", "Bon app'" },
31+
{ "BOTTM", "Bottom-Dollar Markets"}
32+
};
33+
}
34+
35+
[OneTimeTearDown]
36+
public void OneTimeTearDown()
37+
{
38+
var customer = _db.Customers.FirstOrDefault(x => x.CustomerId == "TEST.");
39+
if (customer == null)
40+
return;
41+
_db.Customers.Remove(customer);
42+
_db.SaveChanges();
43+
}
44+
45+
[SetUp]
46+
public void SetUp()
47+
{
48+
//_configuration = new ConfigurationBuilder()
49+
// .AddJsonFile("appsettings.json", false, false)
50+
// .Build();
51+
52+
//_db = new MyDbContext(_configuration);
53+
_db = new MyDbContext();
54+
}
55+
56+
[Test]
57+
public void UseEfDirectly()
58+
{
59+
// Arrange
60+
61+
// Act
62+
var data = _db.Customers.Take(10).OrderBy(x => x.CustomerId).ToList();
63+
64+
// Assert
65+
AssertCustomerData(data);
66+
}
67+
68+
[Test]
69+
public void UseEfViaRepository()
70+
{
71+
// Arrange
72+
var customersRepository = new CustomersRepository(_db);
73+
74+
// Act
75+
var data = customersRepository.GetTop10().ToList();
76+
77+
// Assert
78+
AssertCustomerData(data);
79+
}
80+
81+
private void AssertCustomerData(List<EntityFramework_Reverse_POCO_Generator.Customer> data)
82+
{
83+
Assert.AreEqual(_dictionary.Count, data.Count);
84+
foreach (var customer in data)
85+
{
86+
Assert.IsTrue(_dictionary.ContainsKey(customer.CustomerId));
87+
Assert.AreEqual(_dictionary[customer.CustomerId], customer.CompanyName);
88+
}
89+
}
90+
91+
[Test]
92+
public void InsertAndDeleteTestRecordSuccessfullyViaFindById()
93+
{
94+
// Arrange
95+
var db2 = new MyDbContext();
96+
var db3 = new MyDbContext();
97+
var customersRepository1 = new CustomersRepository(_db);
98+
var customersRepository2 = new CustomersRepository(db2);
99+
var customersRepository3 = new CustomersRepository(db3);
100+
var customer = new EntityFramework_Reverse_POCO_Generator.Customer
101+
{
102+
CustomerId = "TEST.",
103+
CompanyName = "Integration testing"
104+
};
105+
106+
// Act
107+
customersRepository1.AddCustomer(customer);
108+
var customer2 = customersRepository2.FindById(customer.CustomerId);
109+
customersRepository2.DeleteCustomer(customer2);
110+
var customer3 = customersRepository3.FindById(customer.CustomerId); // Should not be found
111+
112+
// Assert
113+
Assert.IsNotNull(customer2);
114+
Assert.AreEqual(customer.CustomerId, customer2.CustomerId);
115+
Assert.AreEqual(customer.CompanyName, customer2.CompanyName);
116+
Assert.IsNull(customer3);
117+
}
118+
119+
[Test]
120+
public void InsertAndDeleteTestRecordSuccessfullyViaFind()
121+
{
122+
// Arrange
123+
var db2 = new MyDbContext();
124+
var db3 = new MyDbContext();
125+
var customersRepository1 = new CustomersRepository(_db);
126+
var customersRepository2 = new CustomersRepository(db2);
127+
var customersRepository3 = new CustomersRepository(db3);
128+
var customer = new EntityFramework_Reverse_POCO_Generator.Customer
129+
{
130+
CustomerId = "TEST.",
131+
CompanyName = "Integration testing"
132+
};
133+
134+
// Act
135+
customersRepository1.AddCustomer(customer);
136+
var customer2 = customersRepository2.Find(customer.CustomerId);
137+
customersRepository2.DeleteCustomer(customer2);
138+
var customer3 = customersRepository3.Find(customer.CustomerId); // Should not be found
139+
140+
// Assert
141+
Assert.IsNotNull(customer2);
142+
Assert.AreEqual(customer.CustomerId, customer2.CustomerId);
143+
Assert.AreEqual(customer.CompanyName, customer2.CompanyName);
144+
Assert.IsNull(customer3);
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)