Beispiel #1
0
        public IActionResult Back()
        {
            if (!CanGoBack)
            {
                return(Ok(StepTransitionResult.Failure("This is the first step")));
            }

            _currentIndex--;
            return(Ok(StepTransitionResult.Success()));
        }
        public void Next_DoesNotGoToNextStep_IfStepReturnsFailedTransition()
        {
            _step1Mock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Failure("test"));

            Node node = new Node();

            _session.Next(node);

            _session.CurrentStep.Should().BeSameAs(_step1Mock.Object, "Should be still on first step.");
        }
        public StepTransitionResult Next(Node node)
        {
            // validates data, may do something more and returns transition result
            if (string.IsNullOrEmpty(node.IpOrHostname))
            {
                return(StepTransitionResult.Failure("Node address has to be specified."));
            }

            node.IpOrHostname = NormalizeIpOrHostname(node.IpOrHostname);

            return(StepTransitionResult.Success());
        }
        public void Next_ReturnsStepTransitionResult()
        {
            _step1Mock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Failure("test"));

            Node node = new Node();
            StepTransitionResult result = _session.Next(node);

            result.Should().BeEquivalentTo(new
            {
                CanTransition = false,
                ErrorMessage  = "test"
            });
        }
Beispiel #5
0
        public void Previous_ReturnsTransitionFromSession()
        {
            _sessionMock.Setup(x => x.Back()).Returns(StepTransitionResult.Failure("test"));

            var actionResult = _controller.Back();

            actionResult.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeOfType <StepTransitionResult>()
            .Which.Should().BeEquivalentTo(new StepTransitionResult
            {
                CanTransition = false,
                ErrorMessage  = "test"
            });
        }
Beispiel #6
0
        public void Next_ReturnsTransitionFromSession()
        {
            _sessionMock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Failure("test"));

            Node node         = new Node();
            var  actionResult = _controller.Next(node);

            actionResult.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeOfType <StepTransitionResult>()
            .Which.Should().BeEquivalentTo(new StepTransitionResult
            {
                CanTransition = false,
                ErrorMessage  = "test"
            });
        }
Beispiel #7
0
        public async Task Next_ReturnsSessionResponse()
        {
            _sessionMock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Failure("test error"));
            Node node = new Node {
                IpOrHostname = "test"
            };

            HttpResponseMessage response = await HttpClient.PostAsync("/wizard/next", new ObjectContent <Node>(node, new JsonMediaTypeFormatter()));

            response.EnsureSuccessStatusCode();

            var result = JsonConvert.DeserializeObject <StepTransitionResult>(await response.Content.ReadAsStringAsync());

            result.Should().BeEquivalentTo(new StepTransitionResult
            {
                CanTransition = false,
                ErrorMessage  = "test error"
            });
        }
Beispiel #8
0
        public IActionResult Next(Node node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (!CanGoForward)
            {
                return(Ok(StepTransitionResult.Failure("This is the last step")));
            }

            StepTransitionResult result = _steps[_currentIndex].Next(node);

            if (result.CanTransition)
            {
                _currentIndex++;
            }

            return(Ok(result));
        }