Ejemplo n.º 1
0
        public async Task EnrollAsyncTest()
        {
            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => { return(new DateTime(2018, 3, 15, 16, 00, 00)); };

                var job = new Job
                {
                    Name         = "Job",
                    WorkLocation = "WorkLocation",
                };
                var jobPo = new PrivateObject(job);

                var plan = new RecruitmentPlan("Title", "Recruitment", new DateTime(2018, 3, 15, 17, 00, 00));
                jobPo.SetProperty(nameof(job.Plan), plan);

                var manager = new ApplicationFormManager(new StubApplicationFormStore(), new StubFileStore());
                var form    = new ApplicationForm(job, new StubPerson());
                var formPo  = new PrivateObject(form);
                formPo.SetProperty(nameof(form.HeadImageFile), "HeadImageFile");
                formPo.SetProperty(nameof(form.AcademicCertFiles), "Files");
                try
                {
                    await manager.EnrollAsync(form);

                    Assert.AreEqual(new DateTime(2018, 3, 15, 16, 00, 00), form.WhenCreated);
                }
                catch (InvalidOperationException)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create new recruitment plan in databse.
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public async Task CreateAsync(RecruitmentPlan plan)
        {
            if (plan == null)
            {
                throw new System.ArgumentNullException(nameof(plan));
            }

            this.set.Add(plan);
            await this.db.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public Task CreateAsync(RecruitmentPlan plan)
        {
            var last   = this.innerList.OrderBy(r => r.Id).LastOrDefault();
            var lastid = last == null ? 0 : last.Id;

            new PrivateObject(plan).SetProperty(nameof(plan.Id), lastid + 1);
            this.innerList.Add(plan);

            return(Task.FromResult(0));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(RecruitmentPlanEditViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(model));
            }

            RecruitmentPlan plan = new RecruitmentPlan(model.Title, model.Recruitment, model.ExpirationDate);

            await this.planManager.CreateAsync(plan);

            return(RedirectToAction("Detail", new { id = plan.Id }));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public async Task NotifyAuditCompleteAsync(RecruitmentPlan plan)
        {
            if (plan == null)
            {
                throw new ArgumentNullException(nameof(plan));
            }

            foreach (var job in plan.Jobs)
            {
                foreach (var form in job.ApplicationForms)
                {
                    await this.smsService.SendAsync(new string[] { form.Person.Mobile }, completeAuditMessageTemplateId, form.Person.DisplayName, form.Job.Plan.Title, (form.AuditFlag ? "已通过" : "未通过"));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Delete recruitment plan from db.
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public async Task DeleteAsync(RecruitmentPlan plan)
        {
            if (plan == null)
            {
                throw new System.ArgumentNullException(nameof(plan));
            }

            var current = await this.FindByIdAsync(plan.Id);

            if (current != null)
            {
                this.set.Remove(current);
                await this.db.SaveChangesAsync();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Update recruitment plan
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public async Task UpdateAsync(RecruitmentPlan plan)
        {
            if (plan == null)
            {
                throw new System.ArgumentNullException(nameof(plan));
            }

            RecruitmentPlan old = await this.FindByIdAsync(plan.Id);

            if (old != null)
            {
                var entry = this.db.Entry <RecruitmentPlan>(old);
                entry.CurrentValues.SetValues(plan);
                entry.Property(p => p.WhenCreated).IsModified = false;

                await this.db.SaveChangesAsync();
            }
        }
Ejemplo n.º 8
0
        public async Task CompleteAuditAsyncTest()
        {
            //
            var plan    = new RecruitmentPlan("Title", "Recruitment", DateTime.Now.AddDays(0));
            var manager = new RecruitmentPlanManager(new StubRecruitmentPlanStore());
            var job     = new Job()
            {
                Name = "Job",
            };

            plan.Jobs.Add(job);
            var form = new ApplicationForm(job, new StubPerson());

            job.ApplicationForms.Add(form);
            new PrivateObject(plan).SetProperty(nameof(plan.EnrollExpirationDate), DateTime.Now);
            new PrivateObject(plan).SetProperty(nameof(plan.WhenPublished), DateTime.Now);

            await manager.CompleteAuditAsync(plan);

            Assert.IsNotNull(form.WhenAuditComplete);
            Assert.IsNotNull(plan.WhenAuditCommited);
        }
Ejemplo n.º 9
0
        public async Task CommitAsyncTest()
        {
            var job = new Job
            {
                Name         = "Job",
                WorkLocation = "WorkLocation",
            };
            var jobPo = new PrivateObject(job);

            var plan = new RecruitmentPlan("Title", "Recruitment", new DateTime(2018, 3, 15, 17, 00, 00));

            jobPo.SetProperty(nameof(job.Plan), plan);
            var manager = new ApplicationFormManager(new StubApplicationFormStore(), new StubFileStore());

            //准备报名表
            var form   = new ApplicationForm(job, new StubPerson());
            var formPo = new PrivateObject(form);

            formPo.SetProperty(nameof(form.HeadImageFile), "HeadImageFile");
            formPo.SetProperty(nameof(form.AcademicCertFiles), "Files");

            var form1   = new ApplicationForm(job, new StubPerson());
            var form1Po = new PrivateObject(form1);

            form1Po.SetProperty(nameof(form1.HeadImageFile), "HeadImageFile");
            form1Po.SetProperty(nameof(form1.AcademicCertFiles), "Files");

            //创建
            await manager.EnrollAsync(form);

            await manager.EnrollAsync(form1);

            //首次提交
            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2018, 3, 15, 16, 0, 0);

                await manager.CommitAsync(form);

                Assert.AreEqual(new DateTime(2018, 3, 15, 16, 0, 0), form.WhenCommited.Value);
                //重复提交
                try
                {
                    await manager.CommitAsync(form);

                    Assert.Fail("重复提交未引发异常");
                }
                catch (Exception)
                {
                    //Test Pass
                }
            }

            //报名时间已过提交
            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2018, 3, 15, 18, 0, 0);
                try
                {
                    await manager.CommitAsync(form1);

                    Assert.Fail("超时提交未引发异常");
                }
                catch (InvalidOperationException)
                {
                    //Test Pass
                }
            }

            //已审查的报名表退回再提交(晚于截止时间)
            await manager.FileReviewAsync(form, false, "FileReviewedBy");

            await manager.ReturnBackAsync(form);

            using (ShimsContext.Create())
            {
                ShimDateTime.NowGet = () => new DateTime(2018, 3, 15, 18, 0, 0);
                await manager.CommitAsync(form);

                Assert.AreEqual(new DateTime(2018, 3, 15, 18, 0, 0), form.WhenCommited.Value);
                Assert.IsFalse(form.WhenFileReviewed.HasValue);
                Assert.IsFalse(form.FileReviewAccepted.HasValue);
                Assert.IsNull(form.FileReviewedBy);
            }
        }
Ejemplo n.º 10
0
 public Task UpdateAsync(RecruitmentPlan plan)
 {
     //do nothing here.
     return(Task.FromResult(0));
 }
Ejemplo n.º 11
0
 public Task DeleteAsync(RecruitmentPlan plan)
 {
     this.innerList.Remove(plan);
     return(Task.FromResult(0));
 }