-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/idotta/SimpleRouter
- Loading branch information
Showing
5 changed files
with
157 additions
and
3 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,83 @@ | ||
using Avalonia.Controls; | ||
using Moq; | ||
using SimpleRouter.Avalonia; | ||
|
||
namespace SimpleRouter.Tests; | ||
|
||
public class AvaloniaRouteViewHostTests | ||
{ | ||
[Fact] | ||
public void NavigateToRoute_RouteIsNull_SetsDefaultContent() | ||
{ | ||
// Arrange | ||
var routeViewHost = new RouteViewHost(); | ||
var defaultContent = new object(); | ||
routeViewHost.DefaultContent = defaultContent; | ||
var router = new Mock<IRouter>(); | ||
router.Setup(r => r.Current).Returns<IRoute?>(null); | ||
Check warning on line 17 in src/SimpleRouter.Tests/AvaloniaRouteViewHostTests.cs GitHub Actions / build
|
||
|
||
// Act | ||
routeViewHost.Router = router.Object; | ||
|
||
// Assert | ||
Assert.Equal(defaultContent, routeViewHost.Content); | ||
} | ||
|
||
[Fact] | ||
public void NavigateToRoute_ViewLocatorIsNull_SetsRouteAsContent() | ||
{ | ||
// Arrange | ||
var routeViewHost = new RouteViewHost(); | ||
var route = new Mock<IRoute>().Object; | ||
var router = new Mock<IRouter>(); | ||
router.Setup(r => r.Current).Returns(route); | ||
|
||
// Act | ||
routeViewHost.Router = router.Object; | ||
|
||
// Assert | ||
Assert.Equal(route, routeViewHost.Content); | ||
} | ||
|
||
[Fact] | ||
public void NavigateToRoute_ViewLocatorBuildReturnsNull_SetsDefaultContent() | ||
{ | ||
// Arrange | ||
var routeViewHost = new RouteViewHost(); | ||
var route = new Mock<IRoute>().Object; | ||
var viewLocator = new Mock<ViewLocatorBase>(); | ||
var defaultContent = new object(); | ||
var router = new Mock<IRouter>(); | ||
router.Setup(r => r.Current).Returns(route); | ||
routeViewHost.ViewLocator = viewLocator.Object; | ||
viewLocator.Setup(v => v.Build(route)).Returns<Control?>(null); | ||
Check warning on line 53 in src/SimpleRouter.Tests/AvaloniaRouteViewHostTests.cs GitHub Actions / build
|
||
routeViewHost.DefaultContent = defaultContent; | ||
|
||
// Act | ||
routeViewHost.Router = router.Object; | ||
|
||
// Assert | ||
Assert.Equal(defaultContent, routeViewHost.Content); | ||
} | ||
|
||
[Fact] | ||
public void NavigateToRoute_ViewLocatorBuildReturnsView_SetsViewAsContent() | ||
{ | ||
// Arrange | ||
var routeViewHost = new RouteViewHost(); | ||
var route = new Mock<IRoute>().Object; | ||
var view = new Mock<Control>().Object; | ||
var viewLocator = new Mock<ViewLocatorBase>(); | ||
routeViewHost.ViewLocator = viewLocator.Object; | ||
viewLocator.Setup(v => v.Build(route)).Returns(view); | ||
var router = new Mock<IRouter>(); | ||
router.Setup(r => r.Current).Returns(route); | ||
|
||
// Act | ||
routeViewHost.Router = router.Object; | ||
|
||
// Assert | ||
Assert.Equal(view, routeViewHost.Content); | ||
Assert.Equal(route, view.DataContext); | ||
} | ||
} |
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,70 @@ | ||
using Avalonia.Controls; | ||
using Moq; | ||
using SimpleRouter.Avalonia; | ||
|
||
namespace SimpleRouter.Tests; | ||
|
||
public class AvaloniaViewLocatorTests | ||
{ | ||
[Fact] | ||
public void Build_WithNullParameter_ReturnsDefaultContent() | ||
{ | ||
// Arrange | ||
var viewLocator = new Mock<ViewLocatorBase>() { CallBase = true }; | ||
var defaultContent = new Control(); | ||
viewLocator.Object.DefaultContent = defaultContent; | ||
|
||
// Act | ||
var result = viewLocator.Object.Build(null); | ||
|
||
// Assert | ||
Assert.Equal(defaultContent, result); | ||
} | ||
|
||
[Fact] | ||
public void Build_WithNonNullParameter_ResolvesControl() | ||
{ | ||
// Arrange | ||
var viewLocator = new Mock<ViewLocatorBase>() { CallBase = true }; | ||
var route = new Mock<IRoute>(); | ||
var resolvedControl = new Control(); | ||
viewLocator.Object.DefaultContent = new Control(); | ||
viewLocator.Setup(x => x.ResolveControl(route.Object)).Returns(resolvedControl); | ||
|
||
// Act | ||
var result = viewLocator.Object.Build(route.Object); | ||
|
||
// Assert | ||
Assert.Equal(resolvedControl, result); | ||
} | ||
|
||
[Fact] | ||
public void Match_WithDataOfTypeIRoute_ReturnsTrue() | ||
{ | ||
// Arrange | ||
var viewLocator = new Mock<ViewLocatorBase>() { CallBase = true }.Object; | ||
var data = new Mock<IRoute>().Object; | ||
|
||
// Act | ||
var result = viewLocator.Match(data); | ||
|
||
// Assert | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void Match_WithDataNotOfTypeIRoute_ReturnsFalse() | ||
{ | ||
// Arrange | ||
var viewLocator = new Mock<ViewLocatorBase>() { CallBase = true }.Object; | ||
var data = new object(); | ||
|
||
// Act | ||
var result = viewLocator.Match(data); | ||
|
||
// Assert | ||
Assert.False(result); | ||
} | ||
|
||
|
||
} |
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