Inheritance: Record
 public void create_post_invalid_throws_exception()
 {
     //Arrange
     var person = new Person();
     _serv.Setup(p => p.Create(person, "UnitTest")).Returns(person);
     fakeform.Remove("firstname1");
     _ctrlr.ValueProvider = fakeform.ToValueProvider();
     //Act
     _ctrlr.Create(person, "UnitTest");
     //Assert
 }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="per"></param>
 /// <param name="sign"></param>
 public signinView(Person per, Signin sign)
 {
     p = per;
     w = p.Worker;
     s = sign;
     ID = s.ID;
     firstname1 = p == null ? null : p.firstname1;
     firstname2 = p == null ? null : p.firstname2;
     lastname1 = p == null ? null : p.lastname1;
     lastname2 = p == null ? null : p.lastname2;
     dateforsignin = s.dateforsignin;
     dwccardnum = s.dwccardnum;
     signinID = s.ID;
     dateupdated = s.dateupdated;
     datecreated = s.datecreated;
     Createdby = s.Createdby;
     Updatedby = s.Updatedby;
     imageID = p == null ? null : p.Worker.ImageID;
     expirationDate = p == null ? DateTime.MinValue : p.Worker.memberexpirationdate;
     memberStatus = p == null ? 0 : p.Worker.memberStatus;
 }
示例#3
0
        public ActionResult Create(Person person, string userName)
        {
            Person newperson = null;
            UpdateModel(person);
            newperson = personService.Create(person, userName);

            return Json(new
            {
                sNewRef = _getTabRef(newperson),
                sNewLabel = _getTabLabel(newperson),
                iNewID = (newperson == null ? 0 : newperson.ID)
            },
            JsonRequestBehavior.AllowGet);
        }
示例#4
0
 public ActionResult Create()
 {
     var _model = new Person();
     _model.gender = Lookups.getDefaultID(LCategory.gender);
     _model.active = true;
     return PartialView(_model);
 }
 public void PersonController_edit_post_valid_updates_model_returns_JSON()
 {
     //Arrange
     _serv = new Mock<IPersonService>();
     int testid = 4242;
     FormCollection fakeform = new FormCollection();
     fakeform.Add("ID", testid.ToString());
     fakeform.Add("firstname1", "blah");     //Every required field must be populated,
     fakeform.Add("lastname1", "UnitTest");  //or result will be null.
     fakeform.Add("gender", "47");
     Person fakeperson = new Person();
     Person savedperson = new Person();
     string user = "";
     _serv.Setup(p => p.Get(testid)).Returns(fakeperson);
     _serv.Setup(x => x.Save(It.IsAny<Person>(),
                                   It.IsAny<string>())
                                  ).Callback((Person p, string str) =>
                                         {
                                             savedperson = p;
                                             user = str;
                                         });
     var _ctrlr = new PersonController(_serv.Object, lcache.Object);
     _ctrlr.SetFakeControllerContext();
     _ctrlr.ValueProvider = fakeform.ToValueProvider();
     //Act
     var result = _ctrlr.Edit(testid, "UnitTest") as JsonResult;
     //Assert
     IDictionary<string, object> data = new RouteValueDictionary(result.Data);
     Assert.AreEqual("OK", data["status"]);
     Assert.AreEqual(fakeperson, savedperson);
     Assert.AreEqual(savedperson.firstname1, "blah");
     Assert.AreEqual(savedperson.lastname1, "UnitTest");
     Assert.AreEqual(savedperson.gender, 47);
 }
 public void PersonController_edit_post_invalid_throws_exception()
 {
     //Arrange
     var person = new Person();
     int testid = 12345;
     //
     // Mock service and setup SavePerson mock
     _serv.Setup(p => p.Save(person, "UnitTest"));
     _serv.Setup(p => p.Get(testid)).Returns(person);
     //
     // Mock HttpContext so that ModelState and FormCollection work
     fakeform.Remove("firstname1");
     _ctrlr.ValueProvider = fakeform.ToValueProvider();
     //
     //Act
     _ctrlr.Edit(testid, "UnitTest");
     //Assert
     //IDictionary<string, object> data = new RouteValueDictionary(result.Data);
     //Assert.AreEqual("Controller UpdateModel failure on recordtype: person", data["status"]);
 }
 public void PersonController_edit_get_returns_person()
 {
     //Arrange
     _serv = new Mock<IPersonService>();
     int testid = 4242;
     Person fakeperson = new Person();
     _serv.Setup(p => p.Get(testid)).Returns(fakeperson);
     var _ctrlr = new PersonController(_serv.Object, lcache.Object);
     //Act
     var result = (PartialViewResult)_ctrlr.Edit(testid);
     //Assert
     Assert.IsInstanceOfType(result.ViewData.Model, typeof(Person));
 }
 public void PersonController_create_post_valid_returns_JSON()
 {
     //Arrange
     var person = new Person();
     _serv.Setup(p => p.Create(person, "UnitTest")).Returns(person);
     _ctrlr.ValueProvider = fakeform.ToValueProvider();
     //Act
     var result = (JsonResult)_ctrlr.Create(person, "UnitTest");
     //Assert
     IDictionary<string, object> data = new RouteValueDictionary(result.Data);
     Assert.AreEqual(12345, data["iNewID"]);
     Assert.AreEqual("Ronald Reagan", data["sNewLabel"]);
     Assert.AreEqual("/Person/Edit/12345", data["sNewRef"]);
 }
