public void WhenCreatedThenOperationHandlerFactoryIsSet() { var config = new HttpHostConfiguration(); config.OperationHandlerFactory = new TestOperationHandlerFactory(); var host = new HttpConfigurableServiceHost(typeof(TestService), config, new Uri(DummyUri)); Assert.AreEqual(config.OperationHandlerFactory, host.OperationHandlerFactory); }
public void WhenCreatedThenHttpEndpointIsAddedToTheService() { var config = new HttpHostConfiguration(); var host = new HttpConfigurableServiceHost(typeof (TestService), config, new Uri(DummyUri)); var httpEndpoint = (HttpEndpoint) host.Description.Endpoints.Find(typeof (TestService)); Assert.IsNotNull(httpEndpoint); }
public void TearDown() { if (host != null) { host.Close(); host = null; } }
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 FixtureSetUp() { var config = HttpHostConfiguration.Create(). SetMessageHandlerFactory(new CustomHttpMessageHandlerFactory(innerChannel => new BasicAuthenticationHandler(innerChannel, new UserValidation(), "test"))); Host = new HttpConfigurableServiceHost<HelloWorldResource>((HttpHostConfiguration)config, new Uri[] { new Uri("http://localhost:8090") }); Host.Open(); }
static void MainWithConfiguration() { var cfg = HttpHostConfiguration.Create() .AddMessageHandlers(typeof (SampleMessageHandler)) .SetOperationHandlerFactory(new MyOperationConfigurationFactory()); using (var host = new HttpConfigurableServiceHost(typeof(TheService), cfg, new Uri("http://localhost:8080"))) { host.Open(); Console.WriteLine("Host opened at {0} , press any key to end", host.Description.Endpoints[0].Address); Console.ReadKey(); } }
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 SetUpFixture() { // Creates a new Spring context var builder = new ContainerBuilder(); builder.RegisterModule(new WebApiModule()); PopulateApplicationContext(builder); var config = HttpHostConfiguration.Create() .AddFormatters(new AtomMediaTypeFormatter()) .SetResourceFactory(new AutofacResourceFactory(builder.Build())); var type = GetServiceType(); host = new HttpConfigurableServiceHost(type, config, baseUri); host.Open(); ResourceLocation.BaseAddress = baseUri; // Create client instance client = new RestClient(baseUri, GetSerializationType()); }
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(); } }
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var host = new HttpConfigurableServiceHost(serviceType, this.Builder, baseAddresses); return host; }
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { var host = new HttpConfigurableServiceHost(serviceType, this.Builder, baseAddresses); return(host); }
public void WhenCreatedWithATypeThenServiceTypeIsSet() { var config = new HttpHostConfiguration(); var host = new HttpConfigurableServiceHost(typeof (TestService), config,new Uri(DummyUri)); Assert.AreEqual(typeof(TestService), host.serviceType); }
public void WhenCreatedWithAnInstanceThenConfigurationIsSet() { var config = new HttpHostConfiguration(); var host = new HttpConfigurableServiceHost(new TestService(), config, new Uri(DummyUri)); Assert.AreEqual(config, host.configuration); }
public void WhenCreatedThenAspNetCompatibilityRequirementsAttributeIsAdded() { var config = new HttpHostConfiguration(); var host = new HttpConfigurableServiceHost(new TestService(), config, new Uri(DummyUri)); Assert.IsTrue(host.Description.Behaviors.Contains(typeof (AspNetCompatibilityRequirementsAttribute))); }
public void WhenHttpEndpointIsCreatedThenOperationHandlerFactoryIsSet() { var config = new HttpHostConfiguration(); config.OperationHandlerFactory = new TestOperationHandlerFactory(); var host = new HttpConfigurableServiceHost(typeof(TestService), config, new Uri(DummyUri)); var httpEndpoint = (HttpEndpoint)host.Description.Endpoints.Find(typeof(TestService)); Assert.AreEqual(config.OperationHandlerFactory, httpEndpoint.OperationHandlerFactory); }
public void WhenHttpEndpointIsCreatedThenInstanceProviderBehaviorIsAdded() { var config = new HttpHostConfiguration(); config.InstanceFactory = new TestInstanceFactory(); var host = new HttpConfigurableServiceHost(typeof(TestService), config, new Uri(DummyUri)); var httpEndpoint = (HttpEndpoint)host.Description.Endpoints.Find(typeof(TestService)); Assert.IsTrue(httpEndpoint.Behaviors.Contains(typeof (InstanceProviderBehavior))); }