示例#1
0
        public void LocalizedWritingQuering()
        {
            var id = Guid.NewGuid();
            var el = new NotifiedElement {
                Key = id, Name = "Test"
            };

            _posterFactory.Stub(k => k.PostResourceBlock(null))
            .IgnoreArguments()
            .Return(new DataRecord[0]);
            _mockRepository.ReplayAll();
            object query = _pool.Spec(name: "Test");
            var    el2   = _pool.Find <NotifiedElement>(query);

            Assert.IsFalse(el2.Any());
            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                _pool.Post(id, el);
                el2 = _pool.Find <NotifiedElement>(query);

                Assert.IsTrue(el2.Any());
                Assert.AreEqual(el.Key, el2.First());
                scope.Complete();
            }

            _posterFactory.AssertWasCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments()
                                           .Repeat.Once());
        }
示例#2
0
        public void MultipleWithoutParameterAndWithoutGrouping()
        {
            object query = _pool.Spec(model: new[] { _model1.Key, _model2.Key });
            var    res   = _pool.Find <Element>(query).ToArray();

            CollectionAssert.AreEquivalent(res, new[] { _e1.Key, _e2.Key, _e3.Key });
            Assert.IsTrue(ElementQuery.WasCalledMultiple);
        }
示例#3
0
        public void GetResourceTestByArgsHelper <T>() where T : class
        {
            ITypedPool target = CreateITransientCachier();

            if (typeof(T) == typeof(Model))
            {
                var    expectedModel = _dependentModel.Key;
                object q             = target.Spec(Element: _dependentElement.Name);
                var    t             = target.Find <Model>(q);
                var    actualModel   = t.First();
                Assert.AreNotSame(expectedModel, actualModel);
                Assert.AreEqual(expectedModel, actualModel);
                q = target.Spec(Element: _singleElement.Name);
                var nolModels = target.Find <Model>(q);
                Assert.IsTrue(!nolModels.Any());

                try
                {
                    q = target.Spec(Default: true);
                    var res = target.Find <Model>(q);
                    Assert.IsTrue(res.Count() == 1);
                }
                catch (InvalidOperationException)
                {
                }
            }

            if (typeof(T) == typeof(Element))
            {
                var    expectedElement = _dependentElement.Key;
                object query           = target.Spec(modelName: _dependentModel.Name);
                var    actualElement   = target.Find <Element>(query).First();
                Assert.AreNotSame(expectedElement, actualElement);
                Assert.AreEqual(expectedElement, actualElement);
                dynamic dquery = target.Spec(ModelName: _dependentModel.Name);
                dquery.ModelId = _singleModel.Key;
                var actualElements = target.Find <Element>(query).ToArray();
                Assert.AreEqual(1, actualElements.Count());
                Assert.AreEqual(expectedElement, actualElements[0]);
                query = target.Spec(modelName: _singleModel.Name);
                var nolElements = target.Find <Element>(query);
                Assert.IsTrue(!nolElements.Any());
                query = target.Spec(badquery: true);
                var emptyKey = target.Find <Element>(query);
                Assert.AreEqual(Guid.Empty, emptyKey.First());
            }
        }