public void CalledWithSomeSimpleSettings_ShouldCleanAndCountCleanedPlaces()
        {
            // Arrange
            var startingPoint = new Point(10, 10);
            var robotSettings = new SessionSettings(startingPoint, new List <Command>
            {
                new Command(CompassDirection.North, 1),
                new Command(CompassDirection.East, 1),
                new Command(CompassDirection.South, 1),
                new Command(CompassDirection.West, 1),
            });
            var expectedSession       = new Session(startingPoint, ImmutableHashSet.Create(startingPoint));
            var cleanedPlacesInTheEnd = Enumerable.Range(0, 10).Select(i => new Point(0, i)).ToImmutableHashSet();
            var expectedSessionOnEnd  = new Session(new Point(1, 1), cleanedPlacesInTheEnd);

            _suit.SetupMock <ICommandExecutor>(e =>
                                               // Make the runner emulate first 3 commands did nothing
                                               e.Execute(It.Is <Command>(c => robotSettings.Commands.Contains(c)), expectedSession.Equivalent()) == expectedSession &&
                                               // But the last one returned 10 cleaned places
                                               e.Execute(robotSettings.Commands[3], expectedSession.Equivalent()) == expectedSessionOnEnd);

            // Act
            var result = _suit.Sut.Clean(robotSettings);

            // Assert
            result.Should().Be(cleanedPlacesInTheEnd.Count,
                               " anyway only the cleanedPlacesAtTheEnd.Count should matter");
        }
示例#2
0
        public void Reset_MocksShouldBeReset()
        {
            //arrange
            _testSuit.SetupMock <IDependency1>(d => d.GetNumber() == "one");
            _testSuit.SetupMock <IDependency2>(d => d.Action2() == "two");
            _testSuit.Sut.Dependency1.GetNumber();
            _testSuit.Sut.Dependency2.Action2();

            //act
            _testSuit.Reset();

            //assert
            //note: checking that the invocations are cleared only because its hard to check anything else
            _testSuit.GetMock <IDependency1>().Invocations.Should().BeEmpty();
            _testSuit.GetMock <IDependency2>().Invocations.Should().BeEmpty();
        }
示例#3
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);
        }