示例#9
0
 public asiView(Person per, ActivitySignin sign)
     : base(per, sign)
 {
 }
 public void edit_get_returns_worker()
 {
     //Arrange
     var _worker = new Worker();
     var _person = new Person();
     int testid = 4242;
     Person fakeperson = new Person();
     _wserv.Setup(p => p.Get(testid)).Returns(_worker);
     //Act
     var result = (PartialViewResult)_ctrlr.Edit(testid);
     //Assert
     Assert.IsInstanceOfType(result.ViewData.Model, typeof(Worker));
 }
 public void WorkerController_create_post_valid_returns_json()
 {
     //Arrange
     var _worker = new Worker();
     var _person = new Person();
     //
     _wserv.Setup(p => p.Create(_worker, "UnitTest")).Returns(_worker);
     _pserv.Setup(p => p.Create(_person, "UnitTest")).Returns(_person);
     _ctrlr.ValueProvider = fakeform.ToValueProvider();
     //Act
     var result = _ctrlr.Create(_worker, "UnitTest", null) as JsonResult;
     Assert.IsInstanceOfType(result, typeof(JsonResult));
     Assert.AreEqual("{ iNewID = 12345, jobSuccess = True }",
                     result.Data.ToString());
 }
        public void edit_post_valid_updates_model_redirects_to_index()
        {
            //Arrange

            int testid = 4242;
            Mock<HttpPostedFileBase> image = new Mock<HttpPostedFileBase>();
            FormCollection fakeform = _fakeCollection(testid);

            Worker fakeworker = new Worker();
            Worker savedworker = new Worker();
            Person fakeperson = new Person();
            fakeworker.Person = fakeperson;

            string user = "******";
            _wserv.Setup(p => p.Get(testid)).Returns(fakeworker);
            _pserv.Setup(p => p.Get(testid)).Returns(fakeperson);
            _wserv.Setup(x => x.Save(It.IsAny<Worker>(),
                                          It.IsAny<string>())
                                         ).Callback((Worker p, string str) =>
                                         {
                                             savedworker = p;
                                             user = str;
                                         });

            _ctrlr.SetFakeControllerContext();
            _ctrlr.ValueProvider = fakeform.ToValueProvider();
            //Act
            var result = _ctrlr.Edit(testid, fakeworker, "UnitTest", null) as PartialViewResult;
            //Assert
            //Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual(fakeworker, savedworker);
            Assert.AreEqual(savedworker.height, "UnitTest");
            Assert.AreEqual(savedworker.height, "UnitTest");
        }
