public void CanRetrieveSimpleResourceDetails()
        {
            using (var host = new InMemoryHost(new SampleApi.Configuration()))
            {
                var request = new InMemoryRequest
                {
                    Uri = new Uri("http://localhost/api-docs/simple"),
                    HttpMethod = "GET",
                    Entity = {ContentType = MediaType.Json}
                };

                request.Entity.Headers["Accept"] = "application/json";

                var response = host.ProcessRequest(request);
                var statusCode = response.StatusCode;
                Assert.AreEqual(200, statusCode);

                Assert.IsTrue(response.Entity.ContentLength>0);

                response.Entity.Stream.Seek(0, SeekOrigin.Begin);

                var serializer = new DataContractJsonSerializer(typeof(ResourceDetails));
                var resourceDetails = (ResourceDetails) serializer.ReadObject(response.Entity.Stream);

                Assert.IsNotNull(resourceDetails);
            }
        }
Exemple #2
0
        public void Should_Get_Specific_Task()
        {
            using (var host = new InMemoryHost(new Configuration()))
            {
                var req = new InMemoryRequest
                    {
                        Uri = new Uri("http://localhost/tasks/1"),
                        HttpMethod = "GET"
                    };

                req.Entity.Headers["Accept"] = "application/json";

                var response = host.ProcessRequest(req);

                // deserialize the content from the response
                Resources.Task returnedObject = null;
                if (response.Entity.ContentLength > 0)
                {
                    // you must rewind the stream, as OpenRasta
                    // won't do this for you
                    response.Entity.Stream.Seek(0, SeekOrigin.Begin);

                    var serializer = new DataContractJsonSerializer(typeof(Resources.Task));
                    returnedObject = (Resources.Task)serializer.ReadObject(response.Entity.Stream);
                }

                returnedObject.Id.ShouldEqual(1);
            }
        }
        public void TestInitialize()
        {
            _mockFileSystem = (new MockFileSystemProvider()).MockFileSystem;
            _repository = new DurableMemoryRepository<ConfigRoot>(DataPath, _mockFileSystem.Object);

            var container = new Container();
            container.Configure(x =>
            {
                x.For<IRepository<IJsonEntity<ConfigRoot>>>().Singleton().Use(_repository);
                //x.For<ILog>().Singleton().Use(l => new NoOpLog());
            });

            _host = new InMemoryHost(new Configuration(container));
        }
        public void Missing_registration_throws_exception()
        {
            var container = new Container();
            _host = new InMemoryHost(new Configuration(container));

            IRequest request = new InMemoryRequest
                                   {
                                       HttpMethod = "GET",
                                       Uri = new Uri("http://localhost/Config/tacos")
                                   };

            var response = _host.ProcessRequest(request);

            Assert.AreEqual(500, response.StatusCode);
        }
 public void SetUp()
 {
     Database.ResetDatabase();
     _inMemoryHost = new InMemoryHost(new Configuration());
     DependencyManager.SetResolver(_inMemoryHost.Resolver);
 }
 public void Initialize()
 {
     _host = new InMemoryHost(new Configurator());
 }
 public void Dispose()
 {
     _host.Close();
     _host = null;
 }
 protected override void SetUp()
 {
     _customResolver = new CustomResolver();
     _host = new InMemoryHost(null, _customResolver);
 }
 protected override void SetUp()
 {
     _host = new InMemoryHost(null);
 }
        public void Ensure_that_error_handling_works_for_put()
        {
            // Override the config to give it a broken logger
            /*var mockLogger = new Mock<ILog>();
            mockLogger.Setup(s => s.Debug(It.Is<string>(m => m.Contains("Entering ConfigHandler"))))
                .Throws(new ApplicationException("ha ha!"));*/

            _mockFileSystem = (new MockFileSystemProvider()).MockFileSystem;
            _repository = new DurableMemoryRepository<ConfigRoot>(DataPath, _mockFileSystem.Object);

            var container = new Container();
            container.Configure(x =>
            {
                x.For<IRepository<IJsonEntity<ConfigRoot>>>().Singleton().Use(_repository);
                //x.For<ILog>().Singleton().Use(mockLogger.Object);
            });

            _host = new InMemoryHost(new Configuration(container));

            var configRoot = new ConfigRoot
            {
                ComponentName = "tabOuli",
                Data = new ConfigNode
                {
                    Name = "tabouli",
                    Value = "tomatoes",
                    Children =
                        new List<ConfigNode> { new ConfigNode { Name = "Side", Value = "Rice" } }
                }
            };

            IRequest request = new InMemoryRequest
            {
                HttpMethod = "PUT",
                Uri = new Uri("http://localhost/Config/tacos")
            };

            request.Headers["Content-Type"] = "application/json";
            var length = WriteConfigRootToStream(request.Entity.Stream, configRoot);
            request.Headers["Content-Length"] = length.ToString(CultureInfo.InvariantCulture);

            var response = _host.ProcessRequest(request);

            Assert.AreEqual(500, response.StatusCode);
        }