Пример #1
0
        public void CalculateRange_OnSuccess_ReturnValidResult(IRangeCalculationStrategy strategy,
                                                               IntervalUnit unit, int intervalValue, int maxSpeed, double?expectedValue)
        {
            var testShip = StarshipUtils.Create(unit, intervalValue, maxSpeed);

            Assert.Equal(expectedValue, strategy.CalculateRange(testShip));
        }
Пример #2
0
        public void CalculateRange_WhenNullInterval_ReturnsNull()
        {
            var testShip = StarshipUtils.Create(IntervalUnit.Unknown, null, null);
            var strategy = new SimpleRangeCalculationStrategy();

            Assert.Null(strategy.CalculateRange(testShip));
        }
Пример #3
0
        public void CalculateRange_WhenUnitMismatch_ThrowsCalculationException()
        {
            var testShip = StarshipUtils.Create(IntervalUnit.Day, 1, 1);
            var strategy = new SimpleRangeCalculationStrategy();

            Assert.Throws <CalculationException>(() => strategy.CalculateRange(testShip));
        }
Пример #4
0
        public void CalculateTotalStops_WhenRangeCalculationNotNull_ReturnsValidResult()
        {
            var moqFactory = new Mock <IRangeCalculationStrategyFactory>();

            moqFactory.Setup(mf => mf.GetRangeCalculationStrategy(It.IsAny <IntervalUnit>()))
            .Returns(CreateMoqStrategy(2).Object);

            var testCalculator = new StopsCalculator(moqFactory.Object, new Mock <ILogger>().Object);
            var result         = testCalculator.CalculateTotalStops(StarshipUtils.Create(IntervalUnit.Day, 2, 1), 5);

            Assert.True(result.IsValid);
            Assert.Equal(2, result.NumberOfStops);
        }
Пример #5
0
        public void CalculateTotalStops_WhenRangeCalculationZero_ThrowsDivideByZeroException()
        {
            var moqFactory = new Mock <IRangeCalculationStrategyFactory>();

            moqFactory.Setup(mf => mf.GetRangeCalculationStrategy(It.IsAny <IntervalUnit>()))
            .Returns(CreateMoqStrategy(0).Object);

            var testCalculator = new StopsCalculator(moqFactory.Object, new Mock <ILogger>().Object);

            Assert.Throws <DivideByZeroException>(() => testCalculator.CalculateTotalStops(StarshipUtils.Create(IntervalUnit.Day, 2, 1), 1));
        }