Skip to content

Commit f83fcda

Browse files
committed
chore: try to run test on mssql
1 parent 93f5661 commit f83fcda

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

.github/workflows/buildAndTest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
uses: supercharge/[email protected]
2121
with:
2222
mongodb-version: 5.0
23+
24+
- name: Start SQLServer
25+
run: docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=MyPass@word" -p 1433:1433 -d --name=sql mcr.microsoft.com/azure-sql-edge
2326

2427
- run: dotnet test
2528

SharpRepository.Tests.Integration/SharpRepository.Tests.Integration.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<DebugType>Full</DebugType>
66
<AssemblyName>SharpRepository.Tests.Integration</AssemblyName>
77
<RootNamespace>SharpRepository.Tests.Integration</RootNamespace>
8+
<UserSecretsId>627a7ed1-b2c9-408a-a341-c01fc197a606</UserSecretsId>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -26,12 +27,14 @@
2627
<ItemGroup>
2728
<PackageReference Include="Effort.EF6" Version="2.2.16" />
2829
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.6" />
30+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
2931
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
3032
<PackageReference Include="Moq" Version="4.18.1" />
3133
<PackageReference Include="NUnit" Version="3.13.3" />
3234
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
3335
<PackageReference Include="Shouldly" Version="4.0.3" />
3436
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
37+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
3538
</ItemGroup>
3639

3740
<ItemGroup>
@@ -43,10 +46,6 @@
4346
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj" />
4447
</ItemGroup>
4548

46-
<ItemGroup>
47-
<Reference Include="System.Transactions" />
48-
</ItemGroup>
49-
5049
<ItemGroup>
5150
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
5251
</ItemGroup>

SharpRepository.Tests.Integration/Spikes/EfCoreLazyLoadSpike.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-

2-
using System.Linq;
1+
using System.Linq;
32
using NUnit.Framework;
43
using SharpRepository.EfCoreRepository;
5-
using SharpRepository.Repository;
6-
using SharpRepository.Repository.Caching;
7-
using SharpRepository.Tests.Integration.Data;
84
using SharpRepository.Tests.Integration.TestObjects;
95
using Shouldly;
106
using System.Collections.Generic;
11-
using System.Diagnostics;
127
using SharpRepository.Repository.FetchStrategies;
138
using SharpRepository.Repository.Queries;
149
using SharpRepository.Repository.Specifications;
1510
using Microsoft.EntityFrameworkCore;
16-
using Microsoft.Extensions.Logging;
1711
using System;
12+
using Microsoft.Extensions.Configuration;
1813

1914
namespace SharpRepository.Tests.Integration.Spikes
2015
{
@@ -23,13 +18,26 @@ public class EfCoreLazyLoadSpike
2318
{
2419
private TestObjectContextCore dbContext;
2520

26-
private Func<string, bool> filterSelects = q => q.StartsWith("Executing DbCommand") && q.Contains("SELECT") && !q.Contains("sqlite_master");
21+
private Func<string, bool> filterSelects = q => q.StartsWith("Executing DbCommand") && q.Contains("SELECT");
22+
23+
public static IConfigurationRoot GetIConfigurationRoot(string outputPath)
24+
{
25+
return new ConfigurationBuilder()
26+
.SetBasePath(outputPath)
27+
.AddJsonFile("appsettings.json", optional: true)
28+
.AddUserSecrets("627a7ed1-b2c9-408a-a341-c01fc197a606")
29+
.Build();
30+
}
2731

2832
[SetUp]
2933
public void SetupRepository()
3034
{
35+
var configurationRoot = GetIConfigurationRoot(TestContext.CurrentContext.TestDirectory);
36+
37+
var connectionString = configurationRoot.GetConnectionString("EfCoreConnectionString");
38+
3139
var options = new DbContextOptionsBuilder<TestObjectContextCore>()
32-
.UseInMemoryDatabase("integration test")
40+
.UseSqlServer(connectionString)
3341
.Options;
3442

3543
// Create the schema in the database
@@ -48,8 +56,8 @@ public void SetupRepository()
4856
new EmailAddress {
4957
ContactId = i.ToString(),
5058
EmailAddressId = i,
51-
Email = "omar.piani." + i.ToString() + "@email.com",
52-
Label = "omar.piani." + i.ToString()
59+
Email = "test.addr." + i.ToString() + "@email.com",
60+
Label = "test.addr." + i.ToString()
5361
}
5462
}
5563
});
@@ -66,7 +74,7 @@ public void EfCore_GetAll_Without_Includes_LazyLoads_Email()
6674
var contact = repository.GetAll().First();
6775
contact.Name.ShouldBe("Test User 1");
6876
dbContext.QueryLog.Count(filterSelects).ShouldBe(1);
69-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
77+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
7078
// dbContext.QueryLog.Count(filterSelects).ShouldBe(2); may be that dbcontext is disposed and the successive queries are not logged, quieries does not contains email so query was made in a lazy way but after.
7179
}
7280

