public void CommitSingleRepositoryTest()
        {
            var mockRepo = new Mock <IUnitOfWorkRepository>();

            var domainUser = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            var uow = new InMemoryUnitOfWork();

            uow.RegisterInsertion(domainUser, mockRepo.Object);

            domainUser.Name = "test";

            uow.RegisterUpdate(domainUser, mockRepo.Object);

            uow.RegisterDeletion(domainUser, mockRepo.Object);

            uow.Commit();

            mockRepo.Verify(w => w.PersistInsertion(domainUser), Times.Once);
            mockRepo.Verify(w => w.PersistUpdate(domainUser), Times.Once);
            mockRepo.Verify(w => w.PersistDeletion(domainUser), Times.Once);
        }
Esempio n. 2
0
        public void EqualsTest()
        {
            var user1 = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            var user2 = user1;

            Assert.IsTrue(user1.Equals(user2));

            var user3 = new FakeDomainUser {
                Id   = user1.Id,
                Name = user1.Name + "aaa"
            };

            Assert.IsTrue(user1.Equals(user3));

            var user4 = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = user1.Name
            };

            Assert.IsFalse(user1.Equals(user4));
        }
Esempio n. 3
0
        public void GetHashCodeTest()
        {
            var user = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            Assert.AreEqual(user.Id.GetHashCode(), user.GetHashCode());
        }
        public void CommitEmptyTest()
        {
            var mockRepo = new Mock <IUnitOfWorkRepository>();

            var domainUser = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            var uow = new InMemoryUnitOfWork();

            uow.Commit();

            mockRepo.Verify(w => w.PersistInsertion(domainUser), Times.Never);
            mockRepo.Verify(w => w.PersistUpdate(domainUser), Times.Never);
            mockRepo.Verify(w => w.PersistDeletion(domainUser), Times.Never);
        }
        public void PersistUpdateTest()
        {
            var mockContext = new Mock <IDataContext>();

            mockContext.Setup(x => x.UpdateEntity(It.IsAny <FakeDatabaseUser>()));

            var mockContextFactory = new Mock <IDataContextFactory <IDataContext> >();

            mockContextFactory.Setup(x => x.Create()).Returns(mockContext.Object);

            var mockUow = new Mock <IUnitOfWork>();

            var repo = new FakeRepository(mockUow.Object, mockContextFactory.Object);

            var domainUser = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            repo.PersistUpdate(domainUser);

            mockContext.Verify(w => w.UpdateEntity(It.IsAny <FakeDatabaseUser>()), Times.Once);
        }
        public void DeleteTest()
        {
            var mockContext = new Mock <IDataContext>();

            var mockContextFactory = new Mock <IDataContextFactory <IDataContext> >();

            mockContextFactory.Setup(x => x.Create()).Returns(mockContext.Object);

            var mockUow = new Mock <IUnitOfWork>();

            var repo = new FakeRepository(mockUow.Object, mockContextFactory.Object);

            var domainUser = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            mockUow.Setup(x => x.RegisterDeletion(domainUser, repo));

            repo.Delete(domainUser);

            mockUow.Verify(w => w.RegisterDeletion(domainUser, repo), Times.Once);
        }
        public void CommitMultipleRepositoriesTest()
        {
            var mockRepo1 = new Mock <IUnitOfWorkRepository>();

            var domainUser1 = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test"
            };

            var mockRepo2 = new Mock <IUnitOfWorkRepository>();

            var domainUser2 = new FakeDomainUser {
                Id   = Guid.NewGuid(),
                Name = "test2"
            };

            var uow = new InMemoryUnitOfWork();

            uow.RegisterInsertion(domainUser1, mockRepo1.Object);
            uow.RegisterInsertion(domainUser2, mockRepo2.Object);

            domainUser2.Name = "test22";

            uow.RegisterUpdate(domainUser2, mockRepo2.Object);

            uow.RegisterDeletion(domainUser1, mockRepo1.Object);

            uow.Commit();

            mockRepo1.Verify(w => w.PersistInsertion(domainUser1), Times.Once);
            mockRepo1.Verify(w => w.PersistUpdate(domainUser1), Times.Never);
            mockRepo1.Verify(w => w.PersistDeletion(domainUser1), Times.Once);

            mockRepo2.Verify(w => w.PersistInsertion(domainUser2), Times.Once);
            mockRepo2.Verify(w => w.PersistUpdate(domainUser2), Times.Once);
            mockRepo2.Verify(w => w.PersistDeletion(domainUser2), Times.Never);
        }