•It talks to the database
•It communicates across the network
•It touches the file system
•It can't run at the same time as any of your other unit tests
•You have to do special things to your environment (such as editing config files) to run it.
<end>
If you find the post has answered your issue, then please mark post as 'answered'.
None
0 Points
1 Post
Xunit test case
Jun 05, 2018 09:53 PM|Vamshi J|LINK
Hi, I am new to xunit test cases. Learning to write xunit test cases.
Below is my method in the controller. I am trying to write test cases but i am facing issues. Need help on writing [Fact] test method
[HttpPost("trace")]
public ActionResult Post([FromBody] LogParametersModel logParameters)
{
bool isValidNLogFilePath = false;
try
{
isValidNLogFilePath = _appSettings.ValidateNLogFilePath();
validateInputModel(logParameters);
if (!isValidNLogFilePath) ModelState.AddModelError("", _appSettings.GetInvalidPathMessage());
if (ModelState.IsValid)
{
_logManager.Log(logParameters);
}
else
{
IEnumerable<string> allErrors = ModelState.Values.SelectMany(v => v.Errors.Select(n => n.ErrorMessage));
_logManager.CustomMessage(string.Join(LogConstants.LogSeparator, allErrors), LogConstants.Error);
//Response in Array format
LogResponseModel<IEnumerable<string>> errorObj = new LogResponseModel<IEnumerable<string>>()
{
ErrorMessages = allErrors
};
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return Json(errorObj);
}
return new EmptyResult();
}
catch (Exception ex)
{
LogResponseModel<string> errorObj = new LogResponseModel<string>()
{
ErrorMessages = ex.Message
};
if (isValidNLogFilePath)
{
string custommessage = ex.Message;
if (logParameters != null)
{
custommessage = "Web API Log => " +
"Application Name: " + logParameters.applicationName + LogConstants.LogSeparator +
"Class Name: " + logParameters.className + LogConstants.LogSeparator +
"Method Name: " + logParameters.methodName + LogConstants.LogSeparator +
"Message: " + ex.Message + LogConstants.LogSeparator +
"Arguments: " + logParameters.arguments + LogConstants.LogSeparator;
}
_logManager.CustomMessage("trace Method:" + custommessage, LogConstants.Error);
}
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
return Json(errorObj);
}
}
Contributor
4863 Points
4120 Posts
Re: Xunit test case
Jun 06, 2018 03:26 PM|DA924|LINK
A set of unit testing rules.....
https://www.artima.com/weblogs/viewpost.jsp?thread=126923
<copied>
A test is not a unit test if:
•It talks to the database
•It communicates across the network
•It touches the file system
•It can't run at the same time as any of your other unit tests
•You have to do special things to your environment (such as editing config files) to run it.
<end>