public async System.Threading.Tasks.Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new SyncConfiguration("myPart", user);
            var realm = await Realm.GetInstanceAsync(config);

            var synchronousRealm = Realm.GetInstance(config);
            var testTask         = new Task
            {
                Name   = "Do this thing",
                Status = TaskStatus.Open.ToString()
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            testTaskId = testTask.Id;

            return;
        }
        public async System.Threading.Tasks.Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new PartitionSyncConfiguration("foo", user);
            //:hide-start:
            config.Schema = new[]
            {
                typeof(UserTask),
                typeof(UserProject)
            };
            //:hide-end:
            var realm = await Realm.GetInstanceAsync(config);

            var synchronousRealm = await Realm.GetInstanceAsync(config);

            var t = new UserTask()
            {
                Priority = 100, ProgressMinutes = 5, Assignee = "Jamie"
            };
            var t2 = new UserTask()
            {
                Priority = 1, ProgressMinutes = 500, Assignee = "Elvis"
            };
            var up = new UserProject()
            {
                Name = "A Big Project"
            };

            up.Tasks.Add(t);
            up.Tasks.Add(t2);
            realm.Write(() =>
            {
                realm.Add(t);
                realm.Add(t2);
                realm.Add(up);
            });
            return;
        }
Beispiel #3
0
        public async System.Threading.Tasks.Task Setup()
        {
            // :code-block-start: initialize-realm
            app = App.Create(myRealmAppId);
            // :code-block-end:
            user = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            // :code-block-start: open-synced-realm
            config = new SyncConfiguration("myPart", user);
            var realm = await Realm.GetInstanceAsync(config);

            // :code-block-end:
            // :code-block-start: open-synced-realm-sync
            var synchronousRealm = Realm.GetInstance(config);
            // :code-block-end:
            // :code-block-start: create
            var testTask = new Task
            {
                Name      = "Do this thing",
                Status    = TaskStatus.Open.ToString(),
                Partition = "myPart"
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            // :code-block-end:
            testTaskId = testTask.Id;

            /* var schemas = config.ObjectClasses;
             * foreach (var schema in schemas)
             * {
             *   Console.WriteLine(schema.FullName);
             * }*/


            return;
        }
Beispiel #4
0
        public void Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new SyncConfiguration("myPartition", user);

            // Synchronous here because setup and tear down don't support async
            var realm = Realm.GetInstance(config);

            // :code-block-start:create
            Address address = new Address() // Create an Address
            {
                Street     = "123 Fake St.",
                City       = "Springfield",
                Country    = "USA",
                PostalCode = "90710"
            };

            Contact contact = new Contact() // Create a Contact
            {
                Name    = "Nick Riviera",
                Address = address // Embed the Address Object
            };

            realm.Write(() =>
            {
                realm.Add(contact);
            });
            //:code-block-end:

            var contacts = realm.All <Contact>();

            // Test that the Contact document has been created
            Assert.AreEqual(contacts.Count(), 1);

            // Test that the first (and only) Contact document has an embedded Address with a Street of "123 Fake St."
            Assert.AreEqual(contacts.FirstOrDefault().Address.Street, "123 Fake St.");
        }
