Пример #1
0
        public void Flush_calls_SubmitChanges_on_all_open_IEFSession_instances()
        {
            var resolver = MockRepository.GenerateMock<IEFSessionResolver>();
            resolver.Stub(x => x.GetSessionKeyFor<string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor<int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor<string>()).Return(MockRepository.GenerateStub<IEFSession>());
            resolver.Stub(x => x.OpenSessionFor<int>()).Return(MockRepository.GenerateStub<IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);
            unitOfWork.GetSession<string>();
            unitOfWork.GetSession<int>();

            unitOfWork.Flush();
            resolver.OpenSessionFor<string>().AssertWasCalled(x => x.SaveChanges());
            resolver.OpenSessionFor<int>().AssertWasCalled(x => x.SaveChanges());
        }
Пример #2
0
        public void Dispose_disposes_all_open_IEFSession_instances()
        {
            var resolver = MockRepository.GenerateMock<IEFSessionResolver>();
            resolver.Stub(x => x.GetSessionKeyFor<string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor<int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor<string>()).Return(MockRepository.GenerateStub<IEFSession>());
            resolver.Stub(x => x.OpenSessionFor<int>()).Return(MockRepository.GenerateStub<IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);
            unitOfWork.GetSession<string>();
            unitOfWork.GetSession<int>();

            unitOfWork.Dispose();
            resolver.OpenSessionFor<string>().AssertWasCalled(x => x.Dispose());
            resolver.OpenSessionFor<int>().AssertWasCalled(x => x.Dispose());
        }
Пример #3
0
        public void GetSessionFor_returns_different_session_for_types_handled_by_different_context()
        {
            var resolver = new Mock<IEFSessionResolver>();
            resolver.Setup(x => x.GetSessionKeyFor<string>()).Returns(Guid.NewGuid());
            resolver.Setup(x => x.GetSessionKeyFor<int>()).Returns(Guid.NewGuid());
            resolver.Setup(x => x.OpenSessionFor<string>()).Returns(new Mock<IEFSession>().Object);
            resolver.Setup(x => x.OpenSessionFor<int>()).Returns(new Mock<IEFSession>().Object);

            var unitOfWork = new EFUnitOfWork(resolver.Object);
            var stringSession = unitOfWork.GetSession<string>();
            var intSession = unitOfWork.GetSession<int>();

            Assert.AreNotSame(stringSession, intSession);
            resolver.Verify(x => x.GetSessionKeyFor<string>());
            resolver.Verify(x => x.GetSessionKeyFor<int>());
            resolver.Verify(x => x.OpenSessionFor<string>());
            resolver.Verify(x => x.OpenSessionFor<int>());
        }
Пример #4
0
        public void Dispose_disposes_all_open_IEFSession_instances()
        {
            var resolver = new Mock<IEFSessionResolver>();
            resolver.Setup(x => x.GetSessionKeyFor<string>()).Returns(Guid.NewGuid());
            resolver.Setup(x => x.GetSessionKeyFor<int>()).Returns(Guid.NewGuid());
            var session = new Mock<IEFSession>();
            resolver.Setup(x => x.OpenSessionFor<string>()).Returns(session.Object);
            resolver.Setup(x => x.OpenSessionFor<int>()).Returns(session.Object);

            var unitOfWork = new EFUnitOfWork(resolver.Object);
            unitOfWork.GetSession<string>();
            unitOfWork.GetSession<int>();

            unitOfWork.Dispose();
            resolver.Object.OpenSessionFor<string>();
            session.Verify(x => x.Dispose());
            session.Verify(x => x.Dispose());
        }
Пример #5
0
        public void Flush_calls_SubmitChanges_on_all_open_IEFSession_instances()
        {
            var resolver = MockRepository.GenerateMock <IEFSessionResolver>();

            resolver.Stub(x => x.GetSessionKeyFor <string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor <int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor <string>()).Return(MockRepository.GenerateStub <IEFSession>());
            resolver.Stub(x => x.OpenSessionFor <int>()).Return(MockRepository.GenerateStub <IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);

            unitOfWork.GetSession <string>();
            unitOfWork.GetSession <int>();

            unitOfWork.Flush();
            resolver.OpenSessionFor <string>().AssertWasCalled(x => x.SaveChanges());
            resolver.OpenSessionFor <int>().AssertWasCalled(x => x.SaveChanges());
        }
Пример #6
0
        public void Dispose_disposes_all_open_IEFSession_instances()
        {
            var resolver = MockRepository.GenerateMock <IEFSessionResolver>();

            resolver.Stub(x => x.GetSessionKeyFor <string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor <int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor <string>()).Return(MockRepository.GenerateStub <IEFSession>());
            resolver.Stub(x => x.OpenSessionFor <int>()).Return(MockRepository.GenerateStub <IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);

            unitOfWork.GetSession <string>();
            unitOfWork.GetSession <int>();

            unitOfWork.Dispose();
            resolver.OpenSessionFor <string>().AssertWasCalled(x => x.Dispose());
            resolver.OpenSessionFor <int>().AssertWasCalled(x => x.Dispose());
        }
