Skip to content

Commit 8a066c0

Browse files
committed
Add test for Sqlite Encrypted Database
1 parent 177c08b commit 8a066c0

File tree

13 files changed

+199
-89
lines changed

13 files changed

+199
-89
lines changed

Projects/Dotmim.Sync.Core/CoreProvider.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ public void SetProgress(IProgress<ProgressArgs> progress)
106106
/// <summary>
107107
/// Set an interceptor to get info on the current sync process
108108
/// </summary>
109-
public void SetInterceptor(InterceptorBase interceptor)
109+
public void On(InterceptorBase interceptor)
110110
=> this.interceptorBase = interceptor;
111111

112+
/// <summary>
113+
/// Set an interceptor to get info on the current sync process
114+
/// </summary>
115+
public void On<T>(Action<T> interceptorAction) where T : ProgressArgs
116+
=> this.interceptorBase = new Interceptor<T>(interceptorAction);
117+
112118
/// <summary>
113119
/// Set the cancellation token used to cancel sync
114120
/// </summary>
@@ -280,5 +286,6 @@ private void RemoveTrackingColumns(DmTable changes, string name)
280286
changes.Columns.Remove(name);
281287
}
282288

289+
283290
}
284291
}

Projects/Dotmim.Sync.Core/IProvider.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public interface IProvider
3333
/// <summary>
3434
/// set the Interceptor class to intercepts multipes events during the sync process
3535
/// </summary>
36-
void SetInterceptor(InterceptorBase interceptor);
36+
void On(InterceptorBase interceptor);
37+
38+
/// <summary>
39+
/// set the Interceptor class to intercepts multipes events during the sync process
40+
/// </summary>
41+
void On<T>(Action<T> interceptorAction) where T : ProgressArgs;
3742

3843
/// <summary>
3944
/// Begin Session. if Configuration is set locally, then send it to the server

Projects/Dotmim.Sync.Core/Interceptors/InterceptorExtensions.cs

+65-65
Large diffs are not rendered by default.

Projects/Dotmim.Sync.Core/SyncAgent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void SetProgress(IProgress<ProgressArgs> progress)
7070
/// Set an interceptor to get info on the current sync process
7171
/// </summary>
7272
public void SetInterceptor(InterceptorBase interceptor)
73-
=> this.LocalProvider.SetInterceptor(interceptor);
73+
=> this.LocalProvider.On(interceptor);
7474

7575

7676
/// <summary>

Projects/Dotmim.Sync.Web.Client/WebProxyClientProvider.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ public void SetProgress(IProgress<ProgressArgs> progress) { }
6868
/// <summary>
6969
/// The proxy client does not use any interceptor
7070
/// </summary>
71-
public void SetInterceptor(InterceptorBase interceptorBase) { }
72-
71+
public void On(InterceptorBase interceptorBase) { }
7372

73+
/// <summary>
74+
/// Set an interceptor to get info on the current sync process
75+
/// </summary>
76+
public void On<T>(Action<T> interceptorAction) where T : ProgressArgs { }
7477

7578
/// <summary>
7679
/// The proxy client does not interecot changes failed

Projects/Dotmim.Sync.Web.Server/SyncMemoryProvider.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,17 @@ public void SetConfiguration(Action<SyncConfiguration> configuration)
5151
public void SetProgress(IProgress<ProgressArgs> progress)
5252
=> this.LocalProvider.SetProgress(progress);
5353

54+
/// <summary>
55+
/// Set an interceptor to get info on the current sync process
56+
/// </summary>
57+
public void On(InterceptorBase interceptorBase)
58+
=> this.LocalProvider.On(interceptorBase);
5459

55-
public void SetInterceptor(InterceptorBase interceptorBase)
56-
=> this.LocalProvider.SetInterceptor(interceptorBase);
57-
60+
/// <summary>
61+
/// Set an interceptor to get info on the current sync process
62+
/// </summary>
63+
public void On<T>(Action<T> interceptorAction) where T : ProgressArgs
64+
=> this.LocalProvider.On<T>(interceptorAction);
5865

5966
internal async Task<HttpMessage> GetResponseMessageAsync(HttpMessage httpMessage,
6067
CancellationToken cancellationToken)

Samples/Dotmim.Sync.SampleConsole/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ private static async Task SynchronizeExistingTablesAsync()
226226

227227
});
228228

229-
remoteProvider.InterceptDatabaseProvisioned(dpAction);
229+
remoteProvider.OnDatabaseProvisioned(dpAction);
230230

231-
agent.LocalProvider.InterceptDatabaseProvisioned(dpAction);
231+
agent.LocalProvider.OnDatabaseProvisioned(dpAction);
232232

