Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
        public IHttpActionResult Put(ProblemViewModel prob)
        {
            try
            {
                int retVal = prob.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Problem " + prob.Description + " updated!"));

                case -1:
                    return(Ok("Problem " + prob.Description + " not updated!"));

                case -2:
                    return(Ok("Data is stale for " + prob.Description + ", Problem not updated!"));

                default:
                    return(Ok("Problem " + prob.Description + " not updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Retrieve failed - " + ex.Message));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult Put(ProblemViewModel prob)
        {
            try
            {
                int retVal = prob.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Ok! Problem " + prob.Description + " updated!"));

                case -1:
                    return(Ok("Problem" + prob.Description + " not updated!"));

                case -2:
                    return(Ok("Data is Stale for " + prob.Description + ", Problem not updated"));

                default:
                    return(Ok("Department " + prob.Description + " not updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update Failed - Contact Tech Support"));
            }
        }
Exemplo n.º 5
0
        public void ProblemVMUpdateShouldReturnTrue()
        {
            ProblemViewModel vm = new ProblemViewModel();

            // simulate user 1 getting an Problem
            vm.GetByID("563d30b53dd4dd34b4c05cc2"); // problems' id
            vm.Description = "Device Not Plugged In";
            int rowsUpdated = vm.Update();

            //user 1 makes update
            Assert.IsTrue(rowsUpdated == 1);
        }
Exemplo n.º 6
0
 public IHttpActionResult Put(ProblemViewModel prob)
 {
     try
     {
         if (prob.Update() == 1)
         {
             return(Ok("Problem " + prob.Description + " updated!"));
         }
         else if (prob.Update() == -1)
         {
             return(Ok("Problem " + prob.Description + " not updated!"));
         }
         else
         {
             return(Ok("Data is stale for " + prob.Description + " data not updated!"));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Update failed - " + ex.Message));
     }
 }
Exemplo n.º 7
0
        public void ProblemVMUpdateTwiceShouldReturnNegative2()
        {
            ProblemViewModel vm  = new ProblemViewModel();
            ProblemViewModel vm2 = new ProblemViewModel();

            // simulate 2 users getting an Problem
            vm.GetByID("563d30b53dd4dd34b4c05cc2");  // problems' id
            vm2.GetByID("563d30b53dd4dd34b4c05cc2"); // problems' id
            vm.Description = "Device Not Plugged In";
            int rowsUpdated = vm.Update();

            if (rowsUpdated == 1)
            {
                rowsUpdated = vm2.Update();
            }
            Assert.IsTrue(rowsUpdated == -2);
        }