Coder Social home page Coder Social logo

netarchtest's Introduction

NetArchTest

Build Status

A fluent API for .Net Standard that can enforce architectural rules in unit tests.

A fork and rewrite from BenMorris/NetArchTest which is inspired by the ArchUnit library for Java.

Rationale

This project allows you create tests that enforce conventions for class design, naming and dependency in .Net code bases. These can be used with any unit test framework and incorporated into a build pipeline. It uses a fluid API that allows you to string together readable rules that can be used in test assertions.

There are plenty of static analysis tools that can evaluate application structure, but they are aimed more at enforcing generic best practice rather than application-specific conventions. The better tools in this space can be press-ganged into creating custom rules for a specific architecture, but the intention here is to incorporate rules into a test suite and create a self-testing architecture.

The project is inspired by ArchUnit, a java-based library that attempts to address the difficulties of preserving architectural design patterns in code bases over the long term. Many patterns can only be enforced by convention, which tends to rely on a rigorous and consistent process of code review. This discipline often breaks down as projects grow, use cases become more complex and developers come and go.

Examples

// Classes in the presentation should not directly reference repositories
var result = Types.InCurrentDomain()
    .That(ResideInNamespace("NetArchTest.SampleLibrary.Presentation"))
    .Should(!HaveDependencyOn("NetArchTest.SampleLibrary.Data"))
    .GetResult();

// Classes in the "data" namespace should implement IRepository
result = Types.InCurrentDomain()
    .That(HaveDependencyOn("System.Data")
        & ResideInNamespace(("ArchTest")))
    .Should(ResideInNamespace("NetArchTest.SampleLibrary.Data"))
    .GetResult();

// All the service classes should be sealed
result = Types.InCurrentDomain()
    .That(ImplementInterface(typeof(IWidgetService)))
    .Should(BeSealed())
    .GetResult();

netarchtest's People

Contributors

benmorris avatar xiaoyvr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.