Exemplo n.º 1
0
        public async Task PutItem_Upsert()
        {
            var filePath    = UTHelpers.Up();
            var ds          = new DataStore(filePath);
            var apiSettings = Options.Create(new ApiSettings {
                UpsertOnPut = true
            });

            var controller = new DynamicController(ds, apiSettings);

            var result = await controller.ReplaceItem("my_test", "2", JToken.Parse("{ 'id': 2, 'name': 'Raymond', 'age': 32 }"));

            Assert.IsType <NoContentResult>(result);

            var itemResult = controller.GetItem("my_test", "2");

            Assert.IsType <OkObjectResult>(itemResult);

            var     okObjectResult = itemResult as OkObjectResult;
            dynamic item           = okObjectResult.Value as ExpandoObject;

            Assert.Equal("Raymond", item.name);

            UTHelpers.Down(filePath);
        }
Exemplo n.º 2
0
        public async Task PutItem_NoUpsert()
        {
            var filePath    = UTHelpers.Up();
            var ds          = new DataStore(filePath);
            var apiSettings = Options.Create(new ApiSettings {
                UpsertOnPut = false
            });

            var controller = new DynamicController(ds, apiSettings);

            var result = await controller.ReplaceItem("my_test", "2", JToken.Parse("{ 'id': 2, 'name': 'Raymond', 'age': 32 }"));

            Assert.IsType <NotFoundResult>(result);

            UTHelpers.Down(filePath);
        }
Exemplo n.º 3
0
        public async Task PutItem_Upsert_Id_String()
        {
            var filePath    = UTHelpers.Up();
            var ds          = new DataStore(filePath);
            var apiSettings = Options.Create(new ApiSettings {
                UpsertOnPut = true
            });

            var controller = new DynamicController(ds, apiSettings);

            var result = await controller.ReplaceItem("my_test_string", "acdc", JToken.Parse("{ 'id': 2, 'text': 'Hello' }")) as NoContentResult;

            Assert.Equal(204, result.StatusCode);

            var itemResult = controller.GetItem("my_test_string", "acdc") as OkObjectResult;

            dynamic item = itemResult.Value as ExpandoObject;

            Assert.Equal("acdc", item.id);
            Assert.Equal("Hello", item.text);

            UTHelpers.Down(filePath);
        }