示例#13
0
        public bool personValidate(Person _per)
        {
            string prefix = "person" + _per.ID + "-";
            var selectedTab = WaitForElement(By.CssSelector("li.person.ui-tabs-selected"));
            Assert.IsNotNull(selectedTab, "Failed to find Person selected tab element");
            IWebElement tabAnchor = selectedTab.FindElement(By.CssSelector("a"));
            Assert.IsNotNull(tabAnchor, "Failed to find Person selected tab element anchor");
            var name = _per.firstname1 + " " + (_per.firstname2 != null ? _per.firstname2 + " " : "") + _per.lastname1 + (_per.lastname2 != null ? " " + _per.lastname2: "");

            Assert.IsTrue(tabAnchor.Text == name, "Person anchor label doesn't match person name");

            Assert.AreEqual(_per.firstname1, WaitForElement(By.Id(prefix + "firstname1")).GetAttribute("value"));
            Assert.AreEqual(_per.firstname2 == null ? "" : _per.firstname2, WaitForElement(By.Id(prefix + "firstname2")).GetAttribute("value"));
            Assert.AreEqual(_per.lastname1, WaitForElement(By.Id(prefix + "lastname1")).GetAttribute("value"));
            Assert.AreEqual(_per.lastname2 == null ? "" : _per.lastname2, WaitForElement(By.Id(prefix + "lastname2")).GetAttribute("value"));
            Assert.AreEqual(_per.address1, WaitForElement(By.Id(prefix + "address1")).GetAttribute("value"));
            Assert.AreEqual(_per.address2 == null ? "" : _per.address2, WaitForElement(By.Id(prefix + "address2")).GetAttribute("value"));
            Assert.AreEqual(_per.phone, WaitForElement(By.Id(prefix + "phone")).GetAttribute("value"));
            Assert.AreEqual(_per.city, WaitForElement(By.Id(prefix + "city")).GetAttribute("value"));
            Assert.AreEqual(_per.genderother == null ? "" : _per.genderother, WaitForElement(By.Id(prefix + "genderOther")).GetAttribute("value"));
            Assert.AreEqual(_per.state, WaitForElement(By.Id(prefix + "state")).GetAttribute("value"));
            Assert.AreEqual(_per.zipcode, WaitForElement(By.Id(prefix + "zipcode")).GetAttribute("value"));
            Assert.AreEqual(_per.active, WaitForElement(By.Id(prefix + "active")).Selected);
            Assert.AreEqual(_per.gender.ToString(), GetOptionValue(By.Id(prefix + "gender")));
            return true;
        }
