public void FirstTestMethod() { string commands = "LMLMLMLMM"; var position = new Position(1, 2, LocationEnum.N, commands, XCoordinate, YCoordinate); var result = _locationManager.SetLocation(position); Assert.NotNull(result); var resultJoin = result.xCoordinate.ToString() + result.yCoordinate.ToString() + result.location.ToString(); Assert.Equal("13N", resultJoin); }
public IActionResult Post(Guid userId, Location location) { logger.LogInformation("Saving location"); location.CreatedOn = DateTime.UtcNow; //put try catch only when you want to return custom message or status code, else this will //be caught in ExceptionHandling middleware so no need to put try catch here locationManager.SetLocation(userId, location); return(new StatusCodeResult(StatusCodes.Status201Created)); }
//[HttpPost("save")] public JsonResult CreateLocation([FromBody] LocationModel locationModel) { Position newPosition = null; try { if (ModelState.IsValid) { LocationEnum location = (LocationEnum)Enum.Parse(typeof(LocationEnum), locationModel.StPosition); Position position = new Position(locationModel.StStartX, locationModel.StStartY, location, locationModel.StCommand, locationModel.StMarsX, locationModel.StMarsY); newPosition = _locationManager.SetLocation(position); return(Json((object)new { data = "[" + newPosition.xCoordinate + "," + newPosition.yCoordinate + "] " + newPosition.location, message = newPosition == null ? "işlme başarısız!" : "işlme başarılı", success = newPosition == null ? "false" : "true", redirectUrl = "", })); } } catch (Exception ex) { if (ex.Message == "Coordinate_Out_bounds") { return(Json((object)new { data = "[Coordinate_Out_bounds]", message = "Başlangıç koordinatların büyük koordinat girildi.", success = "false", redirectUrl = "", })); } } return(Json((object)new { data = "NULL", message = "işlme başarısız! alanları kontorl ediniz", success = "false", redirectUrl = "", })); }