Beispiel #1
0
        public async Task DocumentBaseTest()
        {
            RepoContext.AddDocumentDbRepo(endpoint, key, dbName, collection);

            foreach (var c in await ContactDoc.GetAll())
            {
                await ContactDoc.Remove(c.id);
            }

            var contact = new ContactDoc()
            {
                DateAdded = DateTime.UtcNow,
                FirstName = "John",
                LastName  = "Doe",
                Addresses = new List <Address>()
            };

            contact.Addresses.Add(new Address()
            {
                Line1       = "123 Sample st.",
                Line2       = null,
                CountryCode = "US",
                StateCode   = "IL",
                PostalCode  = "9876543"
            });

            await ContactDoc.Create(contact);

            var contact2 = await ContactDoc.Get(contact.id);

            DoDocAsserts(contact, contact2);

            var contact3 = await ContactDoc.First(c => c.FirstName == contact.FirstName && c.LastName == contact.LastName);

            DoDocAsserts(contact, contact3);

            var contact4 = await ContactDoc.FindById(contact.id);

            DoDocAsserts(contact, contact4);

            var contact5 = (await ContactDoc.Where(c => c.FirstName == contact.FirstName && c.LastName == contact.LastName)).ToList();

            DoDocAsserts(contact, contact5[0]);

            var query    = String.Format("select * from c where c._docType ='ContactDoc' and c.id = '{0}'", contact.id);
            var contact6 = (await ContactDoc.Query(query)).ToList();

            DoDocAsserts(contact, contact6[0]);

            contact.FirstName = "William";
            await ContactDoc.Upsert(contact);

            var contact7 = await ContactDoc.First(c => c.FirstName == "William");

            DoDocAsserts(contact, contact7);

            await ContactDoc.Remove(contact.id);

            var contact8 = await ContactDoc.FirstOrDefault(c => c.id == contact.id);

            Assert.IsNull(contact8);
        }