I would like to test my Web api in asp.net core 2.0 using moq. With operations like : GetAll, getByID there is no problem. But issue starts when I want to test methods like Insert or Update. Whenever I configure setup for example :
serviceMock.Setup(x => x.Update(someModel))
.Returns(someModel);
then call method for Controller under test :
ControllerUnderTest.UpdateRespondentList(someModel.ID, someModel);
Controller receives data properly but counter for my mock list doesn't increase.
I would like you to ask that is there other way then testing this using .Verify() method or create completely new List ?
-- there is what I mean : Unit testing LINQ to SQL CRUD operations using Moq
There is how I inject mocked service :
ControllerUnderTest = new RespondentListController(_config, serviceMock.Object);
In my opinion cinfiguration works because whenever I test methods like : getall I have an access to mockedSerivice
Algorithm should looks like this : Insert object into mocked list via ControllerUnderTest -> Asser.Equal (prevStateOfCounter, currentStateOfCounter-1)