public void FamilyService_Add_Throws_On_Null_Family()
        {
            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<ArgumentNullException>(() => _service.Add(null));
        }
        public void Add_Family_ThrowException_When_Family_Is_Null()
        {
            //Arrange.
            var mockRepo = new Mock <IFamilyRepository>();

            mockRepo.Setup(c => c.SaveOrUpdate(It.IsAny <Family>()));

            var service = new FamilyService(mockRepo.Object);

            //Act.
            service.Add(null);
        }
        public void Add_Family_Is_SaveOrUpdate_Called()
        {
            //Arrange.
            var mockRepo = new Mock <IFamilyRepository>();

            mockRepo.Setup(c => c.SaveOrUpdate(It.IsAny <Family>()));

            var service = new FamilyService(mockRepo.Object);

            //Act.
            service.Add(new Family());

            //Assert.
            mockRepo.Verify();
        }
        public void FamilyService_Add_Calls_Repository_Add_Method_With_The_Same_Family_Object_It_Recieved()
        {
            // Create test data
            var newFamily = new Family
                                {
                                    WifeId = TestConstants.ID_WifeId,
                                    HusbandId = TestConstants.ID_HusbandId
                                };

            //Create Mock
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Family>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Act
            _service.Add(newFamily);

            //Assert
            mockRepository.Verify(r => r.Add(newFamily));
        }
        public void FamilyService_Add_Calls_UnitOfWork_Commit_Method()
        {
            // Create test data
            var newFamily = new Family
                                    {
                                        WifeId = TestConstants.ID_WifeId,
                                        HusbandId = TestConstants.ID_HusbandId
                                    };

            //Create Mock
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Family>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Act
            _service.Add(newFamily);

            //Assert
            _mockUnitOfWork.Verify(db => db.Commit());
        }
        public ActionResult EditSave(Employee employee)
        {
            if (employee.Name == null)
            {
                return(Content("请输入姓名!"));
            }
            if (employee.nl == 0)
            {
                return(Content("请输入年龄!"));
            }
            if (employee.xb == null)
            {
                return(Content("请选择性别!"));
            }

            string strZp   = Request.Form["strZp"].ToString();
            string strSfzt = Request.Form["strSfzt"].ToString();

            HttpFileCollectionBase files    = Request.Files;
            HttpPostedFileBase     FileSfzt = files["sfzt"];
            string FileName = FileSfzt.FileName; //上传的原文件名

            if (FileName != "")                  //换了图片
            {
                string guidSfzt = "";
                if (FileName != null && FileName != "")
                {
                    string FileType = FileName.Substring(FileName.LastIndexOf(".") + 1);                    //得到文件的后缀名
                    guidSfzt = employee.Code + "-SFZ-" + System.Guid.NewGuid().ToString() + "." + FileType; //得到重命名的文件名
                    FileSfzt.SaveAs(Server.MapPath("/Upload/") + guidSfzt);                                 //保存操作
                }
                employee.sfzt = guidSfzt;
            }
            else
            {
                employee.sfzt = strSfzt;
            }


            HttpPostedFileBase FileZp     = files["Zp"];
            string             FileNameZp = FileZp.FileName; //上传的原文件名

            if (FileNameZp != "")                            //换了图片
            {
                string guidZp = "";
                if (FileNameZp != null && FileNameZp != "")
                {
                    string FileType = FileNameZp.Substring(FileNameZp.LastIndexOf(".") + 1);             //得到文件的后缀名
                    guidZp = employee.Code + "-ZP-" + System.Guid.NewGuid().ToString() + "." + FileType; //得到重命名的文件名
                    FileZp.SaveAs(Server.MapPath("/Upload/") + guidZp);                                  //保存操作
                }
                employee.zp = guidZp;
            }
            else
            {
                employee.zp = strZp;
            }

            string jtStr = Request.Form["jtStr"].ToString();
            string gzStr = Request.Form["gzStr"].ToString();
            string pxStr = Request.Form["pxStr"].ToString();

            JavaScriptSerializer js = new JavaScriptSerializer();
            //处理家庭成员
            int           jtCount = FamilyService.GetRecordCoutn(u => u.EmployeeID == employee.ID);
            List <Family> listJt  = js.Deserialize <List <Family> >(jtStr);

            for (int j = 0; j < listJt.Count; j++)
            {
                Family family1 = listJt[j];
                family1.Employee     = employee;
                family1.EmployeeID   = employee.ID;
                family1.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                family1.ModifiedTIme = DateTime.Now;
                if (family1.Code == null)
                {
                    family1      = initFamily(family1);
                    family1.Code = employee.Code + "-F" + (jtCount + 1).ToString();
                    FamilyService.Add(family1);
                }
                else
                {
                    family1.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                    family1.ModifiedTIme = DateTime.Now;
                    FamilyService.Update(family1);
                }
            }
            FamilyService.SaveChanges();

            //处理工作经历
            int gzCount = ExperienceService.GetRecordCoutn(u => u.EmployeeID == employee.ID);
            List <Experience> listGz = js.Deserialize <List <Experience> >(gzStr);

            for (int i = 0; i < listGz.Count; i++)
            {
                Experience experience = listGz[i];
                experience.Employee     = employee;
                experience.EmployeeID   = employee.ID;
                experience.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                experience.ModifiedTIme = DateTime.Now;
                if (experience.Code == null)
                {
                    experience      = initExperience(experience);
                    experience.Code = employee.Code + "-E" + (gzCount + 1).ToString();
                    ExperienceService.Add(experience);
                }
                else
                {
                    experience.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                    experience.ModifiedTIme = DateTime.Now;
                    ExperienceService.Update(experience);
                }
            }
            //处理培训经历
            int          pxCount = TrainService.GetRecordCoutn(u => u.EmployeeID == employee.ID);
            List <Train> listPx  = js.Deserialize <List <Train> >(pxStr);

            for (int i = 0; i < listPx.Count; i++)
            {
                Train train = listPx[i];
                train.Employee     = employee;
                train.EmployeeID   = employee.ID;
                train.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                train.ModifiedTIme = DateTime.Now;
                if (train.Code == null)
                {
                    train      = initTrain(train);
                    train.Code = employee.Code + "-T" + (pxCount + 1).ToString();
                    TrainService.Add(train);
                }
                else
                {
                    train.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
                    train.ModifiedTIme = DateTime.Now;
                    TrainService.Update(train);
                }
            }

            employee.ModifiedBy   = LoginUserInfo == null ? 0 : LoginUserInfo.ID;
            employee.ModifiedTIme = DateTime.Now;
            if (EmployeeService.Update(employee))
            {
                TrainService.SaveChanges();
                ExperienceService.SaveChanges();
                FamilyService.SaveChanges();
                EmployeeService.SaveChanges();
                return(Content("ok"));
            }

            return(Content("修改失败了!"));
        }