Skip to content

Commit 75d5efd

Browse files
committed
brought back the test for CSV report
1 parent 820ded8 commit 75d5efd

File tree

13 files changed

+189
-3
lines changed

13 files changed

+189
-3
lines changed

TestAssembly/Collections/Branch.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace TestAssembly.Collections
2+
{
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
6+
public class Branch : IEnumerable<Leaf>
7+
{
8+
readonly List<Leaf> items = new List<Leaf>();
9+
10+
public IEnumerator<Leaf> GetEnumerator()
11+
{
12+
return items.GetEnumerator();
13+
}
14+
15+
IEnumerator IEnumerable.GetEnumerator()
16+
{
17+
return GetEnumerator();
18+
}
19+
}
20+
}

TestAssembly/Collections/Forest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace TestAssembly.Collections
2+
{
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
6+
public class Forest : ICanAdd<Tree>, ICanRemove<Tree>
7+
{
8+
readonly List<Tree> items = new List<Tree>();
9+
10+
public void Add(Tree item)
11+
{
12+
items.Add(item);
13+
}
14+
15+
IEnumerator IEnumerable.GetEnumerator()
16+
{
17+
return ((IEnumerable) items).GetEnumerator();
18+
}
19+
20+
public IEnumerator<Tree> GetEnumerator()
21+
{
22+
return items.GetEnumerator();
23+
}
24+
25+
public bool Remove(Tree item)
26+
{
27+
return items.Remove(item);
28+
}
29+
}
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestAssembly.Collections
2+
{
3+
using System.Collections.Generic;
4+
5+
public interface ICanAdd<T> : IEnumerable<T>
6+
{
7+
void Add(T item);
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestAssembly.Collections
2+
{
3+
using System.Collections.Generic;
4+
5+
public interface ICanRemove<T> : IEnumerable<T>
6+
{
7+
bool Remove(T item);
8+
}
9+
}

TestAssembly/Collections/Leaf.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TestAssembly.Collections
2+
{
3+
public class Leaf
4+
{
5+
}
6+
}

TestAssembly/Collections/Tree.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace TestAssembly.Collections
2+
{
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
public class Tree : ICanAdd<Branch>, IEnumerable<Leaf>
8+
{
9+
readonly List<Branch> items = new List<Branch>();
10+
11+
public void Add(Branch item)
12+
{
13+
items.Add(item);
14+
}
15+
16+
public IEnumerator<Branch> GetEnumerator()
17+
{
18+
return items.GetEnumerator();
19+
}
20+
21+
IEnumerator IEnumerable.GetEnumerator()
22+
{
23+
return GetEnumerator();
24+
}
25+
26+
IEnumerator<Leaf> IEnumerable<Leaf>.GetEnumerator()
27+
{
28+
return items.SelectMany(i => i).GetEnumerator();
29+
}
30+
}
31+
}

TestAssembly/TestAssembly.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<Compile Include="ClassWithPrivateDefaultCtor.cs" />
4545
<Compile Include="ClassWithProtectedDefaultCtor.cs" />
4646
<Compile Include="ClassWithPublicDefaultCtor.cs" />
47+
<Compile Include="Collections\Branch.cs" />
48+
<Compile Include="Collections\Forest.cs" />
49+
<Compile Include="Collections\ICanAdd.cs" />
50+
<Compile Include="Collections\ICanRemove.cs" />
51+
<Compile Include="Collections\Leaf.cs" />
52+
<Compile Include="Collections\Tree.cs" />
4753
<Compile Include="Dtos\AnotherClass.cs" />
4854
<Compile Include="Dtos\BlahDto.cs" />
4955
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
collection,item,can add,can remove
2+
TestAssembly.Collections.Branch,TestAssembly.Collections.Leaf,False,False
3+
TestAssembly.Collections.Forest,TestAssembly.Collections.Tree,True,True
4+
TestAssembly.Collections.Tree,TestAssembly.Collections.Branch,True,False
5+
TestAssembly.Collections.Tree,TestAssembly.Collections.Leaf,False,False
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace TestStack.ConventionTests.Tests
2+
{
3+
using System.Linq;
4+
using ApprovalTests.Reporters;
5+
using NUnit.Framework;
6+
using TestAssembly.Collections;
7+
using TestStack.ConventionTests.ConventionData;
8+
using TestStack.ConventionTests.Tests.TestConventions;
9+
10+
[UseReporter(typeof(DiffReporter))]
11+
public class CsvReportTests
12+
{
13+
[Test]
14+
public void Can_run_convention_with_simple_reporter()
15+
{
16+
Convention.IsWithApprovedExeptions(new CollectionsRelationsConvention(), new Types("Entities")
17+
{
18+
TypesToVerify =
19+
typeof (Leaf).Assembly.GetExportedTypes()
20+
.Where(t => t.Namespace == typeof (Leaf).Namespace).ToArray()
21+
});
22+
}
23+
}
24+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace TestStack.ConventionTests.Tests.TestConventions
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using TestAssembly.Collections;
7+
using TestStack.ConventionTests.ConventionData;
8+
9+
public class CollectionsRelationsConvention : IConvention<Types>
10+
{
11+
public string ConventionTitle { get; private set; }
12+
13+
public void Execute(Types data, IConventionResult result)
14+
{
15+
ConventionTitle = "well, does the header apply here all across the board? How would that work for CSV?";
16+
var types = data.TypesToVerify;
17+
var collectionToItemLookup = from collection in types
18+
where collection.IsClass
19+
orderby collection.FullName
20+
from item in GetItemTypes(collection)
21+
select new
22+
{
23+
collection,
24+
item,
25+
can_add = typeof (ICanAdd<>).MakeGenericType(item).IsAssignableFrom(collection),
26+
can_remove = typeof (ICanRemove<>).MakeGenericType(item).IsAssignableFrom(collection)
27+
};
28+
29+
result.Is("Some title", collectionToItemLookup);
30+
}
31+
32+
IEnumerable<Type> GetItemTypes(Type type)
33+
{
34+
return from @interface in type.GetInterfaces()
35+
where @interface.IsGenericType
36+
where @interface.GetGenericTypeDefinition() == typeof (IEnumerable<>)
37+
let item = @interface.GetGenericArguments().Single()
38+
orderby item.FullName
39+
select item;
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)