Beispiel #1
0
        public void TestActionOnAlreadyRegisteredObject()
        {
            var uow = new UnitOfWork(null);
              object obj = new object();

              uow.RegisterRemoved(obj);
              Assert.Catch(typeof(Exception),
            delegate()
            {
              uow.RegisterRemoved(obj);
            });

              uow = new UnitOfWork(null);
              uow.RegisterRemoved(obj);
              Assert.Catch(typeof(Exception),
            delegate()
            {
              uow.RegisterSavedOrUpdated(obj);
            });

              uow = new UnitOfWork(null);
              uow.RegisterSavedOrUpdated(obj);
              Assert.Catch(typeof(Exception),
            delegate()
            {
              uow.RegisterRemoved(obj);
            });

              uow = new UnitOfWork(null);
              uow.RegisterSavedOrUpdated(obj);
              Assert.Catch(typeof(Exception),
            delegate()
            {
              uow.RegisterSavedOrUpdated(obj);
            });
        }
Beispiel #2
0
        public void TestDoubleCommit()
        {
            var mockRepository = new Mock<IRepository>();

              int savedCount = 0;
              mockRepository.Setup(r => r.Persist(It.IsAny<IList<object>>(), It.IsAny<IList<object>>()))
            .Callback(delegate(IList<object> saved, IList<object> removed)
            {
              savedCount = saved.Count;
            });

              var uow = new UnitOfWork(mockRepository.Object);

              uow.RegisterSavedOrUpdated(new object());
              uow.Commit();

              Assert.AreEqual(1, savedCount);

              uow.Commit();
              Assert.AreEqual(0, savedCount);
        }
Beispiel #3
0
        public void TestRetryCommit()
        {
            var mockRepository = new Mock<IRepository>();

              bool firstCallToCommit = true;
              int savedCount = 0;

              mockRepository.Setup(r => r.Persist(It.IsAny<IList<object>>(), It.IsAny<IList<object>>()))
            .Callback(delegate(IList<object> saved, IList<object> removed)
            {
              if (firstCallToCommit)
            throw new Exception("First call throws exception for testing purposes");
              else
            savedCount = saved.Count;
            });

              var uow = new UnitOfWork(mockRepository.Object);

              uow.RegisterSavedOrUpdated(new object());

              Assert.Catch(typeof(Exception),
            delegate()
            {
              uow.Commit();
            });

              firstCallToCommit = false;
              uow.Commit();
              Assert.AreEqual(1, savedCount);
        }
Beispiel #4
0
        public void TestSimpleCommit()
        {
            var mockRepository = new Mock<IRepository>();

              int savedCount = 0;
              int removedCount = 0;
              mockRepository.Setup(r => r.Persist(It.IsAny<IList<object>>(), It.IsAny<IList<object>>()))
            .Callback(delegate(IList<object> saved, IList<object> removed)
                  {
                    savedCount = saved.Count;
                    removedCount = removed.Count;
                  });

              var uow = new UnitOfWork(mockRepository.Object);

              uow.RegisterSavedOrUpdated(new object());
              uow.RegisterRemoved(new object());
              uow.Commit();

              Assert.AreEqual(1, savedCount);
              Assert.AreEqual(1, removedCount);

              //mockRepository.Verify(r => r.Persist(It.Is<IDictionary<string, object>>(arg => arg.Count == 1), It.Is<IDictionary<string, object>>(arg => arg.Count == 1)), Times.Exactly(1));
              //mockRepository.Verify(r => r.Persist(It.IsAny<IDictionary<string, object>>(), It.IsAny<IDictionary<string, object>>()), Times.Once());
        }
Beispiel #5
0
        public void TestRollback()
        {
            var mockRepository = new Mock<IRepository>();

              var uow = new UnitOfWork(mockRepository.Object);

              uow.RegisterSavedOrUpdated(new object());
              uow.RegisterRemoved(new object());
              uow.Rollback();

              mockRepository.Verify(r => r.Persist(It.IsAny<IList<object>>(), It.IsAny<IList<object>>()), Times.Never());
        }