Each unit test should check one requirement or problem. Your method implements two requirements:
1) If prompted null, return BadRequestErrorMessageResultan object with a predefined error message. 2) If the request property is MyIDempty GUID, return an object BadRequestErrorMessageResultwith another predefined error message.
This means that we must have two unit tests:
[Test]
public async Task CreateDemo_returns_BadRequestErrorMessageResult_when_request_is_null()
{
var controller = new HomeController();
var response = await controller.CreateDemo(null);
Assert.IsInstanceOf<BadRequestErrorMessageResult>(response);
Assert.AreEqual("request can not be null", response.Message);
}
[Test]
public async Task CreateDemo_returns_BadRequestErrorMessageResult_when_request_ID_is_empty_GUID()
{
var controller = new HomeController();
var request = new MyRequest(Guid.Empty);
var response = await controller.CreateDemo(request);
Assert.IsInstanceOf<BadRequestErrorMessageResult>(response);
Assert.AreEqual("MyID must be provided", response.Message);
}
, , , , , (, Message ). , .
:
nunit, , . , , [TestMethod], Microsoft. , , . Assert.IsInstanceOf Assert.IsInstanceOfType.
, GUID MyRequest , MyID.
, , BadRequest , BadRequestErrorMessageResult, string .