Skip to content

Commit

Permalink
change text
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsales committed Sep 11, 2024
1 parent adc115b commit 6913cec
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/SSync.Server.LiteDB.PlayGround/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ internal class Finance
public DateTime? DeletedAt { get; set; }
}

internal class PlayParamenter : SSyncParamenter
internal class PlayParamenter : SSyncParameter
{
public int Time { get; set; } = new Random().Next(100);
}
Expand All @@ -280,11 +280,11 @@ public FinanceSync(Guid id) : base(id)
public double Price { get; set; }
}

internal class PullUserRequesHandler : ISSyncPullRequest<UserSync, PlayParamenter>
internal class PullUserRequestHandler : ISSyncPullRequest<UserSync, PlayParamenter>
{
private readonly TestDbContext _ctx;

public PullUserRequesHandler(TestDbContext ctx)
public PullUserRequestHandler(TestDbContext ctx)
{
_ctx = ctx;
}
Expand All @@ -303,11 +303,11 @@ public async Task<IEnumerable<UserSync>> QueryAsync(PlayParamenter parameter)
}
}

internal class PullFinanceRequesHandler : ISSyncPullRequest<FinanceSync, PlayParamenter>
internal class PullFinanceRequestHandler : ISSyncPullRequest<FinanceSync, PlayParamenter>
{
private readonly TestDbContext _ctx;

public PullFinanceRequesHandler(TestDbContext ctx)
public PullFinanceRequestHandler(TestDbContext ctx)
{
_ctx = ctx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IPullExecutionOrderStep

IPullExecutionOrderStep ThenBy<TSync>(string collection) where TSync : ISchema;

Task ExecuteAsync<TParameter>(TParameter parameter, string[] filter) where TParameter : SSyncParamenter;
Task ExecuteAsync<TParameter>(TParameter parameter, string[] filter) where TParameter : SSyncParameter;

List<(Type SyncType, string Parameter)> GetSteps();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SSync.Server.LitebDB.Abstractions.Sync
{
public interface ISSyncPullRequest<TSchema, in TParameter>
where TSchema : ISchema
where TParameter : SSyncParamenter
where TParameter : SSyncParameter
{
Task<IEnumerable<TSchema>> QueryAsync(TParameter parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ IInternalISSyncPushRequest<TRequestSchema> PushRequestHandler<TRequestSchema>()

ISSyncPullRequest<TRequestCollectionSchema, TParameter> PullRequestHandler<TRequestCollectionSchema, TParameter>()
where TRequestCollectionSchema : ISchema
where TParameter : SSyncParamenter;
where TParameter : SSyncParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace SSync.Server.LitebDB.Abstractions
{
public interface ISchemaCollection
{
Task<List<object>> PullChangesAsync(SSyncParamenter parameter, SSyncOptions? options = null);
Task<List<object>> PullChangesAsync(SSyncParameter parameter, SSyncOptions? options = null);

Task<bool> PushChangesAsync(JsonArray changes, SSyncParamenter parameter, SSyncOptions? options = null);
Task<bool> PushChangesAsync(JsonArray changes, SSyncParameter parameter, SSyncOptions? options = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public IPullExecutionOrderStep ThenBy<TSync>(string collection) where TSync : IS
public List<(Type SyncType, string Parameter)> GetSteps() => _steps;

public async Task ExecuteAsync<TParameter>(TParameter parameter, string[] filter)
where TParameter : SSyncParamenter
where TParameter : SSyncParameter
{
var steps = GetSteps();
foreach (var (SyncType, Parameter) in steps)
Expand Down
2 changes: 1 addition & 1 deletion src/SSync.Server.LitebDB/Engine/SSyncParamenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SSync.Server.LitebDB.Engine
{
public class SSyncParamenter
public class SSyncParameter
{
public string[] Colletions { get; set; } = [];
public long Timestamp { get; set; } = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/SSync.Server.LitebDB/Services/SSyncServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public SSyncServices(IServiceProvider serviceProvider)

public ISSyncPullRequest<TRequestSchema, TParameter> PullRequestHandler<TRequestSchema, TParameter>()
where TRequestSchema : ISchema
where TParameter : SSyncParamenter
where TParameter : SSyncParameter
=> ServiceProvider.GetRequiredService<ISSyncPullRequest<TRequestSchema, TParameter>>();

public IInternalISSyncPushRequest<TRequestSchema> PushRequestHandler<TRequestSchema>() where TRequestSchema : ISchema
Expand Down
10 changes: 5 additions & 5 deletions src/SSync.Server.LitebDB/Sync/SchemaCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SchemaCollection(ISSyncServices syncServices,
_sSyncDbContextTransaction = sSyncDbContextTransaction;
}

public async Task<List<object>> PullChangesAsync(SSyncParamenter parameter, SSyncOptions? options = null)
public async Task<List<object>> PullChangesAsync(SSyncParameter parameter, SSyncOptions? options = null)
{
if (parameter.Colletions.Length == 0)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task<List<object>> PullChangesAsync(SSyncParamenter parameter, SSyn
return result;
}

public async Task<bool> PushChangesAsync(JsonArray changes, SSyncParamenter parameter, SSyncOptions? optionsSync = null)
public async Task<bool> PushChangesAsync(JsonArray changes, SSyncParameter parameter, SSyncOptions? optionsSync = null)
{
_options = optionsSync;

Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task<bool> PushChangesAsync(JsonArray changes, SSyncParamenter para

private async Task<SchemaPullResult<TCollection>> CheckChanges<TCollection, TParamenter>(TParamenter paramenter)
where TCollection : ISchema
where TParamenter : SSyncParamenter
where TParamenter : SSyncParameter
{
if (paramenter.Colletions.Length == 0)
{
Expand Down Expand Up @@ -224,7 +224,7 @@ private async Task<SchemaPullResult<TCollection>> CheckChanges<TCollection, TPar
return changesOfTime;
}

private async Task<long> ExecuteChanges(JsonArray changes, SSyncParamenter parameter)
private async Task<long> ExecuteChanges(JsonArray changes, SSyncParameter parameter)
{
try
{
Expand Down Expand Up @@ -278,7 +278,7 @@ private async Task<long> ExecuteChanges(JsonArray changes, SSyncParamenter param
}
}

private async Task<bool> ParseChanges<TSchema>(JsonNode nodeChange, SSyncParamenter parameter)
private async Task<bool> ParseChanges<TSchema>(JsonNode nodeChange, SSyncParameter parameter)
where TSchema : ISchema
{
var jsonChange = nodeChange.ToJsonString();
Expand Down
48 changes: 33 additions & 15 deletions test/SSync.Server.LitebDB.Tests/Sync/PullChanges_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ namespace SSync.Server.LitebDB.Tests.Sync
{
public class PullChanges_Tests
{

[Fact]
public async Task NoSetupChanges_SchoudReturnNull()
{
var parameter = new SSyncParamenter()
var parameter = new SSyncParameter()
{
Colletions = [],
Timestamp = 0
Expand All @@ -30,7 +29,7 @@ public async Task NoSetupChanges_SchoudReturnNull()
[Fact]
public async Task SetNoneCollection_ShouldReturnPullChangesException()
{
var parameter = new SSyncParamenter()
var parameter = new SSyncParameter()
{
Colletions = [],
Timestamp = 0
Expand All @@ -52,11 +51,10 @@ public async Task SetNoneCollection_ShouldReturnPullChangesException()
Assert.Equal("You need set collections", exception.Message);
}


[Fact]
public async Task SetTimeStampLessThanZero_ShouldReturnPullChangesException()
{
var parameter = new SSyncParamenter()
var parameter = new SSyncParameter()
{
Colletions = ["User"],
Timestamp = -1
Expand All @@ -83,20 +81,21 @@ public async Task SetTimeStampLessThanZero_ShouldReturnPullChangesException()
[Fact]
public async Task SetTimeStampEqualZero_ShouldReturnPullChangesOnlyCreated()
{
var parameter = new SSyncParamenter()
var parameter = new SSyncParameter()
{
Colletions = ["User"],
Timestamp = 0
};

var syncServiceMock = new Mock<ISSyncServices>();
var pullExecutionMock= new Mock<IPullExecutionOrderStep>();
var pullExecutionMock = new Mock<IPullExecutionOrderStep>();
var pushExecutionMock = new Mock<IPushExecutionOrderStep>();
var syncDbContextTransactionMock = new Mock<ISSyncDbContextTransaction>();

//create setup memory database
//insert rows
//update this rows
//create setup pull_change_user_handler

pullExecutionMock.Setup(s => s.By<UserSync>("user"));

Expand All @@ -105,19 +104,38 @@ public async Task SetTimeStampEqualZero_ShouldReturnPullChangesOnlyCreated()
var changes = await schemaCollection.PullChangesAsync(parameter);

//should return only created rows

}


//TODO: CREATE TEST CHECK TIMESTAMP AND RETURN CHANGE CREATE OR UPDATE OR DELETE

}
}

internal class UserSync(Guid id) : ISchema(id)
{
public string? Name { get; set; }
}


public class UserSync(Guid id) : ISchema(id)
{
public string? Name { get; set; }
}

//TODO: create context moq or memory
//internal class PullUserRequestHandler : ISSyncPullRequest<UserSync, SSyncParameter>
//{
// private readonly TestDbContext _ctx;

// public PullUserRequestHandler(TestDbContext ctx)
// {
// _ctx = ctx;
// }

// public async Task<IEnumerable<UserSync>> QueryAsync(SSyncParameter parameter)
// {
// var users = await _ctx.User.Select(u => new UserSync(u.Id)
// {
// Name = u.Name,
// CreatedAt = u.CreatedAt,
// DeletedAt = u.DeletedAt,
// UpdatedAt = u.UpdatedAt
// }).ToListAsync();

// return users;
// }
//}

0 comments on commit 6913cec

Please sign in to comment.