コード例 #1
0
        public void StudentViewModelReturnByLastNameShouldReturnAllData()
        {
            StudentViewModel vm = new StudentViewModel();

            vm.Lastname = "Peterson-Katz";
            vm.GetByLastName();
            Assert.IsTrue(vm.Firstname.Length > 0); // means student has data
        }
コード例 #2
0
        public void Student_GetByLastNameTest()
        {
            StudentViewModel vm = new StudentViewModel {
                LastName = "Pet "
            };

            vm.GetByLastName();
            Assert.NotNull(vm.FirstName);
        }
コード例 #3
0
        public void Student_DeleteTest()
        {
            StudentViewModel vm = new StudentViewModel {
                LastName = "Desjardins"
            };

            vm.GetByLastName();
            int studentsDeleted = vm.Delete();

            Assert.True(studentsDeleted == 1);
        }
コード例 #4
0
        public void Student_UpdateTest()
        {
            StudentViewModel vm = new StudentViewModel {
                LastName = "Desjardins"
            };

            vm.GetByLastName(); // student just added
            vm.PhoneNo = vm.PhoneNo == "(555)555-5551" ? "(555)555-5552" : "(555)555-5551";
            int studentsUpdated = vm.Update();

            Assert.True(studentsUpdated > 0);
        }
コード例 #5
0
 public IHttpActionResult Get(string name)
 {
     try
     {
         StudentViewModel stu = new StudentViewModel();
         stu.Lastname = name;
         stu.GetByLastName();
         return(Ok(stu));
     }
     catch (Exception ex)
     {
         return(BadRequest("Retrieved failed - " + ex.Message));
     }
 }
コード例 #6
0
        public void StudentViewModelUpdateTwiceShouldReturnStaleInt()
        {
            StudentViewModel vm1 = new StudentViewModel();
            StudentViewModel vm2 = new StudentViewModel();

            vm1.Lastname = "Peterson-Katz";
            vm2.Lastname = "Peterson-Katz";
            vm1.GetByLastName();
            vm2.GetByLastName();
            vm1.Phoneno = "(555)555-5555";
            vm2.Phoneno = "(555)555-4414";
            if (vm1.Update() == 1)
            {
                Assert.IsTrue(vm2.Update() == -2); // -2 represents a stale status
            }
            else
            {
                Assert.Fail();
            }
        }
コード例 #7
0
        public void Student_ConcurrencyTest()
        {
            StudentViewModel vm1 = new StudentViewModel();
            StudentViewModel vm2 = new StudentViewModel();

            vm1.LastName = "Desjardins";
            vm2.LastName = "Desjardins";
            vm1.GetByLastName();
            vm2.GetByLastName();
            vm1.Email = (vm1.Email.IndexOf(".ca") > 0) ? " [email protected]" : "*****@*****.**";


            if (vm1.Update() == 1)
            {
                vm2.Email = "*****@*****.**";
                Assert.True(vm2.Update() == -2);
            }
            else
            {
                Assert.True(false);
            }
        }