Ejemplo n.º 1
0
        public void SetUp()
        {
            _mockFactory = new MockFactory();
            _mock        = _mockFactory.CreateMock <IMockedType>("mock");

            _expectation1 = new MockExpectation();
            _expectation2 = new MockExpectation();
        }
Ejemplo n.º 2
0
        public void AssertionExceptionThrownWhenNoExpectationsMatchContainsDescriptionOfActiveExpectations()
        {
            var mockObjectControl = (IMockObject)_mock.MockObject;

            var expectation3 = new MockExpectation();

            _expectation1.Description    = "expectation1";
            _expectation1.IsActive       = true;
            _expectation1.Matches_Result = false;

            _expectation2.Description    = "expectation2";
            _expectation2.IsActive       = false;
            _expectation2.Matches_Result = false;

            expectation3.Description    = "expectation3";
            expectation3.IsActive       = true;
            expectation3.Matches_Result = false;

            mockObjectControl.AddExpectation(_expectation1);
            mockObjectControl.AddExpectation(_expectation2);
            mockObjectControl.AddExpectation(expectation3);

            try
            {
                _mock.MockObject.DoStuff();
            }
            catch (UnexpectedInvocationException e)
            {
                string newLine = Environment.NewLine;

                Assert.AreEqual(
                    newLine + "Unexpected invocation of:\r\n  System.Void mock.DoStuff()" + newLine +
                    "MockFactory Expectations:" + newLine +
                    "  expectation1" + newLine +
                    "  expectation2" + newLine +
                    "  expectation3" + newLine,
                    e.Message);
            }
        }
Ejemplo n.º 3
0
        public void AssertionExceptionThrownWhenSomeExpectationsHaveNotBeenMetContainsDescriptionOfUnMetExpectations()
        {
            IMockObject mockObjectControl = (IMockObject)_mock.MockObject;

            MockExpectation expectation3 = new MockExpectation();

            _expectation1.Description = "expectation1";
            _expectation1.HasBeenMet  = false;
            _expectation1.IsActive    = true;
            _expectation2.Description = "expectation2";
            _expectation2.HasBeenMet  = true;
            _expectation2.IsActive    = true;
            expectation3.Description  = "expectation3";
            expectation3.HasBeenMet   = false;
            expectation3.IsActive     = true;

            mockObjectControl.AddExpectation(_expectation1);
            mockObjectControl.AddExpectation(_expectation2);
            mockObjectControl.AddExpectation(expectation3);

            try
            {
                _mockFactory.VerifyAllExpectationsHaveBeenMet();
            }
            catch (UnmetExpectationException e)
            {
                string newLine = Environment.NewLine;

                Assert.AreEqual(
                    "Not all expected invocations were performed." + newLine +
                    "MockFactory Expectations:" + newLine +
                    "  expectation1" + newLine +
                    "  expectation3" + newLine,
                    e.Message);
            }
        }