Beispiel #1
0
        public void UsingTraditionalSetups_ShouldCorrectlySetupMocks()
        {
            //arrange

            //act
            _testSuit
            .SetupMockAdv <IDependency1>(d => d.Setup(m => m.GetNumber()).Returns("one"))
            .SetupMockAdv <IDependency2>(d => d.Setup(m => m.Action2()).Returns("two"));

            //assert
            _testSuit.Sut.Dependency1.GetNumber().Should().Be("one");
            _testSuit.Sut.Dependency2.Action2().Should().Be("two");
        }
Beispiel #2
0
        public void Always_ShouldParseTheNumber()
        {
            // Arrange

            // Setup your dependencies here as you do in Mock.Of<>()
            // If you call something in the test which was not setup you will get exception
            // "invocation failed with mock behavior Strict".
            _testSuit.SetupMock <IDependency1>(s => s.GetNumber() == "1" && s.SomethingElse == 2);

            // You can also use the traditional Moq form to setup advanced behaviour and void methods
            _testSuit.SetupMockAdv <IDependency2>(m =>
                                                  m.Setup(d => d.Action2()).Callback(() => Console.WriteLine("Test")));

            // Act

            // Sut (system under test) is created lazily on first usage,
            // all constructor dependencies are automatically injected using mocks
            var result = _testSuit.Sut.ParseNumberFromDependency();

            // Assert
            Assert.AreEqual(1, result);
        }