Exemplo n.º 1
0
        public void Score_Cut_With_Failure_Rate_Should_Not_Fail()
        {
            var cutSettingsMock = new Mock <IScoreCutServiceSettings>();

            cutSettingsMock.SetupGet(x => x.CutTimeMilisecondDelay).Returns(0);
            cutSettingsMock.SetupGet(x => x.FailureRatePerCut).Returns(.5m);
            cutSettingsMock.SetupGet(x => x.MaxFailures).Returns(2);

            var failureServiceMock = new Mock <IFailureService>();

            failureServiceMock.SetupSequence(x => x.IsFailure(It.IsAny <decimal>()))
            .Returns(true)
            .Returns(false);

            var loggerMock = new Mock <ILogger <ScoreCutService> >();

            var scoreCutService = new ScoreCutService(cutSettingsMock.Object, failureServiceMock.Object, loggerMock.Object);
            var layout          = new Bitmap(100, 100);
            var tile            = new Bitmap(100, 100);
            var gridElement     = new GridElement(new Coordinate(0, 0), tile);

            Func <Task> action = async() => await scoreCutService.CutTile(layout, gridElement);

            action.Should().NotThrow("the first pass thru will not be successful but the second one will be successful.");
        }
Exemplo n.º 2
0
        public void Score_Cut_With_Failure_Rate_Zero_Should_Not_Fail()
        {
            var cutSettingsMock = new Mock <IScoreCutServiceSettings>();

            cutSettingsMock.SetupGet(x => x.CutTimeMilisecondDelay).Returns(0);
            cutSettingsMock.SetupGet(x => x.FailureRatePerCut).Returns(0);
            cutSettingsMock.SetupGet(x => x.MaxFailures).Returns(0);

            var failureServiceMock = new Mock <IFailureService>();

            failureServiceMock
            .Setup(x => x.IsFailure(It.IsAny <decimal>()))
            .Returns(true);

            var loggerMock = new Mock <ILogger <ScoreCutService> >();

            var scoreCutService = new ScoreCutService(cutSettingsMock.Object, failureServiceMock.Object, loggerMock.Object);
            var layout          = new Bitmap(100, 100);
            var tile            = new Bitmap(100, 100);
            var gridElement     = new GridElement(new Coordinate(0, 0), tile);

            Func <Task> action = async() => await scoreCutService.CutTile(layout, gridElement);

            action.Should().NotThrow("failure rate per cut is 0");
        }