Skip to content

Commit d42ec15

Browse files
committed
add example test for plant uml
Signed-off-by: Marco Studer <marco.studer@bison-group.com>
1 parent 8017fce commit d42ec15

File tree

12 files changed

+236
-2
lines changed

12 files changed

+236
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent;
3+
using ArchUnitNET.Loader;
4+
using ArchUnitNET.xUnit;
5+
using ExampleTest.PlantUml.Addresses;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
using Xunit;
10+
using static ArchUnitNET.Fluent.ArchRuleDefinition;
11+
12+
namespace ExampleTest
13+
{
14+
public class ExampleArchUnitTestPuml
15+
{
16+
private static readonly Architecture Architecture = new ArchLoader().LoadNamespacesWithinAssembly(typeof(Address).Assembly, "ExampleTest.PlantUml").Build();
17+
18+
[Fact]
19+
public void ClassesShouldAdhereToShoppingExampleConsideringOnlyDependenciesInDiagram()
20+
{
21+
var filename = "./Resources/shopping_example.puml";
22+
23+
IArchRule adhereToPlantUmlDiagram = Types().Should().AdhereToPlantUmlDiagram(filename);
24+
adhereToPlantUmlDiagram.Check(Architecture);
25+
}
26+
}
27+
}

ExampleTest/ExampleTest.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
1717
</ItemGroup>
1818

19+
<ItemGroup>
20+
<None Update="Resources\shopping_example.puml">
21+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
24+
1925
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using ExampleTest.PlantUml.Catalog;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace ExampleTest.PlantUml.Addresses
7+
{
8+
public class Address
9+
{
10+
#pragma warning disable CS0169
11+
private ProductCatalog productCatalog;
12+
#pragma warning restore CS0169
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using ExampleTest.PlantUml.Orders;
2+
using ExampleTest.PlantUml.Products;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace ExampleTest.PlantUml.Catalog
8+
{
9+
public class ProductCatalog
10+
{
11+
private List<Product> _allProducts = new List<Product>();
12+
13+
internal void GonnaDoSomethingIllegalWithOrder()
14+
{
15+
Order order = new Order();
16+
foreach (Product product in _allProducts)
17+
{
18+
product.Register();
19+
}
20+
order.AddProducts(_allProducts);
21+
}
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using ExampleTest.PlantUml.Addresses;
2+
using ExampleTest.PlantUml.Orders;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace ExampleTest.PlantUml.Customers
8+
{
9+
public class Customer
10+
{
11+
public Address Address { get; set; }
12+
13+
internal void AddOrder(Order order)
14+
{
15+
// simply having such a parameter violates the specified UML diagram
16+
}
17+
18+
}
19+
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using ExampleTest.PlantUml.Catalog;
2+
using ExampleTest.PlantUml.Customers;
3+
using ExampleTest.PlantUml.Xml.Processor;
4+
using ExampleTest.PlantUml.Xml.Types;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace ExampleTest.PlantUml.Importer
10+
{
11+
public class ProductImport
12+
{
13+
public ProductCatalog productCatalog;
14+
public XmlTypes xmlType;
15+
public XmlProcessor xmlProcessor;
16+
17+
public Customer Customer
18+
{
19+
get
20+
{
21+
return new Customer(); // violates diagram -> product import may not directly know Customer
22+
}
23+
}
24+
25+
ProductCatalog Parse(byte[] xml)
26+
{
27+
return new ProductCatalog();
28+
}
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ExampleTest.PlantUml.Addresses;
2+
using ExampleTest.PlantUml.Customers;
3+
using ExampleTest.PlantUml.Products;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
namespace ExampleTest.PlantUml.Orders
9+
{
10+
public class Order
11+
{
12+
public Customer _customer;
13+
private List<Product> _products = new List<Product>();
14+
15+
public void AddProducts(IList<Product> products)
16+
{
17+
_products.AddRange(products);
18+
}
19+
20+
internal void Report()
21+
{
22+
Report(_customer.Address);
23+
foreach (Product product in _products)
24+
{
25+
product.Report();
26+
}
27+
}
28+
29+
private void Report(Address address)
30+
{
31+
}
32+
}
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using ExampleTest.PlantUml.Customers;
2+
using ExampleTest.PlantUml.Orders;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace ExampleTest.PlantUml.Products
8+
{
9+
public class Product
10+
{
11+
public Customer _customer;
12+
13+
internal Order Order
14+
{
15+
get
16+
{
17+
return null; // the return type violates the specified UML diagram
18+
}
19+
}
20+
21+
22+
public void Register()
23+
{
24+
}
25+
26+
public void Report()
27+
{
28+
}
29+
}
30+
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ExampleTest.PlantUml.Xml.Processor
6+
{
7+
public class XmlProcessor
8+
{
9+
}
10+
}

ExampleTest/ExampleArchitectureTestPlantUml.cs renamed to ExampleTest/PlantUml/Xml/Types/XmlTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace ExampleTest
5+
namespace ExampleTest.PlantUml.Xml.Types
66
{
7-
public class ExampleArchitectureTestPlantUml
7+
public class XmlTypes
88
{
99
}
1010
}

0 commit comments

Comments
 (0)