public async Task TestCreateAndGetEntitiesUsingCache()
        {
            var c = Resolve<IDocumentEntityCache>();

            var t = new TestKeyEntity();

            t.Id = "JordanKey5";

            t.SubKey = new TestKeyEntity
            {
                PersonName = "Knight"
            };

            t.PersonName = "Jordan3";

            var k = Guid.NewGuid().ToString();

            var result = await c.SetEntity(k, t);

            Assert.IsTrue(result);


            var resultGet = await c.GetEntity<TestKeyEntity>(k);

            Assert.IsNotNull(resultGet);

            Assert.IsTrue(resultGet.PersonName == "Jordan3");

            var resultDelete = await c.Delete<TestKeyEntity>(k);

            Assert.IsTrue(resultDelete);

            var resultGet2 = await c.GetEntity<TestKeyEntity>(k);

            Assert.IsNull(resultGet2);
        }
        public async Task TestDocumentQueries()
        {
            var i = Resolve<IDocumentEntityCache>();

            var t = new TestKeyEntity()
            {
                Id = "Key1",
                PersonName = "PersonName",
                SubKey = new TestKeyEntity
                {
                    Id = "Key2",
                    PersonName = "PersonNameInner",
                }
            };

            var t2 = new TestKeyEntity()
            {
                Id = "Key3",
                PersonName = "PersonName2",
                SubKey = new TestKeyEntity
                {
                    Id = "Key4",
                    PersonName = "PersonNameInner2",
                }
            };

            var o = new OtherTestKeyEntity()
            {
                Id = "KeyOtherTestKeyEntity1",
                PersonName = "PersonName",
                SubKey = new OtherTestKeyEntity
                {
                    Id = "Key2",
                    PersonName = "PersonNameInner",
                }
            };

            var save = await i.SetEntity(t.Id, t);
            var save2 = await i.SetEntity(t2.Id, t2);
            var save3 = await i.SetEntity(o.Id, o);

            var load = await i.GetEntity<TestKeyEntity>(t.Id);
            var load2 = await i.GetEntity<TestKeyEntity>(t2.Id);

            Assert.IsNotNull(load);
            Assert.IsNotNull(load2);

            Assert.AreEqual(t.PersonName, load.PersonName);
            Assert.AreEqual(t2.PersonName, load2.PersonName);


            var query1 = await i.QueryEntity<TestKeyEntity>(_ => _.Item.PersonName.Contains("PersonName"));

            Assert.IsNotNull(query1);
            Assert.IsTrue(query1.Count > 1);

            var query2 = await i.QueryEntity<OtherTestKeyEntity>(_ => _.Item.PersonName == "PersonName");

            Assert.IsNotNull(query2);
            Assert.IsTrue(query2.Count > 0);


            var query3 = await i.QueryEntity<OtherTestKeyEntity>("SELECT * FROM TestCollection C Where C.Item.PersonName = 'PersonName'");

            Assert.IsNotNull(query3);
            Assert.IsTrue(query3.Count > 0);

            var query4actual = await i.GetQuery<OtherTestKeyEntity>();

            query4actual = query4actual.Where(_ => _.Item.PersonName == "PersonName");

            var query4 = await i.Query(query4actual);
            Assert.IsNotNull(query4);
            Assert.IsTrue(query4.Count > 0);
        }
示例#3
0
        public async Task CreateTestDocument()
        {
            var i = Resolve<IDocumentRepo<TestKeyEntity>>();

            var t = new TestKeyEntity();
            t.Id = "JordanKey2";
            t.SubKey = new TestKeyEntity
            {
                PersonName = "Knight"
            };

            t.PersonName = "Jordan3";

            var result = await i.AddOrUpdate(t);

            Assert.IsTrue(result);

            var result1 = await i.Get("JordanKey2");

            Assert.IsTrue(result1);

            var results = await i.GetList(_=>_.SubKey.PersonName == "Knight");

            Assert.IsTrue(results);

            Assert.IsTrue(results.Object.Count > 0);



            //var db = Resolve<IDocumentConnection>();

            ////var db = d.CreateDatabaseQuery()
            ////            .Where(d2 => d2.Id == "TestDatabase")
            ////            .AsEnumerable()
            ////            .FirstOrDefault();

            ////var cb = Resolve<Database>();
            //////var cbb = Resolve<DocumentCollection>();

            //var c = Resolve<IDocumentEntityCache>();

            //var doc = new TestKeyEntity();

            //doc.PersonName = "Jordan Kniht";

            //doc.SubKey = new TestKeyEntity
            //{
            //    Key = "Subkey item"
            //};

            //var result = await c.SetEntity("SOme key!", doc);

            //Assert.IsTrue(result);

            //var getRes = await c.GetEntity<TestKeyEntity>("SOme key!");
            //Assert.IsNotNull(getRes);
            //var collection = await db.GetCollection();

            //var q = db.Client.CreateDocumentQuery<TestKeyEntity>(collection.DocumentsLink)
            //    .Where(d => d.SubKey.Key == "Subkey item").ToList();


            //var i = q.FirstOrDefault();

            //Assert.IsNotNull(i);



        }