I am using AutoFixture to try and test my controllers for the WebApi site. I am using the AutoData function with Moq, as stated on the Ploeh blog .
My controller accepts the IDepartmentManager in the constructor. Here is my test:
[Theory, AutoMoqData] public void GetCallsManagerCorrectly( [Frozen]Mock<IDepartmentManager> departmentManagerMock, DepartmentsController sut) {
When I run this test, it fails with the following:
GetCallsManagerCorrectly failed:
Bug Fix System.InvalidOperationException: An exception was thrown while retrieving data for the Provision.Tests.WebApiControllerTests.DepartmentControllerTests.GetCallsManagerCorrectly: System.Reflection.TargetInvocationException theory: The exception was thrown on the target of the call. ---> System.ArgumentException: Only "http" and "https" schemes are allowed. Parameter name: value in System.Net.Http.HttpRequestMessage.set_RequestUri (Uri value)
First of all, is this really the right and recommended way to write these tests? I like how little he does everything.
Secondly, what should I do to fix this? If I change my test to this:
[Theory, AutoMoqData] public void GetCallsManagerCorrectly( [Frozen]Mock<IDepartmentManager> departmentManagerMock) {
it passes, but then I lose the ability to automatically create the controller and still be fine if I add parameters to the constructor.
source share