Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to test code in Asp.net core project, in controller class in a controller folder

$
0
0

I have an ASP.net core project, using controllers and models, I have a ValidatePromoCodeApi class ,  

[HttpGet]
[Route("/ValidatePromoCode")]
// [SwaggerOperation("ValidatePromoCodeGet")]
// [SwaggerResponse(200, type: typeof(PromoCodeResponse))]
public IActionResult ValidatePromoCodeGet([FromQuery]string promocode, [FromQuery]double? staylength, [FromQuery]double? orderAmount)
{

     SqlConnection sqlConn = new SqlConnection("server=ROHIT-LAPTOP\\SQLEXPRESS;database=UseTest;uid=rohit;password=111222Rt;");

     string sql = "spReadParam";
     SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);

     sqlCmd.CommandType = CommandType.StoredProcedure;
     sqlCmd.Parameters.AddWithValue("@Param", "Rohit");

     SqlParameter outPutParam = new SqlParameter();
     outPutParam.ParameterName = "@ParamOutput";
     outPutParam.SqlDbType = System.Data.SqlDbType.VarChar;
     outPutParam.Direction = System.Data.ParameterDirection.Output;
     sqlCmd.Parameters.Add(outPutParam);

     sqlConn.Open();
     sqlCmd.CommandText = sql;
     sqlCmd.ExecuteNonQuery();
     sqlConn.Close();

     string Parameter = outPutParam.Value.ToString();

     return new ObjectResult(theResp);

}



Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>