static void Main(string[] args) { var serviceHost = new HttpConfigurableServiceHost<CustomerService>(HttpHostConfiguration.Create(), new Uri[] { new Uri("http://localhost:1234/customers") }); serviceHost.Open(); Console.WriteLine("Service Started.."); Console.ReadLine(); serviceHost.Close(); }
public void ShouldNavigateMaze() { var expectedPath = new[] { CreatePath(1), CreatePath(4), CreatePath(7), CreatePath(6), CreatePath(5), CreatePath(4), CreatePath(8), CreatePath(9), CreatePath(8), CreatePath(10) }; var path = new List<string>(); var configuration = HttpHostConfiguration.Create() .SetResourceFactory((type, instanceContext, request) => new RoomResource(Maze.NewInstance(), Monsters.NullEncounters()), (instanceContext, obj) => { }); // Workaround for serialization issue in Preview 4. // Must clear default XML formatter from Formatters before adding Atom formatter. var hostConfiguration = (HttpHostConfiguration) configuration; hostConfiguration.OperationHandlerFactory.Formatters.Clear(); hostConfiguration.OperationHandlerFactory.Formatters.Insert(0, AtomMediaType.Formatter); using (var host = new HttpConfigurableServiceHost(typeof(RoomResource), configuration, new Uri("http://" + Environment.MachineName + ":8081/rooms/"))) { host.Open(); var moveCount = 0; var client = AtomClient.CreateDefault(); IApplicationState state = new Started(new Uri("http://" + Environment.MachineName + ":8081/rooms/1"), ApplicationStateInfo.WithEndurance(5)); while (!state.IsTerminalState && moveCount++ < 20) { state = state.NextState(client); if (state.GetType().Equals(typeof (Exploring))) { path.Add(state.CurrentResponse.RequestMessage.RequestUri.AbsoluteUri); } } Assert.IsInstanceOf(typeof (GoalAchieved), state); Assert.IsTrue(path.SequenceEqual(expectedPath)); host.Close(); } }
public void FunctionalTest() { var configuration = HttpHostConfiguration.Create() .SetResourceFactory((type, instanceContext, request) => new RoomResource(Maze.NewInstance(), Monsters.NullEncounters()), (instanceContext, obj) => { }); // Workaround for serialization issue in Preview 4. // Must clear default XML formatter from Formatters before adding Atom formatter. var hostConfiguration = (HttpHostConfiguration) configuration; hostConfiguration.OperationHandlerFactory.Formatters.Clear(); hostConfiguration.OperationHandlerFactory.Formatters.Insert(0, AtomMediaType.Formatter); using (var host = new HttpConfigurableServiceHost(typeof (RoomResource), configuration, new Uri("http://" + Environment.MachineName + ":8081/rooms/"))) { host.Open(); var entryFormatter = new Atom10ItemFormatter(); var client = AtomClient.CreateDefault(); using (var firstResponse = client.Get("http://" + Environment.MachineName + ":8081/rooms/1")) { entryFormatter.ReadFrom(XmlReader.Create(firstResponse.Content.ContentReadStream)); } var firstRoom = entryFormatter.Item; var northLink = firstRoom.Links.First(l => l.RelationshipType.Equals("north")); var northUri = new Uri(firstRoom.BaseUri, northLink.Uri); using (var secondResponse = client.Get(northUri)) { entryFormatter.ReadFrom(XmlReader.Create(secondResponse.Content.ContentReadStream)); } var nextRoom = entryFormatter.Item; //See Maze class for layout of the maze. Room 4 is north of room 1. Assert.AreEqual(Maze.NewInstance().Get(4).Description, nextRoom.Summary.Text); host.Close(); } }