public void Execute_DoesNotAddFundingsToEnrollment(bool enrollmentHasFundingsReference)
        {
            Enrollment enrollment;

            using (var context = new TestHedwigContextProvider().Context)
            {
                enrollment = EnrollmentHelper.CreateEnrollment(context);
                FundingHelper.CreateFunding(context, enrollment: enrollment);
            }

            if (!enrollmentHasFundingsReference)
            {
                enrollment.Fundings = null;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                // Only attach found entity to avoid attaching the entire object graph
                // (which would find & attach the fundings navigation property)
                context.Attach(context.Find(enrollment.GetType(), enrollment.Id));
                var _serviceProvider = new Mock <IServiceProvider>();
                _serviceProvider.Setup(sp => sp.GetService(typeof(IEnumerable <IValidationRule <Funding> >)))
                .Returns(new List <IValidationRule <Funding> >());
                var _validator = new NonBlockingValidator(_serviceProvider.Object);
                var _fundings  = new FundingRepository(context);

                // when
                var rule = new FundingsAreValid(_validator, _fundings);
                rule.Execute(enrollment, new NonBlockingValidationContext());

                // then
                Assert.Equal(enrollmentHasFundingsReference, enrollment.Fundings != null);
            }
        }
Beispiel #2
0
        public void DeleteEnrollment_DeletesDanglingSubObjects()
        {
            using (var context = new TestHedwigContextProvider().Context)
            {
                var enrollment = new Enrollment();
                var child      = new Child();
                var funding    = new Funding();
                enrollment.Id        = 1;
                funding.Enrollment   = enrollment;
                funding.EnrollmentId = enrollment.Id;
                enrollment.Child     = child;

                var mapper = new MapperConfiguration(opts =>
                {
                    opts.AddProfile(new EnrollmentProfile());
                    opts.AddProfile(new FundingProfile());
                    opts.AddProfile(new ChildProfile());
                    opts.AddProfile(new FamilyProfile());
                    opts.AddProfile(new SiteProfile());
                }).CreateMapper();
                var enrollmentRepo = new EnrollmentRepository(context, mapper);
                var fundingRepo    = new FundingRepository(context);
                enrollmentRepo.AddEnrollment(enrollment);

                Assert.Equal(EntityState.Added, context.Entry(enrollment).State);

                enrollmentRepo.DeleteEnrollment(enrollment);

                Assert.Equal(EntityState.Detached, context.Entry(funding).State);
                Assert.Equal(EntityState.Added, context.Entry(child).State);
                Assert.Equal(EntityState.Detached, context.Entry(enrollment).State);
            }
        }
        public void Execute_DoesNotAddEnrollmentToFunding(bool fundingHasEnrollmentReference)
        {
            Funding funding;

            using (var context = new TestHedwigContextProvider().Context)
            {
                funding = FundingHelper.CreateFunding(context);
            }

            if (!fundingHasEnrollmentReference)
            {
                funding.Enrollment = null;
            }

            using (var context = new TestHedwigContextProvider().Context)
            {
                // Only attach found entity to avoid attaching the entire object graph
                // (which would find & attach the enrollment navigation property)
                context.Attach(context.Find(funding.GetType(), funding.Id));

                var _serviceProvider  = new Mock <IServiceProvider>();
                var _validator        = new NonBlockingValidator(_serviceProvider.Object);
                var _fundings         = new FundingRepository(context);
                var _enrollments      = new EnrollmentRepository(context);
                var _reportingPeriods = new ReportingPeriodRepository(context);

                // when
                var rule = new FundingTimelinesAreValid(_fundings, _enrollments, _reportingPeriods);
                rule.Execute(funding, new NonBlockingValidationContext());

                // then
                Assert.Equal(fundingHasEnrollmentReference, funding.Enrollment != null);
            }
        }
        public void DeleteEnrollment_DeletesDanglingSubObjects()
        {
            using (var context = new TestHedwigContextProvider().Context)
            {
                var enrollment = new Enrollment();
                var child      = new Child();
                var funding    = new Funding();
                enrollment.Id        = 1;
                funding.Enrollment   = enrollment;
                funding.EnrollmentId = enrollment.Id;
                enrollment.Child     = child;

                var enrollmentRepo = new EnrollmentRepository(context);
                var fundingRepo    = new FundingRepository(context);
                enrollmentRepo.AddEnrollment(enrollment);

                Assert.Equal(EntityState.Added, context.Entry(enrollment).State);

                enrollmentRepo.DeleteEnrollment(enrollment);

                Assert.Equal(EntityState.Detached, context.Entry(funding).State);
                Assert.Equal(EntityState.Added, context.Entry(child).State);
                Assert.Equal(EntityState.Detached, context.Entry(enrollment).State);
            }
        }
Beispiel #5
0
 public FundingProcessor(FundingRepository repository)
 {
     _repository = repository;
 }
Beispiel #6
0
        /// <summary>
        /// 回答新闻的互动问题
        /// </summary>
        /// <returns></returns>
        public static Result <int> Add(QuestionFeedbackModel ent)
        {
            var result = new Result <int>();

            if (ent.UserId <= 0 || ent.NewsId <= 0)
            {
                result.Message = "无效的参数";
                return(result);
            }
            if (ent.QuestionOption.IsNullOrEmpty())
            {
                result.Message = "提交的互动问题不能为空";
                return(result);
            }
            var feedback = ent.QuestionOption.JsonDeserialize <List <QuestionOptionRequest> >();

            if (feedback.IsNullOrEmpty())
            {
                result.Message = "提交的互动问题无效";
                return(result);
            }
            if (QuestionFeedbackRepository.Exists(ent.NewsId, ent.UserId))
            {
                result.Message = "请勿重复提交问卷";
                return(result);
            }
            var memberInfo = MemberRepository.Get(ent.UserId);

            if (memberInfo == null)
            {
                result.Message = "会员信息无效";
                return(result);
            }
            decimal score = 0;

            feedback.ForEach(item =>
            {
                var questionInfo = QuestionRepository.Get(item.QId);
                if (questionInfo != null)
                {
                    ent.QuestionId     = item.QId;
                    ent.QuestionOption = item.Text;
                    var iRet           = QuestionFeedbackRepository.Add(ent);
                    if (iRet > 0)
                    {
                        score      += questionInfo.QuestionScore;
                        result.Code = ResultCode.Success;
                    }
                }
            });
            //修改用户积分
            memberInfo.TotalScore += score;
            MemberRepository.Update(memberInfo);
            //增加账户明细
            FundingRepository.Add(new MemberFundingModel()
            {
                UserId     = ent.UserId,
                OpType     = OperationType.QuestionFeedback,
                ChangeType = ScoreChangeType.Increase,
                OpValue    = score,
                Remark     = OperationType.QuestionFeedback.Description(),
                CreateTime = DateTime.Now
            });
            return(result);
        }
Beispiel #7
0
 /// <summary>
 /// 用户账户明细列表
 /// </summary>
 /// <returns></returns>
 public static void GetList(QueryBase <MemberFundingModel> ent)
 {
     FundingRepository.GetList(ent);
 }