Skip to content

Commit

Permalink
Add test for Sqlite Encrypted Database
Browse files Browse the repository at this point in the history
  • Loading branch information
Mimetis committed Aug 21, 2019
1 parent 177c08b commit 8a066c0
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 89 deletions.
9 changes: 8 additions & 1 deletion Projects/Dotmim.Sync.Core/CoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ public void SetProgress(IProgress<ProgressArgs> progress)
/// <summary>
/// Set an interceptor to get info on the current sync process
/// </summary>
public void SetInterceptor(InterceptorBase interceptor)
public void On(InterceptorBase interceptor)
=> this.interceptorBase = interceptor;

/// <summary>
/// Set an interceptor to get info on the current sync process
/// </summary>
public void On<T>(Action<T> interceptorAction) where T : ProgressArgs
=> this.interceptorBase = new Interceptor<T>(interceptorAction);

/// <summary>
/// Set the cancellation token used to cancel sync
/// </summary>
Expand Down Expand Up @@ -280,5 +286,6 @@ private void RemoveTrackingColumns(DmTable changes, string name)
changes.Columns.Remove(name);
}


}
}
7 changes: 6 additions & 1 deletion Projects/Dotmim.Sync.Core/IProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public interface IProvider
/// <summary>
/// set the Interceptor class to intercepts multipes events during the sync process
/// </summary>
void SetInterceptor(InterceptorBase interceptor);
void On(InterceptorBase interceptor);

/// <summary>
/// set the Interceptor class to intercepts multipes events during the sync process
/// </summary>
void On<T>(Action<T> interceptorAction) where T : ProgressArgs;

/// <summary>
/// Begin Session. if Configuration is set locally, then send it to the server
Expand Down
130 changes: 65 additions & 65 deletions Projects/Dotmim.Sync.Core/Interceptors/InterceptorExtensions.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Projects/Dotmim.Sync.Core/SyncAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void SetProgress(IProgress<ProgressArgs> progress)
/// Set an interceptor to get info on the current sync process
/// </summary>
public void SetInterceptor(InterceptorBase interceptor)
=> this.LocalProvider.SetInterceptor(interceptor);
=> this.LocalProvider.On(interceptor);


/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions Projects/Dotmim.Sync.Web.Client/WebProxyClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ public void SetProgress(IProgress<ProgressArgs> progress) { }
/// <summary>
/// The proxy client does not use any interceptor
/// </summary>
public void SetInterceptor(InterceptorBase interceptorBase) { }

public void On(InterceptorBase interceptorBase) { }

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

/// <summary>
/// The proxy client does not interecot changes failed
Expand Down
13 changes: 10 additions & 3 deletions Projects/Dotmim.Sync.Web.Server/SyncMemoryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ public void SetConfiguration(Action<SyncConfiguration> configuration)
public void SetProgress(IProgress<ProgressArgs> progress)
=> this.LocalProvider.SetProgress(progress);

/// <summary>
/// Set an interceptor to get info on the current sync process
/// </summary>
public void On(InterceptorBase interceptorBase)
=> this.LocalProvider.On(interceptorBase);

public void SetInterceptor(InterceptorBase interceptorBase)
=> this.LocalProvider.SetInterceptor(interceptorBase);

/// <summary>
/// Set an interceptor to get info on the current sync process
/// </summary>
public void On<T>(Action<T> interceptorAction) where T : ProgressArgs
=> this.LocalProvider.On<T>(interceptorAction);

internal async Task<HttpMessage> GetResponseMessageAsync(HttpMessage httpMessage,
CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions Samples/Dotmim.Sync.SampleConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ private static async Task SynchronizeExistingTablesAsync()
});

remoteProvider.InterceptDatabaseProvisioned(dpAction);
remoteProvider.OnDatabaseProvisioned(dpAction);

agent.LocalProvider.InterceptDatabaseProvisioned(dpAction);
agent.LocalProvider.OnDatabaseProvisioned(dpAction);

do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Post()
var provider = webProxyServer.GetLocalProvider(this.HttpContext);
provider.SetConfiguration(c =>c.Filters.Add("Customer", "CustomerId"));