Пример #7
0
        public void GetSessionFor_returns_different_session_for_types_handled_by_different_context()
        {
            var resolver = MockRepository.GenerateMock<IEFSessionResolver>();
            resolver.Stub(x => x.GetSessionKeyFor<string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor<int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor<string>()).Return(MockRepository.GenerateStub<IEFSession>());
            resolver.Stub(x => x.OpenSessionFor<int>()).Return(MockRepository.GenerateStub<IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);
            var stringSession = unitOfWork.GetSession<string>();
            var intSession = unitOfWork.GetSession<int>();

            Assert.That(stringSession, Is.Not.SameAs(intSession));
            resolver.AssertWasCalled(x => x.GetSessionKeyFor<string>());
            resolver.AssertWasCalled(x => x.GetSessionKeyFor<int>());
            resolver.AssertWasCalled(x => x.OpenSessionFor<string>());
            resolver.AssertWasCalled(x => x.OpenSessionFor<int>());
        }
Пример #8
0
        public void Flush_calls_SubmitChanges_on_all_open_IEFSession_instances()
        {
            var resolver = new Mock<IEFSessionResolver>();
            resolver.Setup(x => x.GetSessionKeyFor<string>()).Returns(Guid.NewGuid());
            resolver.Setup(x => x.GetSessionKeyFor<int>()).Returns(Guid.NewGuid());
            var session = new Mock<IEFSession>();
            resolver.Setup(x => x.OpenSessionFor<string>()).Returns(session.Object);
            resolver.Setup(x => x.OpenSessionFor<int>()).Returns(session.Object);

            var unitOfWork = new EFUnitOfWork(resolver.Object);
            unitOfWork.GetSession<string>();
            unitOfWork.GetSession<int>();

            unitOfWork.Flush();
            resolver.Object.OpenSessionFor<string>();
            session.Verify(x => x.SaveChanges());
            resolver.Object.OpenSessionFor<int>();
            session.Verify(x => x.SaveChanges());
        }
Пример #9
0
        public void GetSessionFor_returns_different_session_for_types_handled_by_different_context()
        {
            var resolver = MockRepository.GenerateMock <IEFSessionResolver>();

            resolver.Stub(x => x.GetSessionKeyFor <string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.GetSessionKeyFor <int>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor <string>()).Return(MockRepository.GenerateStub <IEFSession>());
            resolver.Stub(x => x.OpenSessionFor <int>()).Return(MockRepository.GenerateStub <IEFSession>());

            var unitOfWork    = new EFUnitOfWork(resolver);
            var stringSession = unitOfWork.GetSession <string>();
            var intSession    = unitOfWork.GetSession <int>();

            Assert.That(stringSession, Is.Not.SameAs(intSession));
            resolver.AssertWasCalled(x => x.GetSessionKeyFor <string>());
            resolver.AssertWasCalled(x => x.GetSessionKeyFor <int>());
            resolver.AssertWasCalled(x => x.OpenSessionFor <string>());
            resolver.AssertWasCalled(x => x.OpenSessionFor <int>());
        }
Пример #10
0
        public void GetSessionFor_returns_session_for_type()
        {
            var resolver = MockRepository.GenerateStub <IEFSessionResolver>();

            resolver.Stub(x => x.GetSessionKeyFor <string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor <string>()).Return(MockRepository.GenerateStub <IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);
            var session    = unitOfWork.GetSession <string>();

            Assert.That(session, Is.Not.Null);
        }
Пример #11
0
        public void GetSessionFor_returns_session_for_type()
        {
            var resolver = new Mock<IEFSessionResolver>();
            resolver.Setup(x => x.GetSessionKeyFor<string>()).Returns(Guid.NewGuid());
            resolver.Setup(x => x.OpenSessionFor<string>()).Returns(new Mock<IEFSession>().Object);

            var unitOfWork = new EFUnitOfWork(resolver.Object);
            var session = unitOfWork.GetSession<string>();
            Assert.IsNotNull(session);
        }
Пример #12
0
        public void GetSessionFor_returns_session_for_type()
        {
            var resolver = MockRepository.GenerateStub<IEFSessionResolver>();
            resolver.Stub(x => x.GetSessionKeyFor<string>()).Return(Guid.NewGuid());
            resolver.Stub(x => x.OpenSessionFor<string>()).Return(MockRepository.GenerateStub<IEFSession>());

            var unitOfWork = new EFUnitOfWork(resolver);
            var session = unitOfWork.GetSession<string>();
            Assert.That(session, Is.Not.Null);
        }