Beispiel #5
0
        public async Task Setup()
        {
            app              = App.Create(myRealmAppId);
            user             = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config           = new SyncConfiguration("myPart", user);
            mongoClient      = user.GetMongoClient("mongodb-atlas");
            dbPlantInventory = mongoClient.GetDatabase("inventory");
            plantsCollection = dbPlantInventory.GetCollection <Plant>("plants");

            venus = new Plant
            {
                Name      = "Venus Flytrap",
                Sunlight  = Sunlight.Full,
                Color     = PlantColor.White,
                Type      = PlantType.Perennial,
                Partition = "Store 42"
            };
            sweetBasil = new Plant
            {
                Name      = "Sweet Basil",
                Sunlight  = Sunlight.Partial,
                Color     = PlantColor.Green,
                Type      = PlantType.Annual,
                Partition = "Store 42"
            };
            thaiBasil = new Plant
            {
                Name      = "Thai Basil",
                Sunlight  = Sunlight.Partial,
                Color     = PlantColor.Green,
                Type      = PlantType.Perennial,
                Partition = "Store 42"
            };
            helianthus = new Plant
            {
                Name      = "Helianthus",
                Sunlight  = Sunlight.Full,
                Color     = PlantColor.Yellow,
                Type      = PlantType.Annual,
                Partition = "Store 42"
            };
            petunia = new Plant
            {
                Name      = "Petunia",
                Sunlight  = Sunlight.Full,
                Color     = PlantColor.Purple,
                Type      = PlantType.Annual,
                Partition = "Store 47"
            };

            var listofPlants = new List <Plant>
            {
                venus,
                sweetBasil,
                thaiBasil,
                helianthus,
                petunia
            };

            var insertResult = await plantsCollection.InsertManyAsync(listofPlants);



            return;
        }
        public async Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new PartitionSyncConfiguration("myPart", user);
            //:hide-start:
            config.Schema = new[] { typeof(Plant) };
            //:hide-end:
            SetupPlantCollection();

            await plantsCollection.DeleteManyAsync();

            venus = new Plant
            {
                Name      = "Venus Flytrap",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.White.ToString(),
                Type      = PlantType.Perennial.ToString(),
                Partition = "Store 42"
            };
            sweetBasil = new Plant
            {
                Name      = "Sweet Basil",
                Sunlight  = Sunlight.Partial.ToString(),
                Color     = PlantColor.Green.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 42"
            };
            thaiBasil = new Plant
            {
                Name      = "Thai Basil",
                Sunlight  = Sunlight.Partial.ToString(),
                Color     = PlantColor.Green.ToString(),
                Type      = PlantType.Perennial.ToString(),
                Partition = "Store 42"
            };
            helianthus = new Plant
            {
                Name      = "Helianthus",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.Yellow.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 42"
            };
            petunia = new Plant
            {
                Name      = "Petunia",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.Purple.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 47"
            };

            var listofPlants = new List <Plant>
            {
                venus,
                sweetBasil,
                thaiBasil,
                helianthus,
                petunia
            };

            var insertResult = await plantsCollection.InsertManyAsync(listofPlants);



            return;
        }
Beispiel #7
0
        public async System.Threading.Tasks.Task LogsOnManyWays()
        {
            {
                // :code-block-start: logon_anon
                var user = await app.LogInAsync(Credentials.Anonymous());

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                // :code-block-start: logon_EP
                var user = await app.LogInAsync(
                    Credentials.EmailPassword("*****@*****.**", "shhhItsASektrit!"));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                var apiKey = "F5ONly653MyQEq781wR4LT3nu3eGmIf0uDhHnkpsAkXyvsbPee8RqJyv6HVzM9dU";
                // :code-block-start: logon_API
                var user = await app.LogInAsync(Credentials.ApiKey(apiKey));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                // :code-block-start: logon_Function
                var functionParameters = new
                {
                    username = "******",
                    password = "******",
                    IQ       = 42,
                    isCool   = false
                };

                var user =
                    await app.LogInAsync(Credentials.Function(functionParameters));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                var jwt_token =
                    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
                    "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6ImNhbGViQGV4YW1wbGUuY29tIiwiaWF0IjoxNjAxNjc4ODcyLCJleHAiOjI1MTYyMzkwMjIsImF1ZCI6InNuaXBwZXRzZG9ub3RkZWxldGUtcXJvdXEifQ." +
                    "Qp-sRcKAyuS5ONeBDvZuSg6-YAzohCdU3yKLnz7MXbI";
                // :code-block-start: logon_JWT
                var user =
                    await app.LogInAsync(Credentials.JWT(jwt_token));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            try
            {
                var facebookToken = "";
                // :code-block-start: logon_fb
                var user =
                    await app.LogInAsync(Credentials.Facebook(facebookToken));

                // :code-block-end:
            }
            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-facebook' is unsupported", e.Message);
            }
            try
            {
                var googleAuthCode = "";
                // :code-block-start: logon_google
                var user =
                    await app.LogInAsync(Credentials.Google(googleAuthCode, GoogleCredentialType.AuthCode));

                // :code-block-end:
            }
            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-google' is unsupported", e.Message);
            }
            try
            {
                var appleToken = "";
                // :code-block-start: logon_apple
                var user =
                    await app.LogInAsync(Credentials.Apple(appleToken));

                // :code-block-end:
            }

            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-apple' is unsupported", e.Message);
            }
        }