233233
do
234234
{

Samples/Dotmim.Sync.SampleWebServer/Controllers/SyncController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task Post()
2727
var provider = webProxyServer.GetLocalProvider(this.HttpContext);
2828
provider.SetConfiguration(c =>c.Filters.Add("Customer", "CustomerId"));
2929

30-
provider.InterceptApplyChangesFailed(e =>
30+
provider.OnApplyChangesFailed(e =>
3131
{
3232
if (e.Conflict.RemoteRow.Table.TableName == "Region")
3333
{

Tests/Dotmim.Sync.Tests/BasicTests.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,8 @@ public virtual async Task Conflict_Insert_Insert_Client_Should_Wins_Coz_Handler_
696696

697697

698698
this.testRunner.BeginRun = provider
699-
=> provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(c => c.Resolution = ConflictResolution.ClientWins));
700-
this.testRunner.EndRun = provider => provider.SetInterceptor(null);
699+
=> provider.On(new Interceptor<ApplyChangesFailedArgs>(c => c.Resolution = ConflictResolution.ClientWins));
700+
this.testRunner.EndRun = provider => provider.On(null);
701701

702702
var results = await this.testRunner.RunTestsAsync(conf);
703703

@@ -850,7 +850,7 @@ public virtual async Task Conflict_Update_Update_Client_Should_Wins_Coz_Handler_
850850

851851

852852
this.testRunner.BeginRun = provider =>
853-
provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(args =>
853+
provider.On(new Interceptor<ApplyChangesFailedArgs>(args =>
854854
args.Resolution = ConflictResolution.ClientWins));
855855

856856
var results = await this.testRunner.RunTestsAsync(conf);
@@ -932,15 +932,15 @@ public virtual async Task Conflict_Update_Update_Resolve_By_Merge()
932932
}
933933

934934
this.testRunner.BeginRun = provider
935-
=> provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(args =>
935+
=> provider.On(new Interceptor<ApplyChangesFailedArgs>(args =>
936936
{
937937
args.Resolution = ConflictResolution.MergeRow;
938938
args.FinalRow["Name"] = productCategoryNameMerged;
939939

940940
}));
941941

942942

943-
this.testRunner.EndRun = provider => provider.SetInterceptor(null);
943+
this.testRunner.EndRun = provider => provider.On(null);
944944

945945

946946
var results = await this.testRunner.RunTestsAsync(conf);
@@ -1285,7 +1285,7 @@ public virtual async Task Use_Existing_Client_Database_Provision_Deprosivion()
12851285

12861286

12871287
// just check interceptor
1288-
localProvider.SetInterceptor(new Interceptor<TableProvisioningArgs>(args =>
1288+
localProvider.On(new Interceptor<TableProvisioningArgs>(args =>
12891289
{
12901290
Assert.Equal(SyncProvision.All, args.Provision);
12911291
}));
@@ -1357,7 +1357,7 @@ public virtual async Task Use_Existing_Client_Database_Provision_Deprosivion()
13571357
}
13581358

13591359
// just check interceptor
1360-
localProvider.SetInterceptor(new Interceptor<TableDeprovisioningArgs>(args =>
1360+
localProvider.On(new Interceptor<TableDeprovisioningArgs>(args =>
13611361
{
13621362
Assert.Equal(SyncProvision.All, args.Provision);
13631363
}));
@@ -1414,7 +1414,7 @@ public virtual async Task Use_Existing_Client_Database_Provision_Deprosivion()
14141414
}
14151415

14161416

1417-
localProvider.SetInterceptor(null);
1417+
localProvider.On(null);
14181418

14191419

14201420
}
@@ -1596,7 +1596,7 @@ Task tableChangesSelected(TableChangesSelectedArgs changes)
15961596
};
15971597

15981598
// during first run, add a new row during selection on client (very first step of whole sync process)
1599-
clientRun.ClientProvider.SetInterceptor
1599+
clientRun.ClientProvider.On
16001600
(new Interceptor<TableChangesSelectedArgs>(tableChangesSelected));
16011601

16021602
var trr = await clientRun.RunAsync(this.fixture, null, conf, false);
@@ -1605,7 +1605,7 @@ Task tableChangesSelected(TableChangesSelectedArgs changes)
16051605
Assert.Equal(1, trr.Results.TotalChangesUploaded);
16061606
cpt = cpt + 2;
16071607

1608-
clientRun.ClientProvider.SetInterceptor(null);
1608+
clientRun.ClientProvider.On(null);
16091609

16101610
var trr2 = await clientRun.RunAsync(this.fixture, null, conf, false);
16111611
Debug.WriteLine($"{trr2.ClientProvider.ConnectionString}: Upload={trr2.Results.TotalChangesUploaded}");

Tests/Dotmim.Sync.Tests/HelperDB.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Dotmim.Sync.Tests
1414
public static class HelperDB
1515
{
1616

17-
public static Func<String, String> GetSqlConnectionString;
17+
public static Func<string, string> GetSqlConnectionString;
1818

1919

2020
/// <summary>

Tests/Dotmim.Sync.Tests/Models/AdventureWorksContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public partial class AdventureWorksContext : DbContext
1313
{
1414
internal bool useSchema = false;
1515
internal bool useSeeding = false;
16-
public ProviderType ProviderType { get; }
17-
public string ConnectionString { get; }
16+
public ProviderType ProviderType { get; set; }
17+
public string ConnectionString { get; set; }
1818

1919
private DbConnection Connection { get; }
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Dotmim.Sync.Tests.Core;
2+
using Dotmim.Sync.Tests.Misc;
3+
using Dotmim.Sync;
4+
using System;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Dotmim.Sync.Tests.SqlServer;
8+
using Dotmim.Sync.SqlServer;
9+
using Dotmim.Sync.Sqlite;
10+
using Dotmim.Sync.Tests.Models;
11+
12+
namespace Dotmim.Sync.Tests.Sqlite
13+
{
14+
/// <summary>
15+
/// this is the class which implements concret fixture with SqlSyncProviderFixture
16+
/// and will call all the base tests
17+
/// </summary>
18+
[TestCaseOrderer("Dotmim.Sync.Tests.Misc.PriorityOrderer", "Dotmim.Sync.Tests")]
19+
[Collection("Sqlite")]
20+
public class SqliteEncryptedTests
21+
{
22+
private string[] sqlTables;
23+
private SqlSyncProvider serverProvider;
24+
private SqliteSyncProvider clientProvider;
25+
private string serverCString = HelperDB.GetConnectionString(ProviderType.Sql, "AdvWorksForEncrypted");
26+
private string clientCString = HelperDB.GetConnectionString(ProviderType.Sqlite, "EncryptedAdventureWorks.db");
27+
28+
public SqliteEncryptedTests()
29+
{
30+
this.sqlTables = new string[]
31+
{
32+
"SalesLT.ProductCategory", "SalesLT.ProductModel", "SalesLT.Product", "Employee", "Customer", "Address", "CustomerAddress", "EmployeeAddress",
33+
"SalesLT.SalesOrderHeader", "SalesLT.SalesOrderDetail", "dbo.Sql", "Posts", "Tags", "PostTag",
34+
"PricesList", "PriceListCategory", "PriceListDetail"
35+
};
36+
37+
38+
this.serverProvider = new SqlSyncProvider(serverCString);
39+
this.clientProvider = new SqliteSyncProvider(clientCString);
40+
}
41+
42+
[Fact, TestPriority(1)]
43+
public async Task Initialize()
44+
{
45+
try
46+
{
47+
48+
using (var ctx = new AdventureWorksContext())
49+
{
50+
ctx.ProviderType = ProviderType.Sql;
51+
ctx.ConnectionString = this.serverCString;
52+
ctx.useSeeding = true;
53+
ctx.useSchema = true;
54+
55+
ctx.Database.EnsureDeleted();
56+
ctx.Database.EnsureCreated();
57+
}
58+
59+
var agent = new SyncAgent(this.clientProvider, this.serverProvider, this.sqlTables);
60+
61+
agent.LocalProvider.OnConnectionOpen(args =>
62+
{
63+
var keyCommand = args.Connection.CreateCommand();
64+
keyCommand.CommandText = "PRAGMA key = 'password';";
65+
keyCommand.ExecuteNonQuery();
66+
67+
});
68+
69+
var s = await agent.SynchronizeAsync();
70+
71+
Assert.Equal(109, s.TotalChangesDownloaded);
72+
}
73+
catch (Exception ex)
74+
{
75+
Console.WriteLine(ex);
76+
throw;
77+
}
78+
}
79+
80+
}
81+
}

azure-pipelines.yml

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ jobs:
5959
"MYSQLIP": $(setvarStep.mySQLIP)
6060
"AZUREDEV": "true"
6161

62+
- script: dotnet test Tests/Dotmim.Sync.Tests/Dotmim.Sync.Tests.csproj --filter SqliteEncryptedTests --logger trx
63+
name: SqliteEncryptedTests
64+
displayName: "Tests with SQL Server acting as server and encrypted SQLite database"
65+
env:
66+
"MYSQLIP": $(setvarStep.mySQLIP)
67+
"AZUREDEV": "true"
68+
6269
- script: dotnet test Tests/Dotmim.Sync.Tests/Dotmim.Sync.Tests.csproj --filter MySqlBasicTests --logger trx
6370
name: MySqlBasicTests
6471
displayName: "Tests with MySQL Server acting as server"

0 commit comments

Comments
 (0)