public void AddMiddlewareTest() { // - Arrange var screenRegistry = new ScreenRegistry(); var middlewareStub = new Mock <INavigationMiddleware>().Object; // - Act screenRegistry.AddMiddleware(middlewareStub); // - Assert CollectionAssert.Contains(screenRegistry.Middlewares, middlewareStub); }
public void MiddlewareInvokeOrderTest() { // - Arrange var invokeCounter = 0; var firstMiddlewareBeforeIndex = -1; var firstMiddlewareAfterIndex = -1; var secondMiddlewareBeforeIndex = -1; var secondMiddlewareAfterIndex = -1; var firstMiddlewareMock = new Mock <INavigationMiddleware>(); firstMiddlewareMock .Setup(it => it.BeforeApply( It.IsAny <Screen>(), ref It.Ref <INavCommand> .IsAny)) .Callback(() => firstMiddlewareBeforeIndex = invokeCounter++); firstMiddlewareMock .Setup(it => it.AfterApply( It.IsAny <Screen>(), It.IsAny <INavCommand>())) .Callback(() => firstMiddlewareAfterIndex = invokeCounter++); var secondMiddlewareMock = new Mock <INavigationMiddleware>(); secondMiddlewareMock .Setup(it => it.BeforeApply( It.IsAny <Screen>(), ref It.Ref <INavCommand> .IsAny)) .Callback(() => secondMiddlewareBeforeIndex = invokeCounter++); secondMiddlewareMock .Setup(it => it.AfterApply( It.IsAny <Screen>(), It.IsAny <INavCommand>())) .Callback(() => secondMiddlewareAfterIndex = invokeCounter++); var registry = new ScreenRegistry(); registry.AddMiddleware(firstMiddlewareMock.Object); registry.AddMiddleware(secondMiddlewareMock.Object); var navigatorStub = new Mock <Navigator>().Object; var commandMock = new Mock <INavCommand>(); var commands = new[] { commandMock.Object }; var manager = new NavigationManager(registry); manager.SetNavigator(navigatorStub); // - Act manager.SendCommands(commands); // - Assert Assert.IsFalse(manager.HasPendingCommands); Assert.AreEqual(0, firstMiddlewareBeforeIndex); firstMiddlewareMock.Verify( it => it.BeforeApply( It.IsAny <Screen>(), ref It.Ref <INavCommand> .IsAny), Times.Once ); Assert.AreEqual(1, secondMiddlewareBeforeIndex); secondMiddlewareMock.Verify( it => it.BeforeApply( It.IsAny <Screen>(), ref It.Ref <INavCommand> .IsAny), Times.Once ); Assert.AreEqual(2, firstMiddlewareAfterIndex); firstMiddlewareMock.Verify( it => it.AfterApply( It.IsAny <Screen>(), It.IsAny <INavCommand>()), Times.Once ); Assert.AreEqual(3, secondMiddlewareAfterIndex); secondMiddlewareMock.Verify( it => it.AfterApply( It.IsAny <Screen>(), It.IsAny <INavCommand>()), Times.Once ); }