|
| 1 | +// Copyright 2019 Florian Gather <florian.gather@tngtech.com> |
| 2 | +// Copyright 2019 Fritz Brandhuber <fritz.brandhuber@tngtech.com> |
| 3 | +// Copyright 2020 Pavel Fischer <rubbiroid@gmail.com> |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: Apache-2.0 |
| 6 | +// |
| 7 | + |
| 8 | +using System.Linq; |
| 9 | +using ArchUnitNET.Domain; |
| 10 | +using ArchUnitNET.Domain.Extensions; |
| 11 | +using ArchUnitNET.Loader; |
| 12 | +using Xunit; |
| 13 | + |
| 14 | +namespace ExampleTest |
| 15 | +{ |
| 16 | + public class LimitationsOnReleaseTest |
| 17 | + { |
| 18 | + private static readonly Architecture Architecture = |
| 19 | + new ArchLoader().LoadAssembly(typeof(LimitationsOnReleaseTest).Assembly).Build(); |
| 20 | + |
| 21 | + private static IType _edgeCaseDataClass = Architecture.GetClassOfType(typeof(EdgeCaseData)); |
| 22 | + private static IType _missingDependencyClass = Architecture.GetClassOfType(typeof(MissingDependencyClass)); |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void CastTest() |
| 26 | + { |
| 27 | + var typeDependencies = _edgeCaseDataClass.Members |
| 28 | + .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithCastDependency))).ToList().First() |
| 29 | + .GetTypeDependencies().ToList(); |
| 30 | + |
| 31 | + Assert.Contains(_missingDependencyClass, typeDependencies); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void NullVariableTest() |
| 36 | + { |
| 37 | + var methodWithCastDependencyDependencies = _edgeCaseDataClass.Members |
| 38 | + .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithNullVariable))).ToList().First() |
| 39 | + .GetTypeDependencies().ToList(); |
| 40 | + |
| 41 | + Assert.Contains(_missingDependencyClass, methodWithCastDependencyDependencies); |
| 42 | + } |
| 43 | + |
| 44 | + [Fact] |
| 45 | + public void TypeOfDependencyTest() |
| 46 | + { |
| 47 | + var methodWithTypeOfDependencyDependencies = _edgeCaseDataClass.Members |
| 48 | + .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithTypeOfDependency))).ToList().First() |
| 49 | + .GetTypeDependencies().ToList(); |
| 50 | + |
| 51 | + Assert.Contains(_missingDependencyClass, methodWithTypeOfDependencyDependencies); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + internal class EdgeCaseData |
| 56 | + { |
| 57 | + public void MethodWithTypeOfDependency() |
| 58 | + { |
| 59 | + var a = typeof(MissingDependencyClass); |
| 60 | + } |
| 61 | + public void MethodWithCastDependency() |
| 62 | + { |
| 63 | + var a = (MissingDependencyClass) new SubClass(); |
| 64 | + } |
| 65 | + |
| 66 | + public void MethodWithNullVariable() |
| 67 | + { |
| 68 | + MissingDependencyClass a = null; |
| 69 | + } |
| 70 | + } |
| 71 | + internal class MissingDependencyClass |
| 72 | + { |
| 73 | + } |
| 74 | + internal class SubClass : MissingDependencyClass |
| 75 | + { |
| 76 | + } |
| 77 | +} |
0 commit comments