I am using NUnit with FakeIteasy
My test Method:
[Test]
public async Task SiteDetailsView_NMSException()
{
url = "/Svc/v1/Sites/GetNextID?UID=" + orgUID;
A.CallTo(() => fake.GetDataAsync<int>(fakeHttpSession, url)).Throws(new Exception(new Uri(url),
new ExceptionDetail()
{
ErrorCode=ExceptionErrorCode.ParameterOutOfRange
Description="param OrganizationUID"
}));
// Act
var actionResult = await myController.DetailsView(UID, oName, oUID, isReadOnly);
var viewResult = actionResult as ViewResult;
// Assert
Assert.IsNotNull(actionResult);
}
My controller Code:
public async Task<ActionResult> DetailsView(int sUID, string oName, int oUID, bool isReadOnly)
{
try
{
SModel siModel = new SModel();
siModel .dite.Id = await _client.GetDataAsync<int>(Session, "/ManagementSvc/v1/ites/GetID?oUID=" + orgUID);
}
catch (Exception ex)
{
return View("Error", _plExceptionHandler.HandleException(ex));
}
}
}
I am getting error as
System.Uri.Format Exception : the format of URI cannot be determined.' at
A.CallTo(() => fake.GetDataAsync<int>(fakeHttpSession, url)).Throws(new SException(new Uri(url), new ExceptionDetail() { ErrorCode=ExceptionErrorCode.ParameterOutOfRange,Description="param OUID"}));
IS there any way to ignore the first(Uri) parameter and throw exception. I cannot pass null as well for the first parameter
here is my Exception class:
public class NException : Exception
{
private readonly NExceptionDetail m_ExceptionDetails;
private readonly Uri m_requestUri;
public NException(Uri requestUri, nExceptionDetail nExceptionDetails)
{
if (requestUri == null)
throw new ArgumentNullException("requestUri");
m_requestUri = requestUri;
}
}
How to throw NException
using FakeItEasy.
I want to do assertions for the error messages.
How can i do assertion.