示例#1
0
文件: TypeTests.cs 项目: WikiLibs/API
        public async Task Controller_PATCH()
        {
            var controller = new TypeController(Manager, User);

            var mdl = await controller.PostAsync(new TypeCreate()
            {
                Name = "test"
            }) as JsonResult;

            var obj = mdl.Value as Models.Output.Symbols.Type;

            Assert.AreEqual(1, obj.Id);
            Assert.AreEqual("test", obj.Name);

            await controller.PostAsync(new TypeCreate()
            {
                Name = "C1"
            });

            mdl = await controller.PatchAsync(1, new TypeUpdate()
            {
                Name = "function"
            }) as JsonResult;

            obj = mdl.Value as Models.Output.Symbols.Type;

            Assert.AreEqual(1, obj.Id);
            Assert.AreEqual("function", obj.Name);

            Assert.ThrowsAsync <Shared.Exceptions.ResourceAlreadyExists>(() => controller.PatchAsync(1, new TypeUpdate()
            {
                Name = "C1"
            }));

            User.SetPermissions(new string[] { });
            Assert.ThrowsAsync <Shared.Exceptions.InsuficientPermission>(() => controller.PatchAsync(1, null));
        }