Exemplo n.º 1
0
        public void EndWorkingSession_onSubclassException_dontWrapInvalidOperationException()
        {
            // arrange:
            System.Collections.Generic.List <object> mocks = new System.Collections.Generic.List <object>();
            InvalidOperationException thrownException      = new InvalidOperationException("thrownException");

            Fakes.FakeEnterprise enterprise = MockRepository.GeneratePartialMock <Fakes.FakeEnterprise>();
            mocks.Add(enterprise);
            IPrincipal owner = MockRepository.GenerateStrictMock <IPrincipal>();

            mocks.Add(owner);
            WorkingSessionBase session = MockRepository.GeneratePartialMock <WorkingSessionBase>("MockWorkingSession", owner);

            mocks.Add(session);
            enterprise.Expect(e => e.CallBeforeWorkingSessionEnd(owner, session)).Throw(thrownException).Repeat.Once();
            InvalidOperationException cought = null;

            // act:
            try
            {
                enterprise.EndWorkingSession(owner, session);
            }
            catch (InvalidOperationException e)
            {
                cought = e;
            }

            // assert:
            Assert.IsNotNull(cought);
            Assert.AreSame(thrownException, cought);
            foreach (object m in mocks)
            {
                m.VerifyAllExpectations();
            }
        }
Exemplo n.º 2
0
        public void EndWorkingSession_withoutSession_throwsArgumentNullException()
        {
            // arrange:
            IEnterprise enterprise = new Fakes.FakeEnterprise();
            IPrincipal  owner      = new GenericPrincipal(new GenericIdentity("test", "test"), new string[] {});

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { enterprise.EndWorkingSession(owner, null); });
        }
Exemplo n.º 3
0
        public void EndWorkingSession_withoutOwner_throwsArgumentNullException()
        {
            // arrange:
            IEnterprise     enterprise = new Fakes.FakeEnterprise();
            IWorkingSession session    = MockRepository.GenerateStrictMock <IWorkingSession>();

            // assert:
            Assert.Throws <ArgumentNullException>(delegate { enterprise.EndWorkingSession(null, session); });
        }
Exemplo n.º 4
0
        public void EndWorkingSession_withWrongSessionType_throwsInvalidOperationException()
        {
            // arrange:
            IEnterprise     enterprise = new Fakes.FakeEnterprise();
            IPrincipal      owner      = new GenericPrincipal(new GenericIdentity("test", "test"), new string[] {});
            IWorkingSession session    = MockRepository.GenerateStrictMock <IWorkingSession>();

            // assert:
            Assert.Throws <InvalidOperationException>(delegate { enterprise.EndWorkingSession(owner, session); });
        }
Exemplo n.º 5
0
        public void EndWorkingSession_onWorkingSessionException_throwsInvalidOperationException()
        {
            // arrange:
            System.Collections.Generic.List <object> mocks = new System.Collections.Generic.List <object>();
            Exception dummyException = new Exception("dummyException");

            Fakes.FakeEnterprise enterprise = MockRepository.GeneratePartialMock <Fakes.FakeEnterprise>();
            mocks.Add(enterprise);
            IPrincipal owner = MockRepository.GenerateStrictMock <IPrincipal>();

            owner.Expect(p => p.Identity).Return(new GenericIdentity("testPrincipal"));
            mocks.Add(owner);
            FakeWorkingSession session = MockRepository.GeneratePartialMock <FakeWorkingSession>("MockWorkingSession", owner);

            session.Expect(s => s.CallBeforeDispose()).Throw(dummyException).Repeat.Once();
            mocks.Add(session);
            enterprise.Expect(e => e.CallBeforeWorkingSessionEnd(owner, session)).Repeat.Once();
            InvalidOperationException cought = null;

            // act:
            try
            {
                enterprise.EndWorkingSession(owner, session);
            }
            catch (InvalidOperationException e)
            {
                cought = e;
            }

            // assert:
            Assert.IsNotNull(cought);
            Assert.AreSame(dummyException, cought.InnerException);
            foreach (object m in mocks)
            {
                m.VerifyAllExpectations();
            }
        }
Exemplo n.º 6
0
        public void EndWorkingSession_withValidArguments_callTemplateMethod()
        {
            // arrange:
            System.Collections.Generic.List <object> mocks = new System.Collections.Generic.List <object>();
            Fakes.FakeEnterprise enterprise = MockRepository.GeneratePartialMock <Fakes.FakeEnterprise>();
            mocks.Add(enterprise);
            IPrincipal owner = MockRepository.GenerateStrictMock <IPrincipal>();

            mocks.Add(owner);
            FakeWorkingSession session = MockRepository.GeneratePartialMock <FakeWorkingSession>("MockWorkingSession", owner);

            session.Expect(s => s.CallBeforeDispose()).Repeat.Once();
            mocks.Add(session);
            enterprise.Expect(e => e.CallBeforeWorkingSessionEnd(owner, session)).Repeat.Once();

            // act:
            enterprise.EndWorkingSession(owner, session);

            // assert:
            foreach (object m in mocks)
            {
                m.VerifyAllExpectations();
            }
        }