@@ -80,7 +88,7 @@ public void EfCore_GetAll_With_Includes_In_Strategy_LazyLoads_Email()
8088
var contact = repository.GetAll(strategy).First();
8189
contact.Name.ShouldBe("Test User 1");
8290
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
83-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
91+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
8492
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
8593
}
8694

@@ -95,7 +103,7 @@ public void EfCore_GetAll_With_Includes_In_Strategy_String_LazyLoads_Email()
95103
var contact = repository.GetAll(strategy).First();
96104
contact.Name.ShouldBe("Test User 1");
97105
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
98-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
106+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
99107
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
100108
}
101109

@@ -107,7 +115,7 @@ public void EfCore_GetAll_With_Text_Include_LazyLoads_Email()
107115
var contact = repository.GetAll("EmailAddresses").First();
108116
contact.Name.ShouldBe("Test User 1");
109117
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
110-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
118+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
111119
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
112120
}
113121

@@ -121,7 +129,7 @@ public void EfCore_GetAll_With_Text_Include_And_Pagination_LazyLoads_Email()
121129
var contact = repository.GetAll(pagination, "EmailAddresses").First();
122130
contact.Name.ShouldBe("Test User 1");
123131
dbContext.QueryLog.Count(filterSelects).ShouldBe(3); // first query is count for total records
124-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
132+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
125133
dbContext.QueryLog.Count(filterSelects).ShouldBe(3);
126134
}
127135

@@ -131,7 +139,7 @@ public void EfCore_FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email()
131139
var repository = new EfCoreRepository<Contact, string>(dbContext);
132140

133141
var findAllBySpec = new Specification<Contact>(obj => obj.ContactId == "1")
134-
.And(obj => obj.EmailAddresses.Any(m => m.Email == "omar.piani[email protected]"));
142+
.And(obj => obj.EmailAddresses.Any(m => m.Email == "test.addr[email protected]"));
135143

136144
var specification = new Specification<Contact>(obj => obj.Name == "Test User 1");
137145

@@ -148,7 +156,7 @@ public void EfCore_FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email()
148156
var contact = repository.FindAll(findAllBySpec).First();
149157
contact.Name.ShouldBe("Test User 1");
150158
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
151-
contact.EmailAddresses.First().Email.ShouldBe("omar.piani[email protected]");
159+
contact.EmailAddresses.First().Email.ShouldBe("test.addr[email protected]");
152160
dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
153161

154162
repository.FindAll(findAllBySpec).Count().ShouldBe(1);

SharpRepository.Tests.Integration/appsettings.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"connectionStrings": {
3-
"EfCoreConnectionString": "Data Source=:memory:;"
3+
"EfCoreConnectionString": "Server=127.0.0.1;Database=testdb;User Id=sa;Password=MyPass@word"
44
},
55
"sharpRepository": {
66
"repositories": {
@@ -28,16 +28,12 @@
2828
"noCachingProvider": {
2929
"factory": "SharpRepository.Repository.Caching.NoCachingConfigCachingProviderFactory, SharpRepository.Repository"
3030
}
31-
//,
32-
//"redisProvider": {
33-
// "factory": "SharpRepository.Caching.Redis.RedisConfigCachingProviderFactory, SharpRepository.Caching.Redis",
34-
// "host": "127.0.0.1",
35-
// "port": "6379"
36-
//},
37-
//"memCachedProvider": {
38-
// "factory": "SharpRepository.Caching.Memcached.MemCachedConfigCachingProviderFactory, SharpRepository.Caching.Memcached",
39-
// "sectionName": "memcached"
40-
//}
31+
,
32+
"redisProvider": {
33+
"factory": "SharpRepository.Caching.Redis.RedisConfigCachingProviderFactory, SharpRepository.Caching.Redis",
34+
"host": "127.0.0.1",
35+
"port": "6379"
36+
}
4137
},
4238
"cachingStrategies": {
4339
"default": "standard",

0 commit comments

Comments
 (0)