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 ErrorStateForNonAtomMediaTypeShouldBeInitializedWithCurrentApplicationStateInfo() { var applicationStateInfo = ApplicationStateInfo.WithEndurance(5).GetBuilder().AddToHistory(new Uri("http://localhost/rooms1")).Build(); var currentResponse = CreateHtmlResponse(); var initialState = new ResolvingEncounter(currentResponse, applicationStateInfo); var nextState = initialState.NextState(new HttpClient()); Assert.AreEqual(applicationStateInfo, nextState.ApplicationStateInfo); }
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 WhenEnduranceIsZeroShouldReturnDefeatedApplicationState() { const int endurance = 0; var entry = CreateRoundEntry(endurance); var initialState = new ResolvingEncounter(CreateResponseWithEntry(entry), ApplicationStateInfo.WithEndurance(endurance)); var newState = initialState.NextState(new HttpClient()); Assert.IsInstanceOf(typeof(Defeated), newState); }
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); }
public void ErrorStateForNonAtomMediaTypeShouldBeInitializedWithCurrentResponse() { var currentResponse = CreateHtmlResponse(); var initialState = new ResolvingEncounter(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = initialState.NextState(new HttpClient()); Assert.AreEqual(currentResponse, nextState.CurrentResponse); }
public void ShouldReturnExploringApplicationStateIfCurrentResponseContainsRoomEntry() { var entry = new EntryBuilder().WithCategory("room").ToString(); var initialState = new ResolvingEncounter(CreateResponseWithEntry(entry), ApplicationStateInfo.WithEndurance(5)); var nextState = initialState.NextState(new HttpClient()); Assert.IsInstanceOf(typeof (Exploring), nextState); }
public void ShouldReturnErrorApplicationStateIfCurrentResponseContainsUncategorizedFeed() { var feed = new FeedBuilder().ToString(); var currentResponse = CreateResponseWithFeed(feed); var initialState = new ResolvingEncounter(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = initialState.NextState(new HttpClient()); Assert.IsInstanceOf(typeof (Error), nextState); }
public void ShouldReturnErrorApplicationStateIfCurrentResponseContainsNonAtomMediaType() { var currentResponse = CreateHtmlResponse(); var initialState = new ResolvingEncounter(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = initialState.NextState(new HttpClient()); Assert.IsInstanceOf(typeof (Error), nextState); }
public void ShouldBeNonTerminalState() { var state = new ResolvingEncounter(new HttpResponseMessage(), ApplicationStateInfo.WithEndurance(5)); Assert.IsFalse(state.IsTerminalState); }
public void ErrorStateForUncategorizedFeedShouldBeInitializedWithCurrentResponse() { var feed = new FeedBuilder().ToString(); var currentResponse = CreateResponseWithFeed(feed); var initialState = new ResolvingEncounter(currentResponse, ApplicationStateInfo.WithEndurance(5)); var nextState = initialState.NextState(new HttpClient()); Assert.AreEqual(currentResponse, nextState.CurrentResponse); }