public void Initialize() { validator = new Strategy2Validator(); viewModel = new Strategy2ViewModel { PointA = new CoordinateViewModel { Latitude = 32.3, Longitute = 43.34 }, PointB = new CoordinateViewModel { Latitude = 122.3332443, Longitute = -43.3886 }, Unit = "km", EarthRadius = 4544 }; }
private ResponseResult CalculateDistance(Strategy2ViewModel viewModel) { var response = validator.Validate(viewModel); if (!response.IsSucceed) { return(response); } var a = AppConstants.Degree90 - viewModel.PointB.Latitude; var b = AppConstants.Degree90 - viewModel.PointA.Latitude; var c = viewModel.PointA.Longitute - viewModel.PointB.Longitute; response.Result = Math.Cos(a) * Math.Cos(b) + Math.Sin(a) * Math.Sin(b) * Math.Cos(c) * viewModel.EarthRadius; return(response); }
public ActionResult <ResponseResult> GetDistanceByStrategy2(string unit, double latA, double lonA, double latB, double lonB) { var viewModel = new Strategy2ViewModel { PointA = new CoordinateViewModel { Latitude = latA, Longitute = lonA }, PointB = new CoordinateViewModel { Latitude = latB, Longitute = lonB }, Unit = unit, EarthRadius = AppConstants.EarthRadius }; var calculator = new DistanceCalulator(); calculator.SetStrategy(new Strategy2(new Strategy2Validator())); return(calculator.CalculateDistance(viewModel)); }
public void Initialize() { validator = new Mock <IStrategy2Validator>(); strategy1 = new Strategy2(validator.Object); viewModel = new Strategy2ViewModel { PointA = new CoordinateViewModel { Latitude = 32.3, Longitute = 43.34 }, PointB = new CoordinateViewModel { Latitude = 82.3332443, Longitute = -43.3886 }, Unit = "km", }; validResponse = new ResponseResult { IsSucceed = true, Message = "Succeed" }; inValidResponse = new ResponseResult { IsSucceed = false, Message = "Failed" }; }