Exemplo n.º 1
0
        public void LocalizedWritingQueringWithInnerScope4()
        {
            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 ResourceTransactionScope(TransactionScopeOption.RequiresNew))
            {
                _pool.Post(id, el);
                using (var scope2 = new ResourceTransactionScope(TransactionScopeOption.Suppress))
                {
                    el2 = _pool.Find <NotifiedElement>(query);
                    scope2.Complete();
                }
                Assert.IsFalse(el2.Any());
                scope.Complete();
            }

            _posterFactory.AssertWasCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments()
                                           .Repeat.Once());
        }
Exemplo n.º 2
0
        public void LocalizedWritingWithInnerScope()
        {
            var id = Guid.NewGuid();
            var el = new NotifiedElement {
                Name = "Test"
            };
            var id2 = Guid.NewGuid();
            var el2 = new NotifiedElement {
                Name = "Test2"
            };
            IEnumerable <DataRecord> records = null;

            _posterFactory.Stub(k => k.PostResourceBlock(null))
            .IgnoreArguments()
            .Do(new Func <IEnumerable <DataRecord>, IEnumerable <DataRecord> >(k =>
            {
                records = k;
                return(k);
            }));
            _mockRepository.ReplayAll();

            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                _pool.Post(id, el);
                using (var scope2 = new TransactionScope(TransactionScopeOption.Required))
                {
                    _pool.Post(id2, el2);
                    _posterFactory.AssertWasNotCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments()
                                                      .Repeat.Once());
                    scope2.Complete();
                }
                scope.Complete();
            }
            CollectionAssert.AreEquivalent(records.Select(k => k.Content.ResourceKey).ToList(), new[] { id, id2 }.ToList());
        }
Exemplo n.º 3
0
        public void LocalizedWritingGettingWithInnerScope2()
        {
            var id = Guid.NewGuid();
            var el = new NotifiedElement {
                Name = "Test"
            };

            _posterFactory.Stub(k => k.PostResourceBlock(null))
            .IgnoreArguments()
            .Return(new DataRecord[0]);
            _mockRepository.ReplayAll();
            var el2 = _pool.Get <NotifiedElement>(id);

            Assert.IsNull(el2);
            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                using (var scope2 = new TransactionScope(TransactionScopeOption.Required))
                {
                    _pool.Post(id, el);
                    scope2.Complete();
                }
                el2 = _pool.Get <NotifiedElement>(id);
                _getter.AssertWasNotCalled(k => k.GetItemTypedProxy(id),
                                           k => k.IgnoreArguments());
                Assert.IsNotNull(el2);
                Assert.AreEqual(el.Name, el2.Name);
                scope.Complete();
            }

            _posterFactory.AssertWasCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments()
                                           .Repeat.Once());
        }
Exemplo n.º 4
0
 public void LocalizedWritingWithInnerScopeWriting()
 {
     _posterFactory.Stub(k => k.PostResourceBlock(null))
     .IgnoreArguments()
     .Return(new DataRecord[0]);
     using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
     {
         var id = Guid.NewGuid();
         var el = new NotifiedElement();
         _mockRepository.ReplayAll();
         using (var innerScope = new TransactionScope(TransactionScopeOption.Required))
         {
             _pool.Post(id, el);
             innerScope.Complete();
         }
         _posterFactory.AssertWasNotCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments());
         scope.Complete();
     }
     _posterFactory.AssertWasCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments());
 }
Exemplo n.º 5
0
        public void WritingMultipleObjects()
        {
            var id = Guid.NewGuid();
            var el = new NotifiedElement {
                Name = "1"
            };
            var id2 = Guid.NewGuid();
            var el2 = new NotifiedElement {
                Name = "2"
            };

            _mockRepository.ReplayAll();
            object[] args = null;
            using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                _pool.Post(id, el);
                _pool.Post(id2, el2);
                _posterFactory.AssertWasNotCalled(k => k.PostResourceBlock(null), k => k.IgnoreArguments());
                _poster.AssertWasNotCalled(k => k.WriteResourceRegardlessofTransaction(id, el),
                                           k => k.IgnoreArguments());
                _poster.BackToRecord();
                _posterFactory.Stub(k => k.PostResourceBlock(null)).IgnoreArguments()
                .WhenCalled(k => { args = k.Arguments; })
                .Return(new DataRecord[0]);
                scope.Complete();
            }

            _posterFactory.AssertWasCalled(k => k.PostResourceBlock(null), k2 => k2.IgnoreArguments()
                                           .Repeat.Once());
            var resPosted = (args[0] as IEnumerable <DataRecord>).ToArray();

            Assert.AreEqual(id, resPosted[0].Content.ResourceKey);
            Assert.AreNotSame(el, resPosted[0].Resource);
            Assert.AreEqual(el.Name, (resPosted[0].Resource as NotifiedElement).Name);
            Assert.AreEqual(id2, resPosted[1].Content.ResourceKey);
            Assert.AreNotSame(el2, resPosted[1].Resource);
            Assert.AreEqual(el2.Name, (resPosted[1].Resource as NotifiedElement).Name);
        }