-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathConductorWithCollectionOneActiveTests.cs
More file actions
154 lines (137 loc) · 5.65 KB
/
ConductorWithCollectionOneActiveTests.cs
File metadata and controls
154 lines (137 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace Caliburn.Micro.Core.Tests
{
public class ConductorWithCollectionOneActiveTests
{
private class StateScreen : Screen
{
public bool IsClosed { get; private set; }
public bool IsClosable { get; set; }
public override Task<bool> CanCloseAsync(CancellationToken cancellationToken)
{
return Task.FromResult(IsClosable);
}
protected override async Task OnDeactivateAsync(bool close, CancellationToken cancellationToken)
{
await base.OnDeactivateAsync(close, cancellationToken);
IsClosed = close;
}
}
[Fact]
public void AddedItemAppearsInChildren()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
Assert.Contains(conducted, conductor.GetChildren());
}
[Fact]
public async Task CanCloseIsTrueWhenItemsAreClosable()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new StateScreen
{
IsClosable = true
};
conductor.Items.Add(conducted);
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
var canClose = await conductor.CanCloseAsync(CancellationToken.None);
Assert.True(canClose);
Assert.False(conducted.IsClosed);
}
[Fact(Skip = "Investigating close issue. http://caliburnmicro.codeplex.com/discussions/275824")]
public async Task CanCloseIsTrueWhenItemsAreNotClosableAndCloseStrategyCloses()
{
var conductor = new Conductor<IScreen>.Collection.OneActive
{
CloseStrategy = new DefaultCloseStrategy<IScreen>(true)
};
var conducted = new StateScreen
{
IsClosable = true
};
conductor.Items.Add(conducted);
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
var canClose = await conductor.CanCloseAsync(CancellationToken.None);
Assert.True(canClose);
Assert.True(conducted.IsClosed);
}
[Fact]
public async Task ChildrenAreActivatedIfConductorIsActive()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
await conductor.ActivateItemAsync(conducted);
Assert.True(conducted.IsActive);
Assert.Equal(conducted, conductor.ActiveItem);
}
[Fact(Skip = "ActiveItem currently set regardless of IsActive value. See http://caliburnmicro.codeplex.com/discussions/276375")]
public async Task ChildrenAreNotActivatedIfConductorIsNotActive()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
await ((IActivate)conductor).ActivateAsync(CancellationToken.None);
Assert.False(conducted.IsActive);
Assert.NotEqual(conducted, conductor.ActiveItem);
}
[Fact(Skip = "Behavior currently allowed; under investigation. See http://caliburnmicro.codeplex.com/discussions/276373")]
public void ConductorCannotConductSelf()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
Assert.Throws<InvalidOperationException>(() => conductor.Items.Add(conductor));
}
[Fact]
public void ParentItemIsSetOnAddedConductedItem()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
Assert.Equal(conductor, conducted.Parent);
}
[Fact]
public void ParentItemIsSetOnReplacedConductedItem()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var originalConducted = new Screen();
conductor.Items.Add(originalConducted);
var newConducted = new Screen();
conductor.Items[0] = newConducted;
Assert.Equal(conductor, newConducted.Parent);
}
[Fact]
public void ParentItemIsUnsetOnClear()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
conductor.Items.Clear();
Assert.NotEqual(conductor, conducted.Parent);
}
[Fact]
public void ParentItemIsUnsetOnRemovedConductedItem()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
conductor.Items.RemoveAt(0);
Assert.NotEqual(conductor, conducted.Parent);
}
[Fact]
public void ParentItemIsUnsetOnReplaceConductedItem()
{
var conductor = new Conductor<IScreen>.Collection.OneActive();
var conducted = new Screen();
conductor.Items.Add(conducted);
var conducted2 = new Screen();
conductor.Items[0] = conducted2;
Assert.NotEqual(conductor, conducted.Parent);
Assert.Equal(conductor, conducted2.Parent);
}
}
}