Skip to content

Commit 749453a

Browse files
committed
add tests for sync session
1 parent 16cd3b3 commit 749453a

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed
Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,58 @@
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+
[OneTimeSetUp]
18+
public void Setup()
19+
{
20+
21+
const string myRealmAppId = Config.FSAppId;
22+
app = App.Create(myRealmAppId);
23+
user = app.LogInAsync(
24+
Credentials.Anonymous()).Result;
25+
26+
config = new FlexibleSyncConfiguration(user)
27+
;
28+
}
29+
30+
[Test]
31+
public void StartStopSession()
1132
{
12-
realm = Realm.GetInstance();
1333
// :snippet-start: pause-synced-realm
34+
realm = Realm.GetInstance(config);
1435
var session = realm.SyncSession;
1536
session.Stop();
1637
//later...
1738
session.Start();
1839
// :snippet-end:
1940
}
41+
42+
[Test]
43+
public void GetSessionAndState(){
44+
// :snippet-start: get-sync-session
45+
realm = Realm.GetInstance(config);
46+
var session = realm.SyncSession;
47+
// :snippet-end:
48+
// :snippet-start: get-session-state
49+
var sessionState = session.State;
50+
if (sessionState == SessionState.Active){
51+
Console.WriteLine("The session is active");
52+
} else {
53+
Console.WriteLine("The session is inactive");
54+
}
55+
// :snippet-end:
56+
}
2057
}
2158
}
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;

source/examples/generated/dotnet/DataSyncExamples.snippet.pause-synced-realm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
realm = Realm.GetInstance(config);
12
var session = realm.SyncSession;
23
session.Stop();
34
//later...

0 commit comments

Comments
 (0)