示例#14
0
        public bool personCreate(Person _per)
        {
            string prefix = "person" + _per.ID + "-";
            _per.firstname1 = RandomString(4);
            _per.lastname1 = RandomString(8);
            WaitThenClickElement(By.Id("menulinkperson"));
            WaitThenClickElement(By.Id("personCreateTab"));
            WaitThenClickElement(By.Id(prefix + "firstname1"));
            _d.FindElement(By.Id(prefix + "firstname1")).Clear();
            _d.FindElement(By.Id(prefix + "firstname1")).SendKeys(_per.firstname1);
            if (_per.firstname2 != null)
            {
                _d.FindElement(By.Id(prefix + "firstname2")).Clear();
                _d.FindElement(By.Id(prefix + "firstname2")).SendKeys(_per.firstname2);
            }
            _d.FindElement(By.Id(prefix + "lastname1")).Clear();
            _d.FindElement(By.Id(prefix + "lastname1")).SendKeys(_per.lastname1);
            if (_per.lastname2 != null)
            {
                _d.FindElement(By.Id(prefix + "lastname2")).Clear();
                _d.FindElement(By.Id(prefix + "lastname2")).SendKeys(_per.lastname2);
            }
            _d.FindElement(By.Id(prefix + "address1")).Clear();
            _d.FindElement(By.Id(prefix + "address1")).SendKeys(_per.address1);
            _d.FindElement(By.Id(prefix + "address2")).Clear();
            _d.FindElement(By.Id(prefix + "address2")).SendKeys(_per.address2);
            _d.FindElement(By.Id(prefix + "phone")).Clear();
            _d.FindElement(By.Id(prefix + "phone")).SendKeys(_per.phone);
            SelectOption(By.Id(prefix + "gender"), MacheteLookup.cache.First(c => c.category == "gender" && c.ID == _per.gender).text_EN);
            _d.FindElement(By.Id(prefix + "city")).Clear();
            _d.FindElement(By.Id(prefix + "city")).SendKeys(_per.city);
            if (_per.genderother != null)
            {
                _d.FindElement(By.Id(prefix + "genderOther")).Clear();
                _d.FindElement(By.Id(prefix + "genderOther")).SendKeys(_per.genderother);
            }
            WaitForElement(By.Id(prefix + "state")).Clear();
            WaitForElement(By.Id(prefix + "state")).SendKeys(_per.state);
            if (!_per.active)
                WaitForElement(By.Id(prefix + "active")).Click();
            WaitForElement(By.Id(prefix + "zipcode")).Clear();
            WaitForElement(By.Id(prefix + "zipcode")).SendKeys(_per.zipcode);
            WaitThenClickElement(By.Id(prefix + "SaveBtn"));

            //
            //WaitForElement(By.Id("personSearchBox")).SendKeys(_per.lastname1);
            //WaitForElementValue(By.XPath("//table[@id='personTable']/tbody/tr/td[4]"), _per.lastname1);
            //WaitAndDoubleClick(By.XPath("//table[@id='personTable']/tbody/tr/td[6]"));

            var selectedTab = WaitForElement(By.CssSelector("li.person.ui-tabs-selected"));
            IWebElement tabAnchor = selectedTab.FindElement(By.CssSelector("a"));
            _per.ID = Convert.ToInt32(tabAnchor.GetAttribute("recordid"));
            //
            return true;
        }
示例#15
0
 private string _getTabLabel(Person per)
 {
     if (per != null) return per.fullName();
     else return null;
 }
 public void DeletePerson()
 {
     //
     //Arrange
     Person _p = (Person)Records.person.Clone();
     _repo = new Mock<IPersonRepository>();
     _uow = new Mock<IUnitOfWork>();
     _lcache = new Mock<ILookupCache>();
     string user = "******";
     int id = 1;
     Person dp = new Person();
     _repo.Setup(r => r.Delete(It.IsAny<Person>())).Callback((Person p) => { dp = p;  });
     _repo.Setup(r => r.GetById(id)).Returns(_p);
     var _serv = new PersonService(_repo.Object, _uow.Object, _lcache.Object);
     //
     //Act
     _serv.Delete(id, user);
     //
     //Assert
     Assert.AreEqual(dp, _p);
 }
示例#17
0
 private string _getTabRef(Person per)
 {
     if (per != null) return "/Person/Edit/" + Convert.ToString(per.ID);
     else return null;
 }
示例#18
0
 public wsiView(Person per, WorkerSignin sign)
     : base(per, sign)
 {
     lotterySequence = sign.lottery_sequence;
     englishlevel = p == null ? 0 : p.Worker.englishlevelID;
     waid = sign.WorkAssignmentID;
     skill1 = p == null ? null : p.Worker.skill1;
     skill2 = p == null ? null : p.Worker.skill2;
     skill3 = p == null ? null : p.Worker.skill3;
     typeOfWorkID = p == null ? 0 : p.Worker.typeOfWorkID;
 }