public void IfResponseContainsRoundEntryWithPrepopulatedFormShouldSubmitForm() { const int initialEndurance = 3; const int newEndurance = 1; var initialEntry = CreateRoundEntry(initialEndurance); var newEntry = CreateRoundEntry(newEndurance); var mockEndpoint = new FakeEndpoint(CreateResponseWithEntry(newEntry)); var client = AtomClient.CreateWithChannel(mockEndpoint); var initialState = new ResolvingEncounter(CreateResponseWithEntry(initialEntry), ApplicationStateInfo.WithEndurance(initialEndurance)); initialState.NextState(client); var expectedContent = new StringContent("endurance=" + initialEndurance); expectedContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); var expectedRequest = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri("http://localhost:8081/encounters/1"), Content = expectedContent }; Assert.IsTrue(HttpRequestComparer.Instance.Equals(expectedRequest, mockEndpoint.ReceivedRequest)); }
public void IfResponseToSubmittingFormIsNotAtomEntryShouldReturnErrorState() { var entry = CreateRoundEntry(3); var stubEndpoint = new FakeEndpoint(CreateHtmlResponse()); var client = AtomClient.CreateWithChannel(stubEndpoint); var initialState = new ResolvingEncounter(CreateResponseWithEntry(entry), ApplicationStateInfo.WithEndurance(5)); var newState = initialState.NextState(client); Assert.IsInstanceOf(typeof(Error), newState); }
public void AfterSubmittingFormShouldReturnNewResolvingEncounterApplicationState() { var initialEntry = CreateRoundEntry(3); var newEntry = CreateRoundEntry(1); var stubEndpoint = new FakeEndpoint(CreateResponseWithEntry(newEntry)); var client = AtomClient.CreateWithChannel(stubEndpoint); var initialState = new ResolvingEncounter(CreateResponseWithEntry(initialEntry), ApplicationStateInfo.WithEndurance(3)); var newState = initialState.NextState(client); Assert.IsInstanceOf(typeof(ResolvingEncounter), newState); }
public void AfterSubmittingFormNewStateShouldContainRevisedEnduranceAsSpecifiedInResponse() { const int newEndurance = 3; var feed = CreateEncounterFeed(); var entry = CreateRoundEntry(newEndurance); var stubEndpoint = new FakeEndpoint(CreateResponseWithEntry(entry)); var client = AtomClient.CreateWithChannel(stubEndpoint); var initialState = new ResolvingEncounter(CreateResponseWithFeed(feed), ApplicationStateInfo.WithEndurance(5)); var newState = initialState.NextState(client); Assert.AreEqual(newEndurance, newState.ApplicationStateInfo.Endurance); }
public void IfAllExitsHaveBeenVisitedPreviouslyShouldRetraceStepsNorthIfNoOtherExits() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithNorthLink(NorthUri) .ToString(); var currentResponse = CreateResponse(entry); var mockEndpoint = new FakeEndpoint(new HttpResponseMessage()); var history = new[] {NorthUri, EastUri, WestUri, SouthUri}; var client = AtomClient.CreateWithChannel(mockEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5).GetBuilder().AddToHistory(history).Build()); state.NextState(client); Assert.AreEqual(new Uri(BaseUri, NorthUri), mockEndpoint.ReceivedRequest.RequestUri); Assert.AreEqual(HttpMethod.Get, mockEndpoint.ReceivedRequest.Method); }
public void ShouldRememberVisitedExits() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithNorthLink(NorthUri) .ToString(); var currentResponse = CreateResponse(entry); var stubEndpoint = new FakeEndpoint(new HttpResponseMessage()); var client = AtomClient.CreateWithChannel(stubEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5)); Assert.IsFalse(state.ApplicationStateInfo.History.Contains(NorthUri)); var nextState = state.NextState(client); Assert.IsTrue(nextState.ApplicationStateInfo.History.Contains(NorthUri)); }
public void ShouldPopulateNextStateWithNewResponse() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithNorthLink(NorthUri) .ToString(); var currentResponse = CreateResponse(entry); var newResponse = new HttpResponseMessage(); var stubEndpoint = new FakeEndpoint(newResponse); var client = AtomClient.CreateWithChannel(stubEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = state.NextState(client); Assert.AreEqual(newResponse, nextState.CurrentResponse); }
public void ShouldNotChoosePreviouslyChosenExitWhileThereAreOtherExits() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithNorthLink(NorthUri) .WithSouthLink(SouthUri) .WithEastLink(EastUri) .WithWestLink(WestUri) .ToString(); var currentResponse = CreateResponse(entry); var mockEndpoint = new FakeEndpoint(new HttpResponseMessage()); var history = new[] {NorthUri, EastUri}; var client = AtomClient.CreateWithChannel(mockEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5).GetBuilder().AddToHistory(history).Build()); state.NextState(client); Assert.AreEqual(new Uri(BaseUri, WestUri), mockEndpoint.ReceivedRequest.RequestUri); Assert.AreEqual(HttpMethod.Get, mockEndpoint.ReceivedRequest.Method); }
public void ShouldFollowExitToWestIfCannotExitNorthOrEast() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithSouthLink(SouthUri) .WithWestLink(WestUri) .ToString(); var currentResponse = CreateResponse(entry); var mockEndpoint = new FakeEndpoint(new HttpResponseMessage()); var client = AtomClient.CreateWithChannel(mockEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5)); state.NextState(client); Assert.AreEqual(new Uri(BaseUri, WestUri), mockEndpoint.ReceivedRequest.RequestUri); Assert.AreEqual(HttpMethod.Get, mockEndpoint.ReceivedRequest.Method); }
public void NextStateShouldReturnExploringApplicatonState() { var entry = new EntryBuilder() .WithBaseUri(BaseUri) .WithNorthLink(NorthUri) .ToString(); var currentResponse = CreateResponse(entry); var stubEndpoint = new FakeEndpoint(new HttpResponseMessage()); var client = AtomClient.CreateWithChannel(stubEndpoint); var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = state.NextState(client); Assert.IsInstanceOf(typeof(Exploring), nextState); Assert.AreNotEqual(state, nextState); }
public void ShouldFollowContinueLinkIfPresentInResponse() { const int endurance = 1; var entry = new EntryBuilder() .WithBaseUri(new Uri("http://localhost:8081/")) .WithCategory("round") .WithContinueLink(new Uri("/rooms/1", UriKind.Relative)) .WithForm(new FormWriter(Action, Method, new TextInput("endurance", endurance.ToString()))) .ToString(); var newEntry = CreateRoomEntry(); var mockEndpoint = new FakeEndpoint(CreateResponseWithEntry(newEntry)); var client = AtomClient.CreateWithChannel(mockEndpoint); var initialState = new ResolvingEncounter(CreateResponseWithEntry(entry), ApplicationStateInfo.WithEndurance(endurance)); initialState.NextState(client); Assert.AreEqual(new Uri("http://localhost:8081/rooms/1"), mockEndpoint.ReceivedRequest.RequestUri); Assert.AreEqual(HttpMethod.Get, mockEndpoint.ReceivedRequest.Method); }