public void WhenQueryingRepeatedArgument_ThenServiceGetsBoth() { var baseUri = new Uri("http://localhost:20000"); var service = new ProductsService(); var config = HttpHostConfiguration.Create() .SetResourceFactory(new SingletonResourceFactory(service)) .UseJsonNet() .AddMessageHandlers(typeof(TracingChannel)); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(ProductsService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var query = (IHttpEntityQuery <Product>)client.Query <Product>("products/search2", new HttpNameValueCollection { { "search", "10" }, { "search", "20" }, { "count", "25" } }); var result = query.Execute(); Assert.Equal(2, result.TotalCount); Assert.Equal(2, result.Count()); Assert.Equal(10, result.First().Id); } }
public void WhenQueryingWithExtraCriteria_ThenPopulatesMatchingEntities() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query <Product>(resourceName, new { search = "kzu" }).ToList(); Assert.True(products.All(x => x.Owner.Name == "kzu")); } }
public void WhenQueryingAndNoMatches_ThenReturnsEmptyEnumerable() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query <Product>(resourceName).Where(x => x.Owner.Name == "foo").ToList(); Assert.Equal(0, products.Count); } }
public void WhenSkipTakeOnly_ThenReturnsSingleElement() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query <Product>(resourceName).Skip(1).Take(1).ToList(); Assert.Equal(1, products.Count); Assert.Equal(2, products[0].Id); } }
public void WhenDeleteFails_ThenThrows() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var exception = Assert.Throws <HttpEntityException>(() => client.Delete(resourceName, "25")); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); } }
public void WhenPostFails_ThenThrows() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var exception = Assert.Throws <HttpEntityException>(() => client.Post <Product>(resourceName, null)); Assert.Equal(HttpStatusCode.InternalServerError, exception.StatusCode); } }
public void WhenOrderByTake_ThenReturnsOrdered() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query <Product>(resourceName).OrderBy(x => x.Title).Take(2).ToList(); Assert.Equal(2, products.Count); Assert.Equal("A", products[0].Title); Assert.Equal("B", products[1].Title); } }
public void WhenGettingWithoutId_ThenRetrieves() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = client.Get <Product>(resourceName + "/latest"); Assert.NotNull(product); Assert.Equal("vga", product.Owner.Name); } }
public void WhenTryGetFails_ThenReturnsResponse() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = default(Product); var response = client.TryGet <Product>(resourceName, "25", out product); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Null(product); } }
public void WhenGettingWithoutId_ThenRetrieves() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = client.Get<Product>(resourceName + "/latest"); Assert.NotNull(product); Assert.Equal("vga", product.Owner.Name); } }
public void WhenDeletingEntity_ThenGetFails() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); client.Delete(resourceName, "1"); var exception = Assert.Throws<HttpEntityException>(() => client.Get<Product>(resourceName, "25")); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); } }
public void WhenQuerying_ThenPopulatesMatchingEntities() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var ids = client.Query <Product>(resourceName).Where(x => x.Owner.Name == "kzu").Select(x => x.Id).ToList(); var products = client.Query <Product>(resourceName).Where(x => x.Owner.Name == "kzu").ToList(); Assert.Equal(2, ids.Count); Assert.True(products.All(x => x.Owner.Name == "kzu")); } }
public void WhenTryGetSucceeds_ThenPopulatesEntity() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = default(Product); var response = client.TryGet <Product>(resourceName, "1", out product); Assert.True(response.IsSuccessStatusCode); Assert.NotNull(product); Assert.Equal("kzu", product.Owner.Name); } }
public void WhenPostNew_ThenSavesAndRetrievesId() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = new Product { Owner = new User { Id = 1, Name = "kzu" } }; var saved = client.Post(resourceName, product); Assert.Equal(4, saved.Id); Assert.Equal(saved.Owner.Id, product.Owner.Id); Assert.Equal(saved.Owner.Name, product.Owner.Name); } }
public void WhenPutUpdate_ThenSaves() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", true, new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = new Product { Id = 1, Owner = new User { Id = 1, Name = "vga" } }; client.Put(resourceName, "1", product); var saved = client.Get <Product>(resourceName, "1"); Assert.Equal(saved.Owner.Name, product.Owner.Name); } }
public void WhenPostNew_ThenSavesAndRetrievesId() { using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = new Product { Owner = new User { Id = 1, Name = "kzu" } }; var saved = client.Post(resourceName, product); Assert.Equal(4, saved.Id); Assert.Equal(saved.Owner.Id, product.Owner.Id); Assert.Equal(saved.Owner.Name, product.Owner.Name); } }
public void WhenQuerying_ThenCanGetTotalCount() { var baseUri = new Uri("http://localhost:20000"); var service = new TestService(); var config = new ServiceConfiguration(service); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(TestService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var products = client.Query <Product>(resourceName, new { search = "kzu" }).Skip(5).Take(10); var query = products as IHttpEntityQuery <Product>; var response = query.Execute(); Assert.Equal(2, response.TotalCount); Assert.Equal(0, response.Count()); Assert.True(response.Response.IsSuccessStatusCode); } }
public void WhenQueryingOverLimit_ThenGetsLimitedResults() { var baseUri = new Uri("http://localhost:20000"); var service = new ProductsService(); var config = HttpHostConfiguration.Create() .SetResourceFactory(new SingletonResourceFactory(service)) .AddMessageHandlers(typeof(TracingChannel)); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(ProductsService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var query = (IHttpEntityQuery <Product>)client.Query <Product>("products").Skip(10).Take(50); var result = query.Execute(); Assert.Equal(100, result.TotalCount); Assert.Equal(25, result.Count()); Assert.Equal(10, result.First().Id); } }
public void WhenQueryingOverLimit_ThenGetsLimitedResults() { var baseUri = new Uri("http://localhost:20000"); var service = new ProductsService(); var config = HttpHostConfiguration.Create() .SetResourceFactory(new SingletonResourceFactory(service)) .AddMessageHandlers(typeof(TracingChannel)); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(ProductsService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var query = (IHttpEntityQuery<Product>)client.Query<Product>("products").Skip(10).Take(50); var result = query.Execute(); Assert.Equal(100, result.TotalCount); Assert.Equal(25, result.Count()); Assert.Equal(10, result.First().Id); } }
public void WhenExecutingRequest_ThenTracesInformationHeaders() { var listener = new ConsoleTraceListener(); TracerExtensibility.AddListener(SourceName.For<TracingChannel>(), listener); TracerExtensibility.SetTracingLevel(SourceName.For<TracingChannel>(), SourceLevels.All); var config = HttpHostConfiguration.Create() .UseJsonNet() .AddMessageHandlers(typeof(TracingChannel)); using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", true, config)) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>().Skip(1).Take(1).ToList(); Assert.Equal(1, products.Count); Assert.Equal(2, products[0].Id); } listener.Flush(); }
public void WhenExecutingRequest_ThenTracesInformationHeaders() { var listener = new ConsoleTraceListener(); TracerExtensibility.AddListener(SourceName.For <TracingChannel>(), listener); TracerExtensibility.SetTracingLevel(SourceName.For <TracingChannel>(), SourceLevels.All); var config = HttpHostConfiguration.Create() .UseJsonNet() .AddMessageHandlers(typeof(TracingChannel)); using (var ws = new HttpWebService <TestService>("http://localhost:20000", "products", true, config)) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query <Product>().Skip(1).Take(1).ToList(); Assert.Equal(1, products.Count); Assert.Equal(2, products[0].Id); } listener.Flush(); }
public void WhenPutUpdate_ThenSaves() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", true, new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = new Product { Id = 1, Owner = new User { Id = 1, Name = "vga" } }; client.Put(resourceName, "1", product); var saved = client.Get<Product>(resourceName, "1"); Assert.Equal(saved.Owner.Name, product.Owner.Name); } }
public void WhenTryGetSucceeds_ThenPopulatesEntity() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = default(Product); var response = client.TryGet<Product>(resourceName, "1", out product); Assert.True(response.IsSuccessStatusCode); Assert.NotNull(product); Assert.Equal("kzu", product.Owner.Name); } }
public void WhenQuerying_ThenPopulatesMatchingEntities() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var ids = client.Query<Product>(resourceName).Where(x => x.Owner.Name == "kzu").Select(x => x.Id).ToList(); var products = client.Query<Product>(resourceName).Where(x => x.Owner.Name == "kzu").ToList(); Assert.Equal(2, ids.Count); Assert.True(products.All(x => x.Owner.Name == "kzu")); } }
public void WhenQueryingAndNoMatches_ThenReturnsEmptyEnumerable() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>(resourceName).Where(x => x.Owner.Name == "foo").ToList(); Assert.Equal(0, products.Count); } }
public void WhenSkipTakeOnly_ThenReturnsSingleElement() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>(resourceName).Skip(1).Take(1).ToList(); Assert.Equal(1, products.Count); Assert.Equal(2, products[0].Id); } }
public void WhenOrderByTake_ThenReturnsOrdered() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>(resourceName).OrderBy(x => x.Title).Take(2).ToList(); Assert.Equal(2, products.Count); Assert.Equal("A", products[0].Title); Assert.Equal("B", products[1].Title); } }
public void WhenQueryingWithExtraCriteria_ThenPopulatesMatchingEntities() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var products = client.Query<Product>(resourceName, new { search = "kzu" }).ToList(); Assert.True(products.All(x => x.Owner.Name == "kzu")); } }
public void WhenQuerying_ThenCanGetTotalCount() { var baseUri = new Uri("http://localhost:20000"); var service = new TestService(); var config = new ServiceConfiguration(service); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(TestService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var products = client.Query<Product>(resourceName, new { search = "kzu" }).Skip(5).Take(10); var query = products as IHttpEntityQuery<Product>; var response = query.Execute(); Assert.Equal(2, response.TotalCount); Assert.Equal(0, response.Count()); Assert.True(response.Response.IsSuccessStatusCode); } }
public void WhenPostFails_ThenThrows() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var exception = Assert.Throws<HttpEntityException>(() => client.Post<Product>(resourceName, null)); Assert.Equal(HttpStatusCode.InternalServerError, exception.StatusCode); } }
public void WhenQueryingRepeatedArgument_ThenServiceGetsBoth() { var baseUri = new Uri("http://localhost:20000"); var service = new ProductsService(); var config = HttpHostConfiguration.Create() .SetResourceFactory(new SingletonResourceFactory(service)) .UseJsonNet() .AddMessageHandlers(typeof(TracingChannel)); using (new SafeHostDisposer( new HttpQueryableServiceHost(typeof(ProductsService), 25, config, new Uri(baseUri, "products")))) { var client = new HttpEntityClient(baseUri); var query = (IHttpEntityQuery<Product>)client.Query<Product>("products/search2", new HttpNameValueCollection { { "search", "10" }, { "search", "20" }, { "count", "25" } }); var result = query.Execute(); Assert.Equal(2, result.TotalCount); Assert.Equal(2, result.Count()); Assert.Equal(10, result.First().Id); } }
public void WhenTryGetFails_ThenReturnsResponse() { using (var ws = new HttpWebService<TestService>("http://localhost:20000", "products", new ServiceConfiguration())) { var client = new HttpEntityClient(ws.BaseUri); var product = default(Product); var response = client.TryGet<Product>(resourceName, "25", out product); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Null(product); } }