public void GetItems_UseResultObject_offsetlimit() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UseResultObject = true }); var controller = new DynamicController(ds, apiSettings); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.ControllerContext.HttpContext.Request.QueryString = new QueryString("?offset=5&limit=12"); var result = controller.GetItems("families") as OkObjectResult; var resultObject = JsonConvert.DeserializeObject <dynamic>(JsonConvert.SerializeObject(result.Value)); Assert.Equal(12, resultObject.results.Count); Assert.Equal(5, resultObject.offset.Value); Assert.Equal(12, resultObject.limit.Value); Assert.Equal(20, resultObject.count.Value); UTHelpers.Down(filePath); }
public void GetItems_EmptyCollection() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UseResultObject = true }); var dsSettings = Options.Create(new DataStoreSettings()); var controller = new DynamicController(ds, apiSettings, dsSettings); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); var result = controller.GetItems("empty_collection") as OkObjectResult; var resultObject = JsonConvert.DeserializeObject <dynamic>(JsonConvert.SerializeObject(result.Value)); Assert.Equal(0, resultObject.results.Count); Assert.Equal(0, resultObject.skip.Value); Assert.Equal(512, resultObject.take.Value); Assert.Equal(0, resultObject.count.Value); UTHelpers.Down(filePath); }
public void GetItems_UseResultObject() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UseResultObject = true }); var dsSettings = Options.Create(new DataStoreSettings()); var controller = new DynamicController(ds, apiSettings, dsSettings); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.ControllerContext.HttpContext.Request.QueryString = new QueryString(""); var result = controller.GetItems("families", 4, 10) as OkObjectResult; dynamic resultObject = JsonConvert.DeserializeObject <dynamic>(JsonConvert.SerializeObject(result.Value)); Assert.Equal(10, resultObject.results.Count); Assert.Equal(4, resultObject.skip.Value); Assert.Equal(10, resultObject.take.Value); Assert.Equal(20, resultObject.count.Value); UTHelpers.Down(filePath); }
public void GetItems_FriendsWithQueryString() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings()); var controller = new DynamicController(ds, apiSettings); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.ControllerContext.HttpContext.Request.QueryString = new QueryString("?children.friends.name=Castillo"); var result = controller.GetItems("families") as OkObjectResult; Assert.Equal(2, ((IEnumerable <dynamic>)result.Value).Count()); UTHelpers.Down(filePath); }
public void GetItems_FavouriteMoveiWithQueryString() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings()); var controller = new DynamicController(ds, apiSettings); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.ControllerContext.HttpContext.Request.QueryString = new QueryString("?parents.favouriteMovie=Predator"); // NOTE: Can't but skip and take to querystring with tests var result = controller.GetItems("families", 0, 100) as OkObjectResult; Assert.Equal(11, ((IEnumerable <dynamic>)result.Value).Count()); UTHelpers.Down(filePath); }
public void GetItems_Single() { var filePath = UTHelpers.Up(); var ds = new DataStore(filePath); var apiSettings = Options.Create(new ApiSettings { UpsertOnPut = true }); var controller = new DynamicController(ds, apiSettings); var itemResult = controller.GetItems("configuration"); Assert.IsType <OkObjectResult>(itemResult); var okObjectResult = itemResult as OkObjectResult; dynamic item = okObjectResult.Value as ExpandoObject; Assert.Equal("abba", item.password); UTHelpers.Down(filePath); }