Skip to content

Commit ce2bb13

Browse files
committed
Removed ItemsSource adapter/behaviour for regions
Added tests for regions Fixes
1 parent 7c5ab1d commit ce2bb13

File tree

58 files changed

+6660
-536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6660
-536
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Prism.Wpf.Tests
9+
{
10+
public class CollectionChangedTracker
11+
{
12+
private readonly List<NotifyCollectionChangedEventArgs> eventList = new List<NotifyCollectionChangedEventArgs>();
13+
14+
public CollectionChangedTracker(INotifyCollectionChanged collection)
15+
{
16+
collection.CollectionChanged += OnCollectionChanged;
17+
}
18+
19+
public IEnumerable<NotifyCollectionChangedAction> ActionsFired { get { return this.eventList.Select(e => e.Action); } }
20+
public IEnumerable<NotifyCollectionChangedEventArgs> NotifyEvents { get { return this.eventList; } }
21+
22+
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
23+
{
24+
this.eventList.Add(e);
25+
}
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace Prism.Wpf.Tests
5+
{
6+
public static class ExceptionAssert
7+
{
8+
public static void Throws<TException>(Action action)
9+
where TException : Exception
10+
{
11+
Throws(typeof(TException), action);
12+
}
13+
14+
public static void Throws(Type expectedExceptionType, Action action)
15+
{
16+
try
17+
{
18+
action();
19+
}
20+
catch (Exception ex)
21+
{
22+
Assert.IsInstanceOfType(ex, expectedExceptionType);
23+
return;
24+
}
25+
26+
Assert.Fail("No exception thrown. Expected exception type of {0}.", expectedExceptionType.Name);
27+
}
28+
}
29+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Threading;
3+
using Prism.Modularity;
4+
5+
namespace Prism.Avalonia.Tests.Mocks
6+
{
7+
public class MockAsyncModuleTypeLoader : IModuleTypeLoader
8+
{
9+
private ManualResetEvent callbackEvent;
10+
11+
public MockAsyncModuleTypeLoader(ManualResetEvent callbackEvent)
12+
{
13+
this.callbackEvent = callbackEvent;
14+
}
15+
16+
public int SleepTimeOut { get; set; }
17+
18+
public Exception CallbackArgumentError { get; set; }
19+
20+
public bool CanLoadModuleType(ModuleInfo moduleInfo)
21+
{
22+
return true;
23+
}
24+
25+
public void LoadModuleType(ModuleInfo moduleInfo)
26+
{
27+
Thread retrieverThread = new Thread(() =>
28+
{
29+
Thread.Sleep(SleepTimeOut);
30+
31+
this.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(moduleInfo, CallbackArgumentError));
32+
callbackEvent.Set();
33+
});
34+
retrieverThread.Start();
35+
}
36+
37+
38+
public event EventHandler<ModuleDownloadProgressChangedEventArgs> ModuleDownloadProgressChanged;
39+
40+
private void RaiseLoadModuleProgressChanged(ModuleDownloadProgressChangedEventArgs e)
41+
{
42+
if (this.ModuleDownloadProgressChanged != null)
43+
{
44+
this.ModuleDownloadProgressChanged(this, e);
45+
}
46+
}
47+
48+
public event EventHandler<LoadModuleCompletedEventArgs> LoadModuleCompleted;
49+
50+
private void RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e)
51+
{
52+
if (this.LoadModuleCompleted != null)
53+
{
54+
this.LoadModuleCompleted(this, e);
55+
}
56+
}
57+
}
58+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Avalonia.Controls;
2+
3+
namespace Prism.Avalonia.Tests.Mocks
4+
{
5+
internal class MockClickableObject : Button
6+
{
7+
public void RaiseClick()
8+
{
9+
OnClick();
10+
}
11+
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Windows.Input;
3+
4+
namespace Prism.Avalonia.Tests.Mocks
5+
{
6+
internal class MockCommand : ICommand
7+
{
8+
public bool ExecuteCalled { get; set; }
9+
public bool CanExecuteReturnValue = true;
10+
public object ExecuteParameter;
11+
public object CanExecuteParameter;
12+
public int CanExecuteTimesCalled;
13+
14+
public event EventHandler CanExecuteChanged;
15+
16+
public void Execute(object parameter)
17+
{
18+
ExecuteCalled = true;
19+
ExecuteParameter = parameter;
20+
}
21+
22+
public bool CanExecute(object parameter)
23+
{
24+
CanExecuteTimesCalled++;
25+
CanExecuteParameter = parameter;
26+
return CanExecuteReturnValue;
27+
}
28+
29+
public void RaiseCanExecuteChanged()
30+
{
31+
if (this.CanExecuteChanged != null)
32+
this.CanExecuteChanged(this, EventArgs.Empty);
33+
}
34+
}
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Prism.Events;
3+
4+
namespace Prism.Avalonia.Tests.Mocks
5+
{
6+
class MockDelegateReference : IDelegateReference
7+
{
8+
public Delegate Target { get; set; }
9+
10+
public MockDelegateReference()
11+
{
12+
13+
}
14+
15+
public MockDelegateReference(Delegate target)
16+
{
17+
Target = target;
18+
}
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
using Avalonia;
4+
5+
namespace Prism.Avalonia.Tests.Mocks
6+
{
7+
public class MockDependencyObject : Visual
8+
{
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Interactivity;
4+
5+
namespace Prism.Avalonia.Tests.Mocks
6+
{
7+
public class MockFrameworkElement : Control
8+
{
9+
public void RaiseLoaded()
10+
{
11+
RaiseLoaded();
12+
}
13+
14+
public void RaiseUnloaded()
15+
{
16+
RaiseUnloaded();
17+
}
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Avalonia;
2+
using Prism.Regions;
3+
using Prism.Regions.Behaviors;
4+
5+
namespace Prism.Avalonia.Tests.Mocks
6+
{
7+
public class MockHostAwareRegionBehavior : IHostAwareRegionBehavior
8+
{
9+
public IRegion Region { get; set; }
10+
11+
public void Attach()
12+
{
13+
14+
}
15+
16+
public Visual HostControl { get; set; }
17+
}
18+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using System;
2+
using System.ComponentModel;
3+
using Prism.Regions;
4+
5+
namespace Prism.Avalonia.Tests.Mocks
6+
{
7+
class MockPresentationRegion : IRegion
8+
{
9+
public MockViewsCollection MockViews = new MockViewsCollection();
10+
public MockViewsCollection MockActiveViews = new MockViewsCollection();
11+
12+
public MockPresentationRegion()
13+
{
14+
Behaviors = new MockRegionBehaviorCollection();
15+
}
16+
public IRegionManager Add(object view)
17+
{
18+
MockViews.Items.Add(view);
19+
20+
return null;
21+
}
22+
23+
public void Remove(object view)
24+
{
25+
MockViews.Items.Remove(view);
26+
MockActiveViews.Items.Remove(view);
27+
}
28+
29+
public void Activate(object view)
30+
{
31+
MockActiveViews.Items.Add(view);
32+
}
33+
34+
public IRegionManager Add(object view, string viewName)
35+
{
36+
throw new NotImplementedException();
37+
}
38+
39+
public IRegionManager Add(object view, string viewName, bool createRegionManagerScope)
40+
{
41+
throw new NotImplementedException();
42+
}
43+
44+
public object GetView(string viewName)
45+
{
46+
throw new NotImplementedException();
47+
}
48+
49+
public IRegionManager RegionManager { get; set; }
50+
51+
public IRegionBehaviorCollection Behaviors { get; set; }
52+
53+
public IViewsCollection Views
54+
{
55+
get { return MockViews; }
56+
}
57+
58+
public IViewsCollection ActiveViews
59+
{
60+
get { return MockActiveViews; }
61+
}
62+
63+
public void Deactivate(object view)
64+
{
65+
MockActiveViews.Items.Remove(view);
66+
}
67+
68+
private object context;
69+
public object Context
70+
{
71+
get { return context; }
72+
set
73+
{
74+
context = value;
75+
OnPropertyChange("Context");
76+
}
77+
}
78+
79+
public NavigationParameters NavigationParameters
80+
{
81+
get { throw new System.NotImplementedException(); }
82+
set { throw new System.NotImplementedException(); }
83+
}
84+
85+
private string name;
86+
public string Name
87+
{
88+
get { return this.name; }
89+
set
90+
{
91+
this.name = value;
92+
this.OnPropertyChange("Name");
93+
}
94+
}
95+
96+
public event PropertyChangedEventHandler PropertyChanged;
97+
98+
public void OnPropertyChange(string propertyName)
99+
{
100+
if (PropertyChanged != null)
101+
{
102+
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
103+
}
104+
}
105+
106+
public bool Navigate(Uri source)
107+
{
108+
throw new NotImplementedException();
109+
}
110+
111+
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
112+
{
113+
throw new NotImplementedException();
114+
}
115+
116+
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback, NavigationParameters navigationParameters)
117+
{
118+
throw new NotImplementedException();
119+
}
120+
121+
public void RemoveAll()
122+
{
123+
throw new NotImplementedException();
124+
}
125+
126+
public IRegionNavigationService NavigationService
127+
{
128+
get { throw new NotImplementedException(); }
129+
set { throw new System.NotImplementedException(); }
130+
}
131+
132+
133+
public Comparison<object> SortComparison
134+
{
135+
get
136+
{
137+
throw new NotImplementedException();
138+
}
139+
set
140+
{
141+
throw new NotImplementedException();
142+
}
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)