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 IActionResult Back() { if (!CanGoBack) { return(Ok(StepTransitionResult.Failure("This is the first step"))); } _currentIndex--; return(Ok(StepTransitionResult.Success())); }
public void DefineNodeWizardStep_WithValidAddress_AllowsTransition() { DefineNodeWizardStep step = new DefineNodeWizardStep(); Node node = new Node { IpOrHostname = "address" }; StepTransitionResult result = step.Next(node); result.CanTransition.Should().BeTrue("Transition should be allowed."); }
public void Next_DoesNotAllowToGoForwardFromLastStep() { Node node = new Node(); _session.Next(node); _session.Next(node); StepTransitionResult result = _session.Next(node); result.CanTransition.Should().BeFalse("Can't go forward from last 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" }); }
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" }); }
public async Task WalkThroughWizard_WithValidNode_AllowsNextOnFirstStep() { Node node = new Node() { IpOrHostname = "1.2.3.4", PollingMethod = "ICMP" }; // first step HttpWebResponse response = Post("/wizard/next", JsonConvert.SerializeObject(node)); string responseData = await GetResponseData(response); StepTransitionResult transitionResult = JsonConvert.DeserializeObject <StepTransitionResult>(responseData); transitionResult.CanTransition.Should().BeTrue("First step should allow Next() with valid node."); }
public void DefineNodeWizardStep_WithInvalidAddress_BlocksTransition() { DefineNodeWizardStep step = new DefineNodeWizardStep(); Node node = new Node { IpOrHostname = "" }; StepTransitionResult result = step.Next(node); result.Should().BeEquivalentTo(new StepTransitionResult { CanTransition = false, ErrorMessage = "Node address has to be specified." }); }
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" }); }
public async Task WalkThroughWizard_WithInvalidNode_DoesNodeAllowNextOnFirstStep() { Node node = new Node() { IpOrHostname = "", PollingMethod = "ICMP" }; // first step HttpWebResponse response = Post("/wizard/next", JsonConvert.SerializeObject(node)); string responseData = await GetResponseData(response); StepTransitionResult transitionResult = JsonConvert.DeserializeObject <StepTransitionResult>(responseData); transitionResult.Should().BeEquivalentTo(new StepTransitionResult { CanTransition = false, ErrorMessage = "Node address has to be specified." }); }
public WizardSessionTest() { _step1Mock = new Mock <IWizardStep>(); _step1Mock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Success()); _step2Mock = new Mock <IWizardStep>(); _step2Mock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Success()); var step3Mock = new Mock <IWizardStep>(); step3Mock.Setup(x => x.Next(It.IsAny <Node>())).Returns(StepTransitionResult.Success()); _stepsProviderMock = new Mock <IWizardStepsProvider>(); _stepsProviderMock.Setup(x => x.GetWizardSteps()) .Returns(new[] { _step1Mock.Object, _step2Mock.Object, step3Mock.Object }); _session = new WizardSession(_stepsProviderMock.Object); // Session is using static fields to keep state for purpose of this example so we need to clear it. // Production code would use different way of keeping the state like real Session, special token etc. _session.Cancel(); }
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" }); }
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)); }
public async Task WalkThroughWizard_WithValidNode_DoesNotAllowNextOnLastStep() { Node node = new Node() { IpOrHostname = "1.2.3.4", PollingMethod = "ICMP" }; // first step Post("/wizard/next", JsonConvert.SerializeObject(node)); // second step - the last HttpWebResponse response = Post("/wizard/next", JsonConvert.SerializeObject(node)); string responseData = await GetResponseData(response); StepTransitionResult transitionResult = JsonConvert.DeserializeObject <StepTransitionResult>(responseData); transitionResult.Should().BeEquivalentTo(new StepTransitionResult { CanTransition = false, ErrorMessage = "This is the last step" }); }
public StepTransitionResult Next(Node node) { return(StepTransitionResult.Success()); }
public void Back_DoesNotAllowToGoBackFromFirstStep() { StepTransitionResult result = _session.Back(); result.CanTransition.Should().BeFalse("Can't go back from first step."); }