Example #1
0
        /// <summary>
        ///A test for Get
        ///</summary>
        public void GetResourceTestByQueryHelper <T>()
            where T : class
        {
            ITypedPool target = CreateITransientCachier();

            if (typeof(T) == typeof(Model))
            {
                var expectedModel = _dependentModel.Key;
                var actualModel   = target.Query <Model>(new UriQuery {
                    { "Element", _dependentElement.Name }
                }).First();
                Assert.AreNotSame(expectedModel, actualModel);
                Assert.AreEqual(expectedModel, actualModel);


                var nolModels = target.Query <Model>(new UriQuery {
                    { "Element", _singleElement.Name }
                });
                Assert.IsTrue(!nolModels.Any());

                try
                {
                    var res = target.Query <Model>(new UriQuery("default=true"));
                    Assert.IsTrue(res.Count() == 1);
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (typeof(T) == typeof(Element))
            {
                var expectedElement = _dependentElement.Key;
                var actualElement   = target.Query <Element>(new UriQuery {
                    { "modelName", _dependentModel.Name }
                }).First();
                Assert.AreNotSame(expectedElement, actualElement);
                Assert.AreEqual(expectedElement, actualElement);

                var actualElements = target.Query <Element>(
                    new UriQuery {
                    { "ElementName", _dependentElement.Name },
                    { "Model", _dependentModel.Key.ToString() }
                }).ToArray();
                Assert.AreEqual(1, actualElements.Count());
                Assert.AreEqual(expectedElement, actualElements[0]);

                var nolElements = target.Query <Element>(new UriQuery {
                    { "modelName", _singleModel.Name }
                });
                Assert.IsTrue(!nolElements.Any());

                var emptyKey = target.Query <Element>(new UriQuery("badquery=true"));
                Assert.AreEqual(Guid.Empty, emptyKey.First());
            }
        }
Example #2
0
 public static IEnumerable <T> QueryFilled <T>(this ITypedPool cachier, UriQuery query) where T : class
 {
     return(cachier.Get <T>(cachier.Query <T>(query)));
 }
Example #3
0
 public static T GetOneDependent <T>(this ITypedPool cachier, UriQuery query) where T : class
 {
     return(cachier.Query <T>(query).SingleOrDefault().ByDefault(cachier.Get <T>, null));
 }