public void ResolvingEncounterStateIsInitializedWithCurrentResponse()
        {
            var feed = new FeedBuilder().WithCategory("encounter").ToString();

            var currentResponse = CreateCurrentResponse(feed);

            var initialState = new Exploring(currentResponse, ApplicationStateInfo);
            var nextState = initialState.NextState(new HttpClient());

            Assert.AreEqual(currentResponse, nextState.CurrentResponse);
        }
        public void ShouldReturnErrorApplicationStateIfCurrentResponseContainsUncategorizedFeed()
        {
            var feed = new FeedBuilder().ToString();

            var currentResponse = CreateCurrentResponse(feed);

            var initialState = new Exploring(currentResponse, ApplicationStateInfo);
            var nextState = initialState.NextState(new HttpClient());

            Assert.IsInstanceOf(typeof (Error), nextState);
        }
        public void ErrorStateIsInitializedWithCurrentHistory()
        {
            var feed = new FeedBuilder().ToString();

            var currentResponse = CreateCurrentResponse(feed);

            var initialState = new Exploring(currentResponse, ApplicationStateInfo);
            var nextState = initialState.NextState(new HttpClient());

            Assert.IsTrue(nextState.ApplicationStateInfo.History.SequenceEqual(ApplicationStateInfo.History));
        }
        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 ShouldReturnResolvingEncounterApplicationStateIfCurrentResponseContainsEncounterFeed()
        {
            var feed = new FeedBuilder().WithCategory("encounter").ToString();

            var currentResponse = CreateCurrentResponse(feed);

            var initialState = new Exploring(currentResponse, ApplicationStateInfo);
            var nextState = initialState.NextState(new HttpClient());

            Assert.IsInstanceOf(typeof (ResolvingEncounter), nextState);
        }
        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 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 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 ShouldBeNonTerminalState()
 {
     var state = new Exploring(new HttpResponseMessage(), ApplicationStateInfo.WithEndurance(5));
     Assert.IsFalse(state.IsTerminalState);
 }
        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);
        }