Skip to content

Commit 60f6a06

Browse files
authored
Add tests & snippets for sync session (#3334)
## Pull Request Info - SDK Docs Consolidation Jira ticket: https://jira.mongodb.org/browse/DOCSP-40247 *Staged Page* n/a ### New snippet locations **Get sync session** `source/examples/generated/dotnet/DataSyncExamples.snippet.get-sync-session.cs` **Check sync state** `source/examples/generated/dotnet/DataSyncExamples.snippet.get-session-state.cs` **Upload and Download Progress** `source/examples/generated/dotnet/ProgressNotifications.snippet.upload-download-progress-notification.cs`
1 parent 16cd3b3 commit 60f6a06

10 files changed

+77
-13
lines changed

examples/dotnet/Examples/BundleARealmExamples.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,37 @@ public async Task TestWriteCopySynced()
7373
// Want to know where the copy is?
7474
var locationOfCopy = existingConfig.DatabasePath;
7575
// :snippet-end:
76+
77+
// :snippet-start: get-sync-session
78+
// :replace-start: {
79+
// "terms": {
80+
// "bundledConfig": "config"
81+
// }
82+
// }
83+
// :replace-end:
84+
realm = Realm.GetInstance(bundledConfig);
85+
// :uncomment-start:
86+
// var session = realm.SyncSession;
87+
// :uncomment-end:
88+
// :snippet-end:
89+
// :snippet-start: pause-synced-realm
90+
// :uncomment-start:
91+
// realm = Realm.GetInstance(config);
92+
// :uncomment-end:
93+
session = realm.SyncSession;
94+
session.Stop();
95+
//later...
96+
session.Start();
97+
// :snippet-end:
98+
// :snippet-start: get-session-state
99+
var sessionState = session.State;
100+
if (sessionState == SessionState.Active){
101+
Console.WriteLine("The session is active");
102+
} else {
103+
Console.WriteLine("The session is inactive");
104+
}
105+
// :snippet-end:
106+
76107
}
77108

78109

@@ -84,6 +115,7 @@ public async Task ExtractAndLoadRealmFile()
84115
// "terms": {
85116
// "Config.AppId": "\"myRealmAppId\""}
86117
// }
118+
// :replace-end:
87119
// If you are using a local realm
88120
var config = RealmConfiguration.DefaultConfiguration;
89121

@@ -94,7 +126,6 @@ public async Task ExtractAndLoadRealmFile()
94126
// :remove-start:
95127
config.Schema = new[] { typeof(Examples.Models.User) };
96128
// :remove-end:
97-
// :replace-end:
98129

99130
// Extract and copy the realm
100131
if (!File.Exists(config.DatabasePath))
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
using Realms;
1+
using System;
2+
using Microsoft.VisualBasic;
3+
using NUnit.Framework;
4+
using NUnit.Framework.Internal;
5+
using Realms;
26
using Realms.Sync;
37

48
namespace Examples
59
{
610
public class DataSyncExamples
711
{
812
Realm realm;
13+
App app;
14+
Realms.Sync.User user;
15+
FlexibleSyncConfiguration config;
916

10-
public void TestsCustomSetter()
17+
18+
public void Setup()
1119
{
12-
realm = Realm.GetInstance();
13-
// :snippet-start: pause-synced-realm
14-
var session = realm.SyncSession;
15-
session.Stop();
16-
//later...
17-
session.Start();
18-
// :snippet-end:
20+
const string myRealmAppId = Config.FSAppId;
21+
app = App.Create(myRealmAppId);
22+
user = app.LogInAsync(
23+
Credentials.Anonymous()).Result;
24+
25+
config = new FlexibleSyncConfiguration(user);
26+
}
27+
28+
public void GetSessionAndState(){
29+
1930
}
2031
}
2132
}

source/examples/generated/dotnet/BundleARealmExamples.snippet.extract_and_copy_realm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var config = RealmConfiguration.DefaultConfiguration;
33

44
// If the realm file is a synced realm
5-
var app = App.Create("myRealmAppId");
5+
var app = App.Create(Config.AppId);
66
var user = await app.LogInAsync(Credentials.Anonymous());
77
config = new PartitionSyncConfiguration("myPartition", user);
88

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var sessionState = session.State;
2+
if (sessionState == SessionState.Active){
3+
Console.WriteLine("The session is active");
4+
} else {
5+
Console.WriteLine("The session is inactive");
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
realm = Realm.GetInstance(bundledConfig);
2+
var session = realm.SyncSession;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
realm = Realm.GetInstance(config);
2+
session = realm.SyncSession;
3+
session.Stop();
4+
//later...
5+
session.Start();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var sessionState = session.State;
2+
if (sessionState == SessionState.Active){
3+
Console.WriteLine("The session is active");
4+
} else {
5+
Console.WriteLine("The session is inactive");
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
realm = Realm.GetInstance(config);
2+
var session = realm.SyncSession;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var session = realm.SyncSession;
1+
realm = Realm.GetInstance(config);
2+
session = realm.SyncSession;
23
session.Stop();
34
//later...
45
session.Start();

source/sdk/dotnet/sync/sync-session.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ method on the paused session, the Sync session resumes.
3131
The following code block demonstrates calling the ``Stop()`` and ``Start()``
3232
methods:
3333

34-
.. literalinclude:: /examples/generated/dotnet/DataSyncExamples.snippet.pause-synced-realm.cs
34+
.. literalinclude:: /examples/generated/dotnet/BundleARealmExamples.snippet.pause-synced-realm.cs
3535
:language: csharp
3636

3737
When to Pause a Sync Session

0 commit comments

Comments
 (0)