Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating Exercise 3 t omake it easier to run as a developer

  • Loading branch information...
commit 5c119d732129018e92222c019eebf6e498b70f09 1 parent d0bf4d7
@iansrobinson authored
View
10 master-src/HydrasAndHypermedia.Server/Resources/EncounterResource.cs
@@ -70,11 +70,11 @@ public HttpResponseMessage<SyndicationFeed> Get(string id, HttpRequestMessage re
{
var entry = new SyndicationItem
{
- Id = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/round/{1}", encounter.Id, round.Id),
+ Id = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/rounds/{1}", encounter.Id, round.Id),
Title = SyndicationContent.CreatePlaintextContent("Round " + round.Id),
Summary = SyndicationContent.CreatePlaintextContent(string.Format("The {0} has {1} Endurance Points", encounter.Title, round.Endurance))
};
- entry.Links.Add(SyndicationLink.CreateSelfLink(new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, round.Id))));
+ entry.Links.Add(SyndicationLink.CreateSelfLink(new Uri(string.Format("http://{0}:8081/encounters/{1}/rounds/{2}", Environment.MachineName, encounter.Id, round.Id))));
entry.Categories.Add(new SyndicationCategory("round"));
return entry;
});
@@ -117,13 +117,13 @@ public HttpResponseMessage<SyndicationItem> Post(string id, HttpRequestMessage r
var entry = new SyndicationItem
{
- Id = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/round/{1}", encounter.Id, round.Id),
+ Id = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/rounds/{1}", encounter.Id, round.Id),
BaseUri = BaseUri,
Title = SyndicationContent.CreatePlaintextContent("Round " + round.Id),
Summary = SyndicationContent.CreatePlaintextContent(string.Format("The {0} has {1} Endurance Point{2}", encounter.Title, round.Endurance, Math.Abs(round.Endurance).Equals(1) ? "" : "s")),
Content = SyndicationContent.CreateXhtmlContent(xhtml),
};
- entry.Links.Add(SyndicationLink.CreateSelfLink(new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, round.Id))));
+ entry.Links.Add(SyndicationLink.CreateSelfLink(new Uri(string.Format("http://{0}:8081/encounters/{1}/rounds/{2}", Environment.MachineName, encounter.Id, round.Id))));
entry.Categories.Add(new SyndicationCategory("round"));
if (encounter.IsResolved)
@@ -137,7 +137,7 @@ public HttpResponseMessage<SyndicationItem> Post(string id, HttpRequestMessage r
}
var response = new HttpResponseMessage<SyndicationItem>(entry) {StatusCode = HttpStatusCode.Created};
- response.Headers.Location = new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, result.Round.Id));
+ response.Headers.Location = new Uri(string.Format("http://{0}:8081/encounters/{1}/rounds/{2}", Environment.MachineName, encounter.Id, result.Round.Id));
response.Content.Headers.ContentType = AtomMediaType.Entry;
return response;
View
20 src/HydrasAndHypermedia.Exercises/Exercise02/Part02_ExploringTests.cs
@@ -46,6 +46,26 @@ public void NextStateShouldReturnExploringApplicatonState()
}
[Test]
+ 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);
+ }
+
+ [Test]
public void ShouldFollowExitToNorthInPreferenceToAllOtherExits()
{
var entry = new EntryBuilder()
View
18 src/HydrasAndHypermedia.Exercises/Exercise03/Part01_UnresolvedEncounterResourceTests.cs
@@ -51,24 +51,24 @@ public void ResponseShouldIndicateItMustNotBeStoredByCaches()
}
[Test]
- public void ResponseShouldIncludeAtomFeedContentTypeHeader()
+ public void ResponseContentShouldBeSyndicationFeed()
{
var encounter = CreateEncounter();
var resource = CreateEncounterResource(encounter);
var response = resource.Get(encounter.Id.ToString(), CreateRequest(encounter.Id));
+ var feed = response.Content.ReadAsOrDefault();
- Assert.AreEqual(AtomMediaType.Feed, response.Content.Headers.ContentType);
+ Assert.IsInstanceOf(typeof(SyndicationFeed), feed);
}
[Test]
- public void ResponseContentShouldBeSyndicationFeed()
+ public void ResponseShouldIncludeAtomFeedContentTypeHeader()
{
var encounter = CreateEncounter();
var resource = CreateEncounterResource(encounter);
var response = resource.Get(encounter.Id.ToString(), CreateRequest(encounter.Id));
- var feed = response.Content.ReadAsOrDefault();
- Assert.IsInstanceOf(typeof (SyndicationFeed), feed);
+ Assert.AreEqual(AtomMediaType.Feed, response.Content.Headers.ContentType);
}
[Test]
@@ -189,7 +189,7 @@ public void FeedShouldIncludeAnItemForEachRound()
}
[Test]
- public void ItemTitlesRepresentRoundsWithMostRecentRoundFirst()
+ public void ItemTitlesShouldIncludeRoundNumberWithMostRecentRoundFirst()
{
const int numberOfRounds = 3;
var encounter = CreateEncounter(numberOfRounds);
@@ -217,13 +217,13 @@ public void EachItemIdShouldBeTagUri()
for (var i = 0; i < numberOfRounds; i++)
{
- var expectedId = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/round/{1}", encounter.Id, numberOfRounds - i);
+ var expectedId = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/rounds/{1}", encounter.Id, numberOfRounds - i);
Assert.AreEqual(expectedId, feed.Items.ElementAt(i).Id);
}
}
[Test]
- public void ItemIdShouldHaveASelfLink()
+ public void EachItemShouldHaveASelfLink()
{
const int numberOfRounds = 3;
var encounter = CreateEncounter(numberOfRounds);
@@ -237,7 +237,7 @@ public void ItemIdShouldHaveASelfLink()
var item = feed.Items.ElementAt(i);
var selfLink = item.Links.First(l => l.RelationshipType.Equals("self"));
- var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, numberOfRounds - i));
+ var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/rounds/{2}", Environment.MachineName, encounter.Id, numberOfRounds - i));
Assert.AreEqual(expectedUri, selfLink.Uri);
}
}
View
62 src/HydrasAndHypermedia.Exercises/Exercise03/Part02_ResolvingEncounterResourceTests.cs
@@ -39,7 +39,7 @@ public void ShouldReturnLocationHeaderWithUriOfEachNewlyCreatedResource()
{
var resource = CreateEncounterResource(encounter);
var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
- var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, encounter.GetAllRounds().Last().Id));
+ var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/rounds/{2}", Environment.MachineName, encounter.Id, encounter.GetAllRounds().Last().Id));
Assert.AreEqual(expectedUri, response.Headers.Location);
}
@@ -63,24 +63,24 @@ public void ShouldReturn404NotFoundIfPostingToEncounterThatDoesNotExist()
}
[Test]
- public void ResponseShouldIncludeAtomEntryContentTypeHeader()
+ public void ResponseContentShouldBeSyndicationItem()
{
var encounter = CreateEncounter();
var resource = CreateEncounterResource(encounter);
var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
+ var item = response.Content.ReadAsOrDefault();
- Assert.AreEqual(AtomMediaType.Entry, response.Content.Headers.ContentType);
+ Assert.IsInstanceOf(typeof(SyndicationItem), item);
}
[Test]
- public void ResponseContentShouldBeSyndicationItem()
+ public void ResponseShouldIncludeAtomEntryContentTypeHeader()
{
var encounter = CreateEncounter();
var resource = CreateEncounterResource(encounter);
var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
- var item = response.Content.ReadAsOrDefault();
- Assert.IsInstanceOf(typeof (SyndicationItem), item);
+ Assert.AreEqual(AtomMediaType.Entry, response.Content.Headers.ContentType);
}
[Test]
@@ -95,16 +95,22 @@ public void ItemShouldContainRoundCategory()
}
[Test]
- public void ItemIdShouldBeTagUri()
+ public void EachItemIdShouldBeTagUri()
{
+ const int numberOfRounds = 3;
var encounter = CreateEncounter();
+
var resource = CreateEncounterResource(encounter);
- var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
- var item = response.Content.ReadAsOrDefault();
- var expectedItemId = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/round/{1}", encounter.Id, encounter.GetAllRounds().Last().Id);
+ for (var i = 0; i < numberOfRounds; i++)
+ {
+ var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
+ var item = response.Content.ReadAsOrDefault();
+
+ var expectedItemId = string.Format("tag:restinpractice.com,2011-09-05:/encounters/{0}/round/{1}", encounter.Id, encounter.GetAllRounds().Last().Id);
- Assert.AreEqual(expectedItemId, item.Id);
+ Assert.AreEqual(expectedItemId, item.Id);
+ }
}
[Test]
@@ -119,17 +125,23 @@ public void ItemShouldIncludeBaseUri()
}
[Test]
- public void ItemShouldHaveSelfLink()
+ public void EachItemShouldHaveSelfLink()
{
+ const int numberOfRounds = 3;
var encounter = CreateEncounter();
+
var resource = CreateEncounterResource(encounter);
- var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
- var item = response.Content.ReadAsOrDefault();
- var selfLink = item.Links.First(l => l.RelationshipType.Equals("self"));
- var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, encounter.GetAllRounds().Last().Id));
+ for (var i = 0; i < numberOfRounds; i++)
+ {
+ var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
+ var item = response.Content.ReadAsOrDefault();
+ var selfLink = item.Links.First(l => l.RelationshipType.Equals("self"));
+
+ var expectedUri = new Uri(string.Format("http://{0}:8081/encounters/{1}/round/{2}", Environment.MachineName, encounter.Id, encounter.GetAllRounds().Last().Id));
- Assert.AreEqual(expectedUri, selfLink.Uri);
+ Assert.AreEqual(expectedUri, selfLink.Uri);
+ }
}
[Test]
@@ -147,16 +159,22 @@ public void ItemShouldHaveFleeLink()
}
[Test]
- public void ItemTitleShouldRepresentCurrentRound()
+ public void EachItemTitleShouldRepresentCurrentRound()
{
+ const int numberOfRounds = 3;
var encounter = CreateEncounter();
+
var resource = CreateEncounterResource(encounter);
- var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
- var item = response.Content.ReadAsOrDefault();
- var expectedTitle = "Round " + encounter.GetAllRounds().Last().Id;
+ for (var i = 0; i < numberOfRounds; i++)
+ {
+ var response = resource.Post(encounter.Id.ToString(), CreateRequest(encounter.Id, CreateFormUrlEncodedContent(ClientEndurance)));
+ var item = response.Content.ReadAsOrDefault();
+
+ var expectedTitle = "Round " + encounter.GetAllRounds().Last().Id;
- Assert.AreEqual(expectedTitle, item.Title.Text);
+ Assert.AreEqual(expectedTitle, item.Title.Text);
+ }
}
[Test]
Please sign in to comment.
Something went wrong with that request. Please try again.