Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
(#484) Added PendingOperations to client. (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhall authored Sep 30, 2022
1 parent a6a7a07 commit 849088a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,10 @@ public override void DefineTable(string tableName, JObject tableDefinition)
Arguments.IsValidTableName(tableName, true, nameof(tableName));
Arguments.IsNotNull(tableDefinition, nameof(tableDefinition));

//if (Initialized)
//{
// throw new InvalidOperationException("Cannot define a table after the offline store has been initialized.");
//}
if (!tableMap.ContainsKey(tableName))
{
tableMap.Add(tableName, new TableDefinition(tableName, tableDefinition));
}
//else
//{
// throw new InvalidOperationException("Cannot define a table twice");
//}
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions sdk/dotnet/src/Microsoft.Datasync.Client/DatasyncClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public DatasyncClient(Uri endpoint, AuthenticationProvider authenticationProvide
/// </summary>
public string InstallationId { get => HttpClient.InstallationId; }

/// <summary>
/// The number of pending operations, or null if the offline store has not been defined.
/// </summary>
public long? PendingOperations { get => SyncContext?.PendingOperations; }

/// <summary>
/// The serializer to use for serializing and deserializing content.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ internal SyncContext(DatasyncClient client, IOfflineStore store)
/// </remarks>
internal IPushContext PushContext { get; set; }

/// <summary>
/// The number of pending operations in the operations queue.
/// </summary>
internal long PendingOperations { get => OperationsQueue.PendingOperations; }

/// <summary>
/// Initialize the synchronization context for this offline store.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async Task DeleteItemAsync_Basic()
// Act
await table!.DeleteItemAsync(item);
Assert.Equal(MovieCount, MovieServer.GetMovieCount());
Assert.Equal(1, client.PendingOperations);

await table!.PushItemsAsync();
Assert.Equal(MovieCount - 1, MovieServer.GetMovieCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public async Task CreateItemAsync_Basic()

// Act
await table!.InsertItemAsync(movieToAdd);

// There should be one pending operation right now.
Assert.Equal(1, client.PendingOperations);

await table!.PushItemsAsync();
var result = await table!.GetItemAsync(movieToAdd.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public async Task ReplaceItemAsync_Basic()

// Act
await table!.ReplaceItemAsync(expected);

// There should be one pending operation
Assert.Equal(1, client.PendingOperations);

await table!.PushItemsAsync();
var response = await table!.GetItemAsync(id);

Expand Down

0 comments on commit 849088a

Please sign in to comment.