Esempio n. 1
0
        public async Task InsertsMany()
        {
            // :code-block-start: mongo-insert-many
            var sweetBasil = new Plant
            {
                Name      = "Sweet Basil",
                Sunlight  = Sunlight.partial,
                Color     = PlantColor.green,
                Type      = PlantType.annual,
                Partition = "Store 42"
            };
            var thaiBasil = new Plant
            {
                Name      = "Thai Basil",
                Sunlight  = Sunlight.partial,
                Color     = PlantColor.green,
                Type      = PlantType.perennial,
                Partition = "Store 42"
            };
            var helianthus = new Plant
            {
                Name      = "Helianthus",
                Sunlight  = Sunlight.full,
                Color     = PlantColor.yellow,
                Type      = PlantType.annual,
                Partition = "Store 42"
            };
            var petunia = new Plant
            {
                Name      = "Petunia",
                Sunlight  = Sunlight.full,
                Color     = PlantColor.purple,
                Type      = PlantType.annual,
                Partition = "Store 47"
            };

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

            var insertResult = await plantsCollection.InsertManyAsync(listofPlants);

            var newIds = insertResult.InsertedIds;

            // :code-block-end:

            Assert.AreEqual(newIds[0], sweetBasil.Id);
            Assert.AreEqual(newIds[1], thaiBasil.Id);
            Assert.AreEqual(newIds[2], helianthus.Id);
            Assert.AreEqual(newIds[3], petunia.Id);
        }
Esempio n. 2
0
        public async Task InsertsMany()
        {
            // :code-block-start: mongo-insert-many
            var sweetBasil = new Plant
            {
                Name      = "Sweet Basil",
                Sunlight  = Sunlight.Partial,
                Color     = PlantColor.Green,
                Type      = PlantType.Annual,
                Partition = "Store 42"
            };
            var thaiBasil = new Plant
            {
                Name      = "Thai Basil",
                Sunlight  = Sunlight.Partial,
                Color     = PlantColor.Green,
                Type      = PlantType.Perennial,
                Partition = "Store 42"
            };
            var helianthus = new Plant
            {
                Name      = "Helianthus",
                Sunlight  = Sunlight.Full,
                Color     = PlantColor.Yellow,
                Type      = PlantType.Annual,
                Partition = "Store 42"
            };
            var petunia = new Plant
            {
                Name      = "Petunia",
                Sunlight  = Sunlight.Full,
                Color     = PlantColor.Purple,
                Type      = PlantType.Annual,
                Partition = "Store 47"
            };

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

            var insertResult = await plantsCollection.InsertManyAsync(listofPlants);

            var newIds = insertResult.InsertedIds;
            // :code-block-end:
        }
Esempio n. 3
0
        public async Task Setup()
        {
            app              = App.Create(myRealmAppId);
            user             = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config           = new SyncConfiguration("myPartition", 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;
        }
Esempio n. 4
0
        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;
        }