-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6326b5d
commit 52db865
Showing
8 changed files
with
200 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Windows; | ||
using BrentEdwards.MVVM.Navigation; | ||
using BrentEdwards.MVVM.Messaging; | ||
using NSubstitute; | ||
|
||
namespace BrentEdwards.MVVM.Test.Navigation | ||
{ | ||
[TestClass] | ||
public class ViewControllerTests | ||
{ | ||
private IMessageBus _messageBus; | ||
private IViewFactory _viewFactory; | ||
private IViewPlacer _viewPlacer; | ||
private IViewAuthorizer _viewAuthorizer; | ||
|
||
private ViewController GetViewController(bool useAuthorizer) | ||
{ | ||
_messageBus = new MessageBus(); | ||
_viewFactory = Substitute.For<IViewFactory>(); | ||
_viewPlacer = Substitute.For<IViewPlacer>(); | ||
|
||
if (useAuthorizer) | ||
{ | ||
_viewAuthorizer = Substitute.For<IViewAuthorizer>(); | ||
} | ||
else | ||
{ | ||
_viewAuthorizer = null; | ||
} | ||
|
||
return new ViewController(_messageBus, _viewFactory, _viewPlacer, _viewAuthorizer); | ||
} | ||
|
||
[TestMethod] | ||
public void ShowView() | ||
{ | ||
var view = new FrameworkElement(); | ||
var viewController = GetViewController(false); | ||
|
||
var viewResult = new ViewResult(view); | ||
_viewFactory.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>()) | ||
.Returns(viewResult); | ||
|
||
var message = new ShowViewMessage(ViewTargets.DefaultView); | ||
_messageBus.Publish<ShowViewMessage>(message); | ||
|
||
_viewPlacer.Received().PlaceView(viewResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShowViewAuthorized() | ||
{ | ||
var view = new FrameworkElement(); | ||
var viewController = GetViewController(true); | ||
|
||
var viewResult = new ViewResult(view); | ||
_viewFactory.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>()) | ||
.Returns(viewResult); | ||
|
||
_viewAuthorizer.AuthorizeView(Arg.Any<ViewTargets>()) | ||
.Returns(true); | ||
|
||
var message = new ShowViewMessage(ViewTargets.DefaultView); | ||
_messageBus.Publish<ShowViewMessage>(message); | ||
|
||
_viewPlacer.Received().PlaceView(viewResult); | ||
} | ||
|
||
[TestMethod, ExpectedException(typeof(InvalidOperationException))] | ||
public void ShowViewNotAuthorized() | ||
{ | ||
var view = new FrameworkElement(); | ||
var viewController = GetViewController(true); | ||
|
||
var viewResult = new ViewResult(view); | ||
_viewFactory.Build(Arg.Any<ViewTargets>(), Arg.Any<Object>()) | ||
.Returns(viewResult); | ||
|
||
_viewAuthorizer.AuthorizeView(Arg.Any<ViewTargets>()) | ||
.Returns(false); | ||
|
||
var message = new ShowViewMessage(ViewTargets.DefaultView); | ||
_messageBus.Publish<ShowViewMessage>(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace BrentEdwards.MVVM.Test.Navigation | ||
{ | ||
[TestClass] | ||
public class ViewTargetsTests | ||
{ | ||
[TestMethod] | ||
public void Enumeration_Default() | ||
{ | ||
var enumeration = new ViewTargets(); | ||
|
||
Assert.AreEqual(0, (int)enumeration); | ||
} | ||
|
||
[TestMethod] | ||
public void ImplicitOperator_Enumeration() | ||
{ | ||
int viewTargetValue = ViewTargets.DefaultView; | ||
|
||
Assert.AreEqual(1, viewTargetValue); | ||
} | ||
|
||
[TestMethod] | ||
public void ImplicitOperator_ViewTargets() | ||
{ | ||
ViewTargets viewTarget = 1; | ||
|
||
Assert.AreEqual(ViewTargets.DefaultView, viewTarget); | ||
} | ||
|
||
[TestMethod] | ||
public void EqualsTest() | ||
{ | ||
Assert.AreEqual(ViewTargets.DefaultView, ViewTargets.DefaultView); | ||
} | ||
|
||
[TestMethod] | ||
public void ToStringTest() | ||
{ | ||
var viewTarget = ViewTargets.DefaultView; | ||
|
||
Assert.AreEqual("DefaultView", viewTarget.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ToString_PropertyDoesntExist() | ||
{ | ||
ViewTargets viewTarget = 0; | ||
|
||
Assert.AreEqual(string.Empty, viewTarget.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetHashCodeTest() | ||
{ | ||
var viewTarget = ViewTargets.DefaultView; | ||
|
||
Assert.AreEqual(((int)1).GetHashCode(), viewTarget.GetHashCode()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<TestSettings name="Local" id="82cfb174-9017-4eb7-8d31-d3d482263834" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> | ||
<Description>These are default test settings for a local test run.</Description> | ||
<Deployment enabled="false" /> | ||
<Execution> | ||
<TestTypeSpecific /> | ||
<AgentRule name="Execution Agents"> | ||
<TestTypeSpecific> | ||
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b"> | ||
<AssemblyResolution> | ||
<TestDirectory useLoadContext="true" /> | ||
</AssemblyResolution> | ||
</UnitTestRunConfig> | ||
</TestTypeSpecific> | ||
<AgentRule name="LocalMachineDefaultRole"> | ||
<DataCollectors> | ||
<DataCollector uri="datacollector://microsoft/CodeCoverage/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn, Microsoft.VisualStudio.QualityTools.Plugins.CodeCoverage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Code Coverage"> | ||
<Configuration> | ||
<CodeCoverage xmlns=""> | ||
<Regular> | ||
<CodeCoverageItem binaryFile="BrentEdwards.MVVM\bin\Debug\BrentEdwards.MVVM.dll" pdbFile="BrentEdwards.MVVM\bin\Debug\BrentEdwards.MVVM.pdb" instrumentInPlace="true" /> | ||
<CodeCoverageItem binaryFile="BrentEdwards.MVVM.Test\bin\Debug\BrentEdwards.MVVM.Test.dll" pdbFile="BrentEdwards.MVVM.Test\bin\Debug\BrentEdwards.MVVM.Test.pdb" instrumentInPlace="true" /> | ||
</Regular> | ||
</CodeCoverage> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</AgentRule> | ||
</Execution> | ||
</TestSettings> |