public void shouldGetOrbitAndVehicleWithShortestTravelTimeSuitableToWeather() { Mock <Vehicle> bikeMock = new Mock <Vehicle>(MockBehavior.Strict); bikeMock.Setup(_ => _.getVehicleType()).Returns(VehicleType.Bike); bikeMock.Setup(_ => _.canTravel(It.IsAny <Weather>())).Returns(true); bikeMock.Setup(_ => _.getTravelTime(It.Is <Orbit>(o => o.getDescription() == orbit1.getDescription()), It.IsAny <Weather>())) .Returns(2); bikeMock.Setup(_ => _.getTravelTime(It.Is <Orbit>(o => o.getDescription() == orbit2.getDescription()), It.IsAny <Weather>())) .Returns(1.5); bikeMock.Setup(_ => _.ToString()).Returns(bikeMock.Object.getVehicleType().ToString()); Mock <Vehicle> superCarMock = new Mock <Vehicle>(MockBehavior.Strict); superCarMock.Setup(_ => _.getVehicleType()).Returns(VehicleType.SuperCar); superCarMock.Setup(_ => _.canTravel(It.IsAny <Weather>())).Returns(false); superCarMock.Setup(_ => _.getTravelTime(It.Is <Orbit>(o => o.getDescription() == orbit1.getDescription()), It.IsAny <Weather>())) .Returns(1.7); superCarMock.Setup(_ => _.getTravelTime(It.Is <Orbit>(o => o.getDescription() == orbit2.getDescription()), It.IsAny <Weather>())) .Returns(1.4); superCarMock.Setup(_ => _.ToString()).Returns(superCarMock.Object.getVehicleType().ToString()); var helper = new TravelHelper(new Orbit[] { orbit1, orbit2 }, new Vehicle[] { bikeMock.Object, superCarMock.Object }, WeatherType.Rainy); var expectedOutput = "Vehicle " + bikeMock.Object.getVehicleType().ToString() + " on " + orbit2.getDescription(); var shortestTrip = helper.getTripWithShortestTravelTime(); Assert.AreEqual(expectedOutput, shortestTrip.ToString()); }
public void MethodOne() { Console.WriteLine("Integeration test 1:"); Orbit[] orbits = new Orbit[] { new Orbit("Orbit1", 12, 20, 18), new Orbit("Orbit2", 10, 10, 20) }; Vehicle[] vehicles = new Vehicle[] { new Vehicle(VehicleType.Bike, 10, 2, new WeatherType[] { WeatherType.Sunny, WeatherType.Windy }, 1), new Vehicle(VehicleType.TukTuk, 12, 1, new WeatherType[] { WeatherType.Sunny, WeatherType.Rainy }, 2), new Vehicle(VehicleType.SuperCar, 20, 3, new WeatherType[] { WeatherType.Sunny, WeatherType.Windy, WeatherType.Rainy }, 3) }; TravelHelper helper = new TravelHelper(orbits, vehicles, WeatherType.Sunny); var shortestTrip = helper.getTripWithShortestTravelTime(); Console.WriteLine("Input: Weather is Sunny"); Console.WriteLine("Input: Orbit1 traffic speed is 12 megamiles/hour"); Console.WriteLine("Input: Orbit2 traffic speed is 10 megamiles/hour"); Console.WriteLine("Output: " + shortestTrip.ToString()); Console.WriteLine(); }