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 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 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 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 IfGoalAchievedShouldTransitionIntoGoalAchievedState()
        {
            var entry = new EntryBuilder()
                .WithBaseUri(BaseUri)
                .WithTitle("Exit")
                .ToString();

            var currentResponse = CreateResponse(entry);

            var state = new Exploring(currentResponse, ApplicationStateInfo.WithEndurance(5));
            var nextState = state.NextState(new HttpClient());

            Assert.IsInstanceOf(typeof (GoalAchieved), 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);
        }
        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);
        }