Giter Club home page Giter Club logo

netarchtest.enhancededition's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

iggi131

netarchtest.enhancededition's Issues

Is there a better way to "ban" unwanted types, like DateTime?

This is something I came up in 5 minutes.

Still not perfect because I can still "create the class" with datetime and not use them.. but ok!

I could achieve the same result using rosyln analyzers

    [Fact]
    public void Test1()
    {
        var r = Types
            .InCurrentDomain()
            .That()
            .ResideInNamespaceContaining("Template.")
            .And()
            .MeetCustomRule(
                r1 => r1.Fields
                    .Any(f => f.FieldType.Name == nameof(DateTime))
            )
            .Should()
            .NotHaveDependencyOnAll()
            // .NotBeUsedByAny()
            .GetResult();

        r.IsSuccessful
            .Should()
            .BeTrue();
    }

Make some ExtensionMethods public for ICustomRule

Hi

I like this project very much, but currently it's a bit hard to write custom rules, because some of the extension methods, like TypeReferenceExtensions, TypeDefinitionExtensions, ... are internal.

For example, I like to write a CustomRule that checks if there are at least 3 TraitAttributes applied to all classes inherited from IntegrationTestBase.

Currently, I can only check against name or fullname of the attribute, because I cannot easily create a TypeDefinition or TypeReference from typeof(TraitAttribute).

I saw, there would be a ToTypeDefinition() method. Having this, would make it really handy.

And maybe 2nd question. How can I add a Explanation to custom Rules? Currently, there is only a bool as return value.

Inconsistent policy behaviour

Hi, the below example seems to produce correct results, i.e. fails on the InterfaceImplementationB class:

public interface IInterfaceA { }
public interface IInterfaceB { }

internal class InterfaceImplementationA : IInterfaceA { }
public class InterfaceImplementationB : IInterfaceB { }

  [Fact]
  public void InterfaceImplementationsShouldBeInternal()
  {
      var policy = Policy.Define("Interface Implementations", "Interface implementations should be internal")
                         .For(NetArchTest.Rules.Types.FromPath(AppDomain.CurrentDomain.BaseDirectory))
                         .Add(types =>
                             types.That()
                                  .ImplementInterface(typeof(IInterfaceB))
                                  .Should()
                                  .NotBePublic())
                         .Add(types =>
                             types.That()
                                  .ImplementInterface(typeof(IInterfaceA))
                                  .Should()
                                  .NotBePublic());

      var results = policy.Evaluate();
      Assert.False(results.HasViolations);
  }

But, when I change the order of policy rules to the below, the test starts passing:

    [Fact]
    public void InterfaceImplementationsShouldBeInternal()
    {
        var policy = Policy.Define("Interface Implementations", "Interface implementations should be internal")
                           .For(NetArchTest.Rules.Types.FromPath(AppDomain.CurrentDomain.BaseDirectory))
                           .Add(types =>
                               types.That()
                                    .ImplementInterface(typeof(IInterfaceA))
                                    .Should()
                                    .NotBePublic())
                           .Add(types =>
                               types.That()
                                    .ImplementInterface(typeof(IInterfaceB))
                                    .Should()
                                    .NotBePublic());

        var results = policy.Evaluate();
        Assert.False(results.HasViolations);
    }

Am I missing something in the implementation of policies, or is there a potential issue here?

Problem with Generic types

I have a problem to check types that have methods with generic types.
The explementation for the failing type is "Has dependency on: T1&"

How I can allow this dep or ignore it?

Test

PolicyResults results = Policy.Define("Deps", "Desc")
            .For(Types.InAssembly(typeof(KeyValuePairExtensions).Assembly))
            .Add(types => types.That()
                .ResideInNamespace("NetArchExample.Utils")
                .ShouldNot()
                .HaveDependencyOtherThan("NetArchExample.Utils", "System"))
            .Evaluate();

        foreach (var result in results.Results)
        {
            Assert.IsTrue(result.IsSuccessful);
        }

Code

namespace NetArchExample.Utils
{
    using System.Collections.Generic;

    /// <summary>
    /// Class KeyValuePairExtensions.
    /// </summary>
    public static class KeyValuePairExtensions
    {
        /// <summary>
        /// Deconstruct a key value pair.
        /// </summary>
        /// <param name="tuple">The tuple.</param>
        /// <param name="key">The deconstructed key.</param>
        /// <param name="value">The deconstructed value.</param>
        /// <typeparam name="T1">The type of the key.</typeparam>
        /// <typeparam name="T2">The type of the value.</typeparam>
        public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value)
        {
            key = tuple.Key;
            value = tuple.Value;
        }
    }
}

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.