public void FindAll_Filter_EntitiesFiltered()
        {
            var unitOfWork = new MemoryUnitOfWork();
            var target = new ParseRepository<StubEntity>(unitOfWork);

            foreach (var toRemove in target.FindAll())
            {
                target.Remove(toRemove);
                unitOfWork.Commit();
            }

            var entity1 = new StubEntity();
            entity1.Date = DateTime.Now;
            entity1.Text1 = "text1";
            entity1.Text2 = "text2";
            entity1.Text3 = "text3";

            var entity2 = new StubEntity();
            entity2.Date = DateTime.Now;
            entity2.Text1 = "text1";
            entity2.Text2 = "text2";
            entity2.Text3 = "text4";

            target.Add(entity1);
            target.Add(entity2);
            unitOfWork.Commit();

            var text1 = "text1";
            var actual = target.FindAll(0, 1, (b) => b.Text1 == text1 && b.Text2 == "text2" && b.Text3 == "text3");

            Assert.AreEqual(1, actual.Count());
            var first = actual.First();
            Assert.AreEqual("text3", first.Text3);

            actual = target.FindAll(0, 1, (b) => b.Text1 == text1 && b.Text2 == "text2" && b.Text3 == "text4");

            Assert.AreEqual(1, actual.Count());
            first = actual.First();
            Assert.AreEqual("text4", first.Text3);

            first = target.FindFirst((b) => b.Text1 == text1 && b.Text2 == "text2" && b.Text3 == "text3");
            Assert.AreEqual("text3", first.Text3);
        }
        public void GetEntities_Args_Filtered()
        {
            var unitOfWork = new MemoryUnitOfWork();
            var repository = new MemoryDomainServiceBaseStubRepository(unitOfWork);
            repository.Add(new DomainEntityBaseStub());
            repository.Add(new DomainEntityBaseStub());
            unitOfWork.Commit();

            var target = new DomainServiceBaseStub(repository, unitOfWork);
            var actual = target.GetEntitiesStub();
            Assert.AreEqual(2, actual.TotalCount);
        }
        public void Count_NoArgs_CountAllEntities()
        {
            var unitOfWork = new MemoryUnitOfWork();
            var repository = new MemoryDomainServiceBaseStubRepository(unitOfWork);
            repository.Add(new DomainEntityBaseStub());
            repository.Add(new DomainEntityBaseStub());
            unitOfWork.Commit();

            var target = new DomainServiceBaseStub(repository, unitOfWork);
            var actual = target.Count();
            Assert.AreEqual(2, actual);
        }
		public void RegisterRemoved_Commit_Deleted ()
		{
			var target = new MemoryUnitOfWork ();
			var user1 = new User ("1");
			var repository = MockRepository.GenerateStrictMock<IUnitOfWorkRepository> ();
			repository.Expect (r => r.PersistDeletedItem(user1));

			target.RegisterRemoved (user1, repository);

			target.Commit ();

			repository.VerifyAllExpectations ();
		}
        public void InitializeTest()
        {
            m_unitOfWork = new MemoryUnitOfWork();
            m_repository = new MemoryPermissionRepository(m_unitOfWork);

            for (int i = 1; i <= 5; i++)
            {
                m_repository.Add(new Permission() { ActionName = "Action " + i, ControllerName = "Controller" });
            }

            m_unitOfWork.Commit();

            m_target = new PermissionService(m_repository, m_unitOfWork);
        }
        public void PersistNewItem_Entity_Persisted()
        {
            var entity = new StubEntity();
            entity.Date = DateTime.Now;
            entity.Integer = 2;
            entity.Text1 = "text1";
            entity.Text2 = "text2";
            entity.Text3 = "text3";

            var unitOfWork = new MemoryUnitOfWork();
            var target = new ParseRepository<StubEntity>(unitOfWork);

            target.Add(entity);
            unitOfWork.Commit();
        }
		public void Commit_EntitiesToAddChangeAndDelete_RightCommit ()
		{
			var target = new MemoryUnitOfWork ();

			var userToDelete = new User ("1");
			var userToAdd = new User ("2");
			var userToUpdate = new User ("3");

			var repository = MockRepository.GenerateStrictMock<IUnitOfWorkRepository> ();
			repository.Expect (r => r.PersistDeletedItem(userToDelete));
			repository.Expect (r => r.PersistNewItem(userToAdd));
			repository.Expect (r => r.PersistUpdatedItem(userToUpdate));

			target.RegisterRemoved (userToDelete, repository);
			target.RegisterAdded (userToAdd, repository);
			target.RegisterChanged (userToUpdate, repository);

			target.Commit ();

			repository.VerifyAllExpectations ();
		}
        public void Rollback_EntitiesToAddChangeAndDelete_Undo()
        {
            var target = new MemoryUnitOfWork();

            var userToDelete = new User("1");
            var userToAdd = new User("2");
            var userToUpdate = new User("3");

            var repository = MockRepository.GenerateStrictMock<IUnitOfWorkRepository>();

            target.RegisterRemoved(userToDelete, repository);
            target.RegisterAdded(userToAdd, repository);
            target.RegisterChanged(userToUpdate, repository);

            target.Rollback();
            target.Commit();            

            repository.VerifyAllExpectations();
        }