コード例 #1
0
        public void TestTransfrom()
        {
            LogicImpl logic = new LogicImpl();

            Moq.Mock <IStore <AppState> > store = new Moq.Mock <IStore <AppState> >();

            logic.OnTransform = (s, a) => Task.FromResult(a + "World");
            var result = ((ILogic <AppState, string>)logic).PreProcess(store.Object, "Hello");

            Assert.AreEqual("HelloWorld", result.Result.Action);
        }
コード例 #2
0
        public void TestValidationSuccess()
        {
            LogicImpl logic = new LogicImpl();

            Moq.Mock <IStore <AppState> > store = new Moq.Mock <IStore <AppState> >();
            store.Setup(s => s.Dispatch(It.IsAny <ValidationException>()));

            logic.OnValidation = (s, a, d) => Task.FromResult(ValidationResult.Success());
            var result = ((ILogic <AppState, string>)logic).PreProcess(store.Object, "Hello");

            Assert.AreEqual(true, result.Result.ContinueToNextStep);
            store.Verify(s => s.Dispatch(It.IsAny <ValidationException>()), Times.Never());
        }
コード例 #3
0
        public void TestValidationFailure()
        {
            LogicImpl logic = new LogicImpl();

            Moq.Mock <IStore <AppState> > store = new Moq.Mock <IStore <AppState> >();
            store.Setup(s => s.Dispatch(It.IsAny <ValidationException>()));

            logic.OnValidation = (s, a, d) => Task.FromResult(ValidationResult.Failure(new ValidationException("", new[] { new ValidationDetails("", "") })));
            var result = ((ILogic <AppState, string>)logic).PreProcess(store.Object, "Hello");

            Assert.AreEqual(false, result.Result.ContinueToNextStep);
            store.Verify(s => s.Dispatch(It.IsAny <ValidationException>()), Times.Once());
        }