public void ShouldThrowCalculationException_OnCalculate_IfCalculatorCannotCalculate() { // arrange var calculator = new DistanceFailureCalculatorStub(); var unitService = new UnitServiceStub(); var service = new DistanceService(new IDistanceCalculator[] { calculator }, 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)); }
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); }