Skip to content

NetArchTest ignores a nameof expression #81

@dbeylkhanov

Description

@dbeylkhanov

I faced with the strange behavior by NetArchTest when I worked with the nameof expression.

I have a simple an architecture test which is below:

public void DomainLayerDoesNotHaveDependencyOnInfrastructureLayer() {
	TestResult result = Types.InAssembly(typeof(Identity).Assembly)
		.That()
		.ResideInNamespace("StronglyTypedIdentity.Domain")
		.ShouldNot()
		.HaveDependencyOn("StronglyTypedIdentity.Infrastructure")
		.GetResult();

	Assert.That(result.IsSuccessful);
}

As you see, I want to avoid dependencies on the Infrastructure in the Domain layer (according to the Onion architecture it's wrong).

Now I'm going to apply this arch. test for my pet project .

To reproduce a strange behavior with nameof I deliberately decided to instantiate an object with CustomDbContext type(Infrastructure) in the CustomType (Domain). This means that I added a dependency on the Infrastructure layer in the Domain layer.
And now is an interesting moment, cuz, when I'm wrapping CustomDbContext into the nameof expr. (is evaluated at compile-time), then my arch test is successfully passing, but in fact, it should not. When I don't use nameof, the arch. test result is failed, and that is correct.

Watch my screencast here to realize an issue.
Also, visit my pet project to reproduce an issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions