Exemplo n.º 1
0
        public void X_DifferentInput_ReturnFullName()
        {
            //Arrange
            _moq.Setup(t => t.JoinUpper(It.IsAny <string>(), It.IsAny <string>()))
            .Returns("A B");

            _moq.Setup(t => t.Meaning)
            .Returns(42);

            //Act
            var thingTested = new ThingBeingTested(_moq.Object);
            var result      = thingTested.X();

            //Assert
            Assert.Equal("A B = 42", result);
        }
Exemplo n.º 2
0
        public void TestUsingMockDependencyUsingInteractionVerification()
        {
            var mockDependency = new Mock <IThingDependency>();

            // create thing being tested with a mock dependency
            var sut = new ThingBeingTested(mockDependency.Object)
            {
                FirstName = "Sarah",
                LastName  = "Smith"
            };

            var test = sut.X();

            // Assert that the JoinUpper method was called with Sarah Smith
            mockDependency.Verify(x => x.JoinUpper("Sarah", "Smith"), Times.Once);

            // Assert that the Meaning property was accessed once
            mockDependency.Verify(x => x.Meaning, Times.Once);
        }
Exemplo n.º 3
0
        public void TestUsingMockDependency()
        {
            var mockDependency = new Mock <IThingDependency>();

            // set up mock version's method
            mockDependency.Setup(x => x.JoinUpper(It.IsAny <string>(), It.IsAny <string>()))
            .Returns("A B");
            // .Verifiable();

            // set up mock version's property
            mockDependency.Setup(x => x.Meaning)
            .Returns(42);

            // create thing being tested with a mock dependency
            var sut = new ThingBeingTested(mockDependency.Object);

            var result = sut.X();

            // mockDependency.Verify();
            Assert.Equal("A B = 42", result);
        }