I have a small problem with running the unit tests with dotnet CLI. I am using xUnit and JustMock.
I have a class called 'DevOpsOptions' which is a internal and located in UserManagement project.
Example:
internal class DevOpsOptions
{
public string Username { get; set; }
public string Password { get; set; }
}
I also have another project for unit tests, called UserManagement.Tests. I added reference to the UserManagement project and set InternalVisibility
Example:
<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
</ItemGroup>
I wrote a test that runs successfully if run the standard way. Right click -> Run tests Example:
[Fact]
public async void ThrowArgumentException_WhenUserEmailIsNull()
{
//Arrange
HttpClient httpClient = Mock.Create<HttpClient>();
ClientOptions clientApplicationOptions = Mock.Create<ClientOptions>();
IOptions<DevOpsOptions> devOpsOptions = Mock.Create<IOptions<DevOpsOptions>>();
AzureDevOpsSettings azureDevOpsSettings = new AzureDevOpsSettings();
IHttpDevOpsServiceClient httpDevOpsServiceClient = new HttpDevOpsServiceClient(httpClient, clientApplicationOptions, devOpsOptions);
//Act
async Task actAsync() => await httpDevOpsServiceClient.DeleteUser(null, azureDevOpsSettings);
//Assert
await Assert.ThrowsAsync<ArgumentException>(actAsync);
}
But when i try to run the test with dotnet command
dotnet test .\UserManagement.Test.csproj
Its throw this exception:
Abstract type Microsoft.Extensions.Options.IOptions'1[Models.DevOpsOptions] is not accessible for inheritance
But when i change Model type to public, everything is fine.