Пример #1
0
    public void TestUpdateShouldReturnStale()
    {
        if (!did_create_run)
        {
            TestCreateShouldReturnNewId();
        }

        ProblemViewModel vm1 = new ProblemViewModel();
        ProblemViewModel vm2 = new ProblemViewModel();

        vm1.ProblemId = vm2.ProblemId = id_string;
        vm1.GetById();
        vm2.GetById();

        vm1.Description = "11";
        vm2.Description = "22";

        int ver = vm1.Version;

        Assert.IsTrue(vm1.Update() == (int)UpdateStatus.Ok);
        Assert.IsTrue(vm2.Update() == (int)UpdateStatus.Stale);

        vm1.GetById(); // get the update version of the emp
        Assert.IsTrue(vm1.Description == "11");
        Assert.IsTrue(vm1.Version == ver + 1);

        // change it back
        vm1.GetById();
        vm1.Description = descrip;
        Assert.IsTrue(vm1.Update() == (int)UpdateStatus.Ok);
    }// TestUpdateShouldReturnStale
Пример #2
0
    public void TestUpdateShouldReturnOk()
    {
        if (!did_create_run)
        {
            TestCreateShouldReturnNewId();
        }

        ProblemViewModel vm = new ProblemViewModel();

        vm.ProblemId = id_string;
        vm.GetById();
        vm.Description = "1";

        int ver = vm.Version;

        Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok);
        vm.GetById(); // get updated version
        Assert.IsTrue(vm.Version == ver + 1);
        Assert.IsTrue(vm.Description == "1");

        // change it back
        vm.Description = descrip;
        Assert.IsTrue(vm.Update() == (int)UpdateStatus.Ok);
        vm.GetById();
        Assert.IsTrue(vm.Version == ver + 2);
        Assert.IsTrue(vm.Description == descrip);
    }// TestUpdateShouldReturnOk
Пример #3
0
        public IHttpActionResult Delete(string id)
        {
            try
            {
                ProblemViewModel vm = new ProblemViewModel();
                vm.ProblemId = id;
                vm.GetById();
                long retVal = vm.Delete();
                switch (retVal)
                {
                case 1:
                    return(Ok("Problem deleted!"));

                case 0:
                    return(Ok("Problem not deleted!"));

                default:
                    return(Ok("Problem not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Retrieve failed - " + ex.Message));
            }
        }
Пример #4
0
    public void TestGetByIdShouldPopulateProps()
    {
        if (!did_create_run)
        {
            TestCreateShouldReturnNewId();
        }

        ProblemViewModel vm = new ProblemViewModel();

        vm.ProblemId = id_string;
        vm.GetById();
        Assert.IsTrue(vm.Description == descrip);
    }// TestGetByIdShouldPopulateProps
Пример #5
0
 public IHttpActionResult Get(string id)
 {
     try
     {
         ProblemViewModel prob = new ProblemViewModel();
         prob.ProblemId = id;
         prob.GetById();
         return(Ok(prob));
     }
     catch (Exception ex)
     {
         return(BadRequest("Retrieve failed - " + ex.Message));
     }
 }
Пример #6
0
    public void TestDeleteShouldReturnOne()
    {
        if (!did_create_run)
        {
            TestCreateShouldReturnNewId();
        }

        ProblemViewModel vm = new ProblemViewModel();

        vm.ProblemId = id_string;
        vm.GetById();

        Assert.IsTrue(vm.Delete() == 1);
    } // TestDeleteShouldReturnOne
Пример #7
0
 public IHttpActionResult GetProblemById(string id)
 {
     try
     {
         ProblemViewModel prob = new ProblemViewModel();
         prob.Id = id;
         prob.GetById();
         return(Ok(prob));
     }
     catch (Exception ex)
     {
         return(BadRequest("Retrieve failed - Contact Tech Support"));
     }
 }