Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit d538eb2

Browse files
authored
Merge pull request #110 from JacopoWolf/dev/tests
updated tests
2 parents 78c9522 + 0da9b7e commit d538eb2

4 files changed

Lines changed: 104 additions & 6 deletions

File tree

tests/StackInjector.TEST.BlackBox/Test.Exceptions.cs renamed to tests/StackInjector.TEST.BlackBox/Exceptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace StackInjector.TEST.BlackBox
1010

1111
#pragma warning disable IDE0051, IDE0044, CS0169, CS0649
1212

13-
internal class TestExceptions
13+
internal class Exceptions
1414
{
1515

1616
private class BaseNotAServiceThrower {[Served] private List<int> integers; }
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using StackInjector;
2+
using System;
3+
using NUnit.Framework;
4+
using StackInjector.Wrappers;
5+
using StackInjector.Attributes;
6+
using StackInjector.Settings;
7+
8+
namespace StackInjector.TEST.BlackBox.Features
9+
{
10+
#pragma warning disable CS0649
11+
12+
class InstantiationDiff
13+
{
14+
[Service]
15+
class WrapperBase
16+
{
17+
[Served]
18+
public readonly ServiceA serviceA;
19+
20+
public void Work()
21+
{
22+
this.serviceA.sharedCondition = true;
23+
}
24+
25+
}
26+
27+
[Service]
28+
class ServiceA : IDisposable
29+
{
30+
public bool sharedCondition;
31+
32+
public void Dispose()
33+
{
34+
Console.WriteLine("I've been disposed!");
35+
}
36+
37+
}
38+
39+
40+
[Test]
41+
public void SimpleCloneWithDispose ()
42+
{
43+
44+
var settings = StackWrapperSettings.Default
45+
.TrackInstantiationDiff();
46+
47+
IStackWrapper<WrapperBase> wrapperB;
48+
49+
using( var wrapperA = Injector.From<WrapperBase>(settings) )
50+
{
51+
wrapperA.Start(e => e.Work());
52+
wrapperB = wrapperA.CloneCore().ToWrapper<WrapperBase>();
53+
}
54+
55+
56+
Assert.Throws<NullReferenceException>( () => wrapperB.Entry.Work() );
57+
58+
}
59+
60+
[Test]
61+
public void SimpleClone ()
62+
{
63+
var settings = StackWrapperSettings.Default
64+
.TrackInstantiationDiff();
65+
66+
IStackWrapper<WrapperBase> wrapperB;
67+
68+
var wrapperA = Injector.From<WrapperBase>(settings);
69+
70+
wrapperA.Start(e => e.Work());
71+
wrapperB = wrapperA.CloneCore().ToWrapper<WrapperBase>();
72+
73+
74+
75+
Assert.DoesNotThrow( () => wrapperB.Entry.Work() );
76+
}
77+
78+
79+
80+
[Test]
81+
public void DeepCloneWithDispose ()
82+
{
83+
var settings = StackWrapperSettings.Default
84+
.TrackInstantiationDiff();
85+
86+
IStackWrapper<WrapperBase> wrapperB;
87+
88+
using( var wrapperA = Injector.From<WrapperBase>(settings) )
89+
{
90+
wrapperA.Start(e => e.Work());
91+
wrapperB = wrapperA.DeepCloneCore().ToWrapper<WrapperBase>();
92+
}
93+
94+
// wrapper B is a deep clone. Being different objects, disposing one won't interact with the other
95+
Assert.DoesNotThrow( () => wrapperB.Entry.Work() );
96+
}
97+
}
98+
}

tests/StackInjector.TEST.BlackBox/Test.Async.cs renamed to tests/StackInjector.TEST.BlackBox/UseCases/Async.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
using StackInjector.Settings;
99
using CTkn = System.Threading.CancellationToken;
1010

11-
namespace StackInjector.TEST.BlackBox
11+
namespace StackInjector.TEST.BlackBox.UseCases
1212
{
1313

1414
#pragma warning disable IDE0051, IDE0044, CS0169, CS0649
1515

16-
internal class TestAsync
16+
internal class Async
1717
{
1818
//todo test is broken. Rewrite.
1919
/*x
@@ -68,7 +68,7 @@ public void AsyncConcurrentExecution ()
6868
);
6969

7070
// test callback
71-
wrapper.OnElaborated += ( i ) => Console.Write(i);
71+
wrapper.OnElaborated += ( i ) => Console.Write(i);
7272

7373
// test submit
7474
wrapper.Submit(420);

tests/StackInjector.TEST.BlackBox/Test.Sync.cs renamed to tests/StackInjector.TEST.BlackBox/UseCases/Sync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
using StackInjector.Attributes;
55
using StackInjector.Settings;
66

7-
namespace StackInjector.TEST.BlackBox
7+
namespace StackInjector.TEST.BlackBox.UseCases
88
{
99

1010
#pragma warning disable IDE0051, IDE0044, CS0169, CS0649
1111

12-
internal class TestSync
12+
internal class Sync
1313
{
1414

1515
[Test]

0 commit comments

Comments
 (0)