public void FindStation_Failed() { var stationFindPattern = "stat"; var stationProviderMock = new Mock <IStationProvider>(MockBehavior.Strict); stationProviderMock.Setup(p => p.FindStations(It.IsAny <string>())) .Throws <Exception>(); var distCalcMock = new Mock <IStationDistanceCalculator>(MockBehavior.Strict); var distCalcController = new DistanceCalculatorController(distCalcMock.Object, stationProviderMock.Object); distCalcController.Request = new HttpRequestMessage(); distCalcController.Configuration = new HttpConfiguration(); // Act var response = distCalcController.FindStations(stationFindPattern); distCalcMock.Verify(); stationProviderMock.Verify(p => p.FindStations(It.IsAny <string>()), Times.Once); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void GetDistance_Failed() { var station1 = StationData.Station1; var station2 = StationData.Station2; var stationProviderMock = new Mock <IStationProvider>(MockBehavior.Strict); stationProviderMock.SetupSequence(p => p.GetStation(It.IsAny <string>())) .Returns(station1) .Returns(station2); double distance = 10.9; var distCalcMock = new Mock <IStationDistanceCalculator>(MockBehavior.Strict); distCalcMock.Setup(calc => calc.GetDistance(It.IsAny <IStation>(), It.IsAny <IStation>())) .Throws <Exception>(); var distCalcController = new DistanceCalculatorController(distCalcMock.Object, stationProviderMock.Object); distCalcController.Request = new HttpRequestMessage(); distCalcController.Configuration = new HttpConfiguration(); // Act var response = distCalcController.GetDistance(station1.Name, station2.Name); stationProviderMock.Verify(p => p.GetStation(It.IsAny <string>()), Times.Exactly(2)); distCalcMock.Verify(calc => calc.GetDistance(It.IsAny <IStation>(), It.IsAny <IStation>()), Times.Once); Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); }
public void GetAddress_ShouldReturnFiveResult() { DistanceCalculatorController controller = new DistanceCalculatorController(); List <Address> result = controller.Get(Constants.ADDRESSINPUT); Assert.AreEqual(result.Count, 5); }
public void GetAddress_ShouldReturnResult() { DistanceCalculatorController controller = new DistanceCalculatorController(); List <Address> result = controller.Get(Constants.ADDRESSINPUT); Assert.IsNotNull(result); }
public void GetAddress_ShouldReturnNearestResult() { DistanceCalculatorController controller = new DistanceCalculatorController(); List <Address> result = controller.Get(Constants.ADDRESSINPUT); var expectedResult = result.OrderBy(x => x.KM); Assert.IsTrue(expectedResult.SequenceEqual(result)); }
private void DistanceCalculator_Load(object sender, EventArgs e) { //Input Fields Empty StartLatitudeTextBox.Text = "0"; StartLongitudeTextBox.Text = "0"; EndLatitudeTextBox.Text = "0"; EndLongitudeTextBox.Text = "0"; //Result Fields Empty KilometerTextBox.Text = String.Empty; MeterTextBox.Text = String.Empty; NautilesMilesTextBox.Text = String.Empty; MilesTextBox.Text = String.Empty; _distanceCalculatorController = new DistanceCalculatorController(); }
public void GetDistance_Success() { var station1 = StationData.Station1; var station2 = StationData.Station2; var stationProviderMock = new Mock <IStationProvider>(MockBehavior.Strict); stationProviderMock.SetupSequence(p => p.GetStation(It.IsAny <string>())) .Returns(station1) .Returns(station2); double distance = 10.9; var distCalcMock = new Mock <IStationDistanceCalculator>(MockBehavior.Strict); distCalcMock.Setup(calc => calc.GetDistance(It.IsAny <IStation>(), It.IsAny <IStation>())) .Returns(distance); var distCalcController = new DistanceCalculatorController(distCalcMock.Object, stationProviderMock.Object); distCalcController.Request = new HttpRequestMessage(); distCalcController.Configuration = new HttpConfiguration(); // Act var response = distCalcController.GetDistance(station1.Name, station2.Name); stationProviderMock.Verify(p => p.GetStation(It.IsAny <string>()), Times.Exactly(2)); distCalcMock.Verify(calc => calc.GetDistance(It.Is <IStation>(st => st.Equals(station1)), It.Is <IStation>(st => st.Equals(station2))), Times.Once); double resultDist; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(response.TryGetContentValue(out resultDist)); Assert.AreEqual(distance, resultDist, "Result distance is incorrect"); }
public void GetDistance_GetStation1_Failed() { var station1 = StationData.Station1; var stationProviderMock = new Mock <IStationProvider>(MockBehavior.Strict); stationProviderMock.Setup(p => p.GetStation(It.Is <string>(s => s == null))) .Throws <Exception>(); stationProviderMock.Setup(p => p.GetStation(It.IsNotNull <string>())) .Returns(station1); double distance = 10.9; var distCalcMock = new Mock <IStationDistanceCalculator>(MockBehavior.Strict); distCalcMock.Setup(calc => calc.GetDistance(It.IsAny <IStation>(), It.IsAny <IStation>())) .Returns(distance); var distCalcController = new DistanceCalculatorController(distCalcMock.Object, stationProviderMock.Object); distCalcController.Request = new HttpRequestMessage(); distCalcController.Configuration = new HttpConfiguration(); // Act var response = distCalcController.GetDistance(null, station1.Name); stationProviderMock.Verify(p => p.GetStation(It.IsAny <string>()), Times.Once); distCalcMock.Verify(calc => calc.GetDistance(It.IsAny <IStation>(), It.IsAny <IStation>()), Times.Never); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void FindStation_Success() { var stationFindPattern = "stat"; var stations = StationData.Stations; string stationFindPatternInternal = null; var stationProviderMock = new Mock <IStationProvider>(MockBehavior.Strict); stationProviderMock.Setup(p => p.FindStations(It.IsAny <string>())) .Callback((string s) => stationFindPatternInternal = s) .Returns(stations); var distCalcMock = new Mock <IStationDistanceCalculator>(MockBehavior.Strict); var distCalcController = new DistanceCalculatorController(distCalcMock.Object, stationProviderMock.Object); distCalcController.Request = new HttpRequestMessage(); distCalcController.Configuration = new HttpConfiguration(); // Act var response = distCalcController.FindStations(stationFindPattern); distCalcMock.Verify(); stationProviderMock.Verify(p => p.FindStations(It.IsAny <string>()), Times.Once); Assert.AreEqual(stationFindPattern, stationFindPatternInternal, "Station name pattern parameter passed to FindStation method of station provider is incorrect."); IEnumerable <IStation> resultStations; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(response.TryGetContentValue(out resultStations)); Assert.AreEqual(stations, resultStations, "Result stations is incorrect"); }