Beispiel #8
0
        public async System.Threading.Tasks.Task Setup()
        {
            // :code-block-start: initialize-realm
            app = App.Create(myRealmAppId);
            // :code-block-end:
            user = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            // :code-block-start: open-synced-realm
            config = new SyncConfiguration("myPart", user);
            //:hide-start:
            config.ObjectClasses = new[]
            {
                typeof(Task),
                typeof(MyClass),
                typeof(dotnet.User),
                typeof(CustomGetterSetter)
            };
            Realm realm;

            //:hide-end:
            try
            {
                realm = await Realm.GetInstanceAsync(config);
            }
            catch (RealmFileAccessErrorException ex)
            {
                Console.WriteLine($@"Error creating or opening the
                    realm file. {ex.Message}");
            }
            //:hide-start:
            realm = await Realm.GetInstanceAsync(config);

            realm.Write(() =>
            {
                realm.RemoveAll <Task>();
            });
            //:hide-end:
            // :code-block-end:
            // :code-block-start: open-synced-realm-sync
            var synchronousRealm = await Realm.GetInstanceAsync(config);

            // :code-block-end:
            // :code-block-start: create
            var testTask = new Task
            {
                Name      = "Do this thing",
                Status    = TaskStatus.Open.ToString(),
                Partition = "myPart"
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            // :code-block-end:
            testTaskId = testTask.Id;

            /* var schemas = config.ObjectClasses;
             * foreach (var schema in schemas)
             * {
             *   Console.WriteLine(schema.FullName);
             * }*/


            return;
        }
        public async System.Threading.Tasks.Task LogsOnManyWays()
        {
            {
                // :code-block-start: logon_anon
                var user = await app.LogInAsync(Credentials.Anonymous());

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                // :code-block-start: logon_EP
                var user = await app.LogInAsync(
                    Credentials.EmailPassword("*****@*****.**", "shhhItsASektrit!"));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                var apiKey = "eRECwv1e6gkLEse99XokWOgegzoguEkwmvYvXk08zAucG4kXmZu7TTgV832SwFCv";
                // :code-block-start: logon_API
                var user = await app.LogInAsync(Credentials.ApiKey(apiKey));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                // :code-block-start: logon_Function
                var functionParameters = new
                {
                    username = "******",
                    password = "******",
                    IQ       = 42,
                    isCool   = false
                };

                var user =
                    await app.LogInAsync(Credentials.Function(functionParameters));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            {
                var jwt_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkNhbGViIiwiaWF0IjoxNjAxNjc4ODcyLCJleHAiOjI1MTYyMzkwMjIsImF1ZCI6InR1dHMtdGlqeWEifQ.LHbeSI2FDWrlUVOBxe-rasuFiW-etv2Gu5e3eAa6Y6k";
                // :code-block-start: logon_JWT
                var user =
                    await app.LogInAsync(Credentials.JWT(jwt_token));

                // :code-block-end:
                Assert.AreEqual(UserState.LoggedIn, user.State);
                await user.LogOutAsync();
            }
            try
            {
                var facebookToken = "";
                // :code-block-start: logon_fb
                var user =
                    await app.LogInAsync(Credentials.Facebook(facebookToken));

                // :code-block-end:
            }
            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-facebook' is unsupported", e.Message);
            }
            try
            {
                var googleAuthCode = "";
                // :code-block-start: logon_google
                var user =
                    await app.LogInAsync(Credentials.Google(googleAuthCode, GoogleCredentialType.AuthCode));

                // :code-block-end:
            }
            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-google' is unsupported", e.Message);
            }
            try
            {
                var appleToken = "";
                // :code-block-start: logon_apple
                var user =
                    await app.LogInAsync(Credentials.Apple(appleToken));

                // :code-block-end:
            }

            catch (Exception e)
            {
                Assert.AreEqual("InvalidSession: authentication via 'oauth2-apple' is unsupported", e.Message);
            }
        }