I am trying to unit test an AspNetCore.Mvc controller with Typemock. Here is the top layer of the controller code.
public async Task<ActionResult> AddFooAsync([FromRoute]string novelid, [FromBody]AddFoo command)
var novel = await RetrieveNovel(novelid);
if (novel == null) return NotFound();
if (!ModelState.IsValid) return BadRequest(ModelState);
command.FooId = Guid.NewGuid();
return Created(UriFactory.GetFooRoute(novel.Novel.NovelId, command.FooId), command);
Here is the test code I've written so far..
public class FooController_UnitTests
public async Task TestMethod()
string novelid = "0";
Novel controllerUnderTest = Isolate.Fake.Dependencies<Novel>();
var ValidTestFoo = Isolate.Fake.Dependencies<AddFoo>();
//Fake the RetrieveNovel(novelid) call
Isolate.NonPublic.WhenCalled(controllerUnderTest, "RetrieveNovel").WillReturn(Task.FromResult(new GenreNovel()));
//Fake the ModelState
Isolate.WhenCalled(() => controllerUnderTest.ModelState.IsValid).WillReturn(true);
var fooResponse = controllerUnderTest.AddFooAsync(novelid, ValidTestFoo);
//that RetrieveNovel(novelid) is called
//that (!ModelState.IsValid) is called
Isolate.Verify.WasCalledWithAnyArguments(() => controllerUnderTest.ModelState.IsValid);
//that command.FooId was set with a Guid.NewGuid();
FooId is an internal property of AddFoo. Right now I am trying to test that the FooId was set as a consequence of the AddFooAsync method logic, AND that it was set with a Guid.NewGuid.
My other 2 Verifies are passing but when I run the test with the last verify I get ....
TypeMock Verification: Property blahblahblah was called with mismatching arguments.