provider.InterceptApplyChangesFailed(e =>
provider.OnApplyChangesFailed(e =>
{
if (e.Conflict.RemoteRow.Table.TableName == "Region")
{
Expand Down
20 changes: 10 additions & 10 deletions Tests/Dotmim.Sync.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ public virtual async Task Conflict_Insert_Insert_Client_Should_Wins_Coz_Handler_


this.testRunner.BeginRun = provider
=> provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(c => c.Resolution = ConflictResolution.ClientWins));
this.testRunner.EndRun = provider => provider.SetInterceptor(null);
=> provider.On(new Interceptor<ApplyChangesFailedArgs>(c => c.Resolution = ConflictResolution.ClientWins));
this.testRunner.EndRun = provider => provider.On(null);

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

Expand Down Expand Up @@ -850,7 +850,7 @@ public virtual async Task Conflict_Update_Update_Client_Should_Wins_Coz_Handler_


this.testRunner.BeginRun = provider =>
provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(args =>
provider.On(new Interceptor<ApplyChangesFailedArgs>(args =>
args.Resolution = ConflictResolution.ClientWins));

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

this.testRunner.BeginRun = provider
=> provider.SetInterceptor(new Interceptor<ApplyChangesFailedArgs>(args =>
=> provider.On(new Interceptor<ApplyChangesFailedArgs>(args =>
{
args.Resolution = ConflictResolution.MergeRow;
args.FinalRow["Name"] = productCategoryNameMerged;
}));


this.testRunner.EndRun = provider => provider.SetInterceptor(null);
this.testRunner.EndRun = provider => provider.On(null);


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


// just check interceptor
localProvider.SetInterceptor(new Interceptor<TableProvisioningArgs>(args =>
localProvider.On(new Interceptor<TableProvisioningArgs>(args =>
{
Assert.Equal(SyncProvision.All, args.Provision);
}));
Expand Down Expand Up @@ -1357,7 +1357,7 @@ public virtual async Task Use_Existing_Client_Database_Provision_Deprosivion()
}

// just check interceptor
localProvider.SetInterceptor(new Interceptor<TableDeprovisioningArgs>(args =>
localProvider.On(new Interceptor<TableDeprovisioningArgs>(args =>
{
Assert.Equal(SyncProvision.All, args.Provision);
}));
Expand Down Expand Up @@ -1414,7 +1414,7 @@ public virtual async Task Use_Existing_Client_Database_Provision_Deprosivion()
}


localProvider.SetInterceptor(null);
localProvider.On(null);


}
Expand Down Expand Up @@ -1596,7 +1596,7 @@ Task tableChangesSelected(TableChangesSelectedArgs changes)
};

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

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

clientRun.ClientProvider.SetInterceptor(null);
clientRun.ClientProvider.On(null);

var trr2 = await clientRun.RunAsync(this.fixture, null, conf, false);
Debug.WriteLine($"{trr2.ClientProvider.ConnectionString}: Upload={trr2.Results.TotalChangesUploaded}");
Expand Down
2 changes: 1 addition & 1 deletion Tests/Dotmim.Sync.Tests/HelperDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Dotmim.Sync.Tests
public static class HelperDB
{

public static Func<String, String> GetSqlConnectionString;
public static Func<string, string> GetSqlConnectionString;


/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Dotmim.Sync.Tests/Models/AdventureWorksContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public partial class AdventureWorksContext : DbContext
{
internal bool useSchema = false;
internal bool useSeeding = false;
public ProviderType ProviderType { get; }
public string ConnectionString { get; }
public ProviderType ProviderType { get; set; }
public string ConnectionString { get; set; }

private DbConnection Connection { get; }

Expand Down
81 changes: 81 additions & 0 deletions Tests/Dotmim.Sync.Tests/Sqlite/SqliteEncryptedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Dotmim.Sync.Tests.Core;
using Dotmim.Sync.Tests.Misc;
using Dotmim.Sync;
using System;
using System.Threading.Tasks;
using Xunit;
using Dotmim.Sync.Tests.SqlServer;
using Dotmim.Sync.SqlServer;
using Dotmim.Sync.Sqlite;
using Dotmim.Sync.Tests.Models;

namespace Dotmim.Sync.Tests.Sqlite
{
/// <summary>
/// this is the class which implements concret fixture with SqlSyncProviderFixture
/// and will call all the base tests
/// </summary>
[TestCaseOrderer("Dotmim.Sync.Tests.Misc.PriorityOrderer", "Dotmim.Sync.Tests")]
[Collection("Sqlite")]
public class SqliteEncryptedTests
{
private string[] sqlTables;
private SqlSyncProvider serverProvider;
private SqliteSyncProvider clientProvider;
private string serverCString = HelperDB.GetConnectionString(ProviderType.Sql, "AdvWorksForEncrypted");
private string clientCString = HelperDB.GetConnectionString(ProviderType.Sqlite, "EncryptedAdventureWorks.db");

public SqliteEncryptedTests()
{
this.sqlTables = new string[]
{
"SalesLT.ProductCategory", "SalesLT.ProductModel", "SalesLT.Product", "Employee", "Customer", "Address", "CustomerAddress", "EmployeeAddress",
"SalesLT.SalesOrderHeader", "SalesLT.SalesOrderDetail", "dbo.Sql", "Posts", "Tags", "PostTag",
"PricesList", "PriceListCategory", "PriceListDetail"
};


this.serverProvider = new SqlSyncProvider(serverCString);
this.clientProvider = new SqliteSyncProvider(clientCString);
}

[Fact, TestPriority(1)]
public async Task Initialize()
{
try
{

using (var ctx = new AdventureWorksContext())
{
ctx.ProviderType = ProviderType.Sql;
ctx.ConnectionString = this.serverCString;
ctx.useSeeding = true;
ctx.useSchema = true;

ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
}

var agent = new SyncAgent(this.clientProvider, this.serverProvider, this.sqlTables);

agent.LocalProvider.OnConnectionOpen(args =>
{
var keyCommand = args.Connection.CreateCommand();
keyCommand.CommandText = "PRAGMA key = 'password';";
keyCommand.ExecuteNonQuery();
});

var s = await agent.SynchronizeAsync();

Assert.Equal(109, s.TotalChangesDownloaded);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}

}
}
7 changes: 7 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ jobs:
"MYSQLIP": $(setvarStep.mySQLIP)
"AZUREDEV": "true"

- script: dotnet test Tests/Dotmim.Sync.Tests/Dotmim.Sync.Tests.csproj --filter SqliteEncryptedTests --logger trx
name: SqliteEncryptedTests
displayName: "Tests with SQL Server acting as server and encrypted SQLite database"
env:
"MYSQLIP": $(setvarStep.mySQLIP)
"AZUREDEV": "true"

- script: dotnet test Tests/Dotmim.Sync.Tests/Dotmim.Sync.Tests.csproj --filter MySqlBasicTests --logger trx
name: MySqlBasicTests
displayName: "Tests with MySQL Server acting as server"
Expand Down

0 comments on commit 8a066c0

Please sign in to comment.