Example #1
0
        public void ShouldThrowCalculationException_OnCalculate_IfNoCalculator()
        {
            // arrange
            var unitService = new UnitServiceStub();
            var service     = new DistanceService(new IDistanceCalculator[] {  }, unitService);
            var c1          = new Coordinate {
                Longitude = 0, Latitude = 0
            };
            var c2 = new Coordinate {
                Longitude = 1, Latitude = 1
            };

            // act and arrange
            Assert.Throws <CalculationException>(() => service.Calculate(c1, c2));
        }
Example #2
0
        public void ShouldNotFail_OnCalculate_IfValidCalculatorExists()
        {
            // arrange
            var calculator1 = new DistanceFailureCalculatorStub();
            var calculator2 = new DistanceSuccessCalculatorStub();
            var unitService = new UnitServiceStub();
            var service     = new DistanceService(new IDistanceCalculator[] { calculator1, calculator2 }, unitService);
            var c1          = new Coordinate {
                Longitude = 0, Latitude = 0
            };
            var c2 = new Coordinate {
                Longitude = 1, Latitude = 1
            };

            // act
            var value = service.Calculate(c1, c2);

            // assert
            Assert.NotNull(value);
            Assert.Equal(Units.Meters, value.Units);
            Assert.Equal(10, value.Value);
        }