コード例 #1
0
        public void Should_getMobileResponse()
        {
            string username          = RandomString();
            string password          = RandomString();
            string msgInstance       = RandomString();
            string msgKey            = RandomString();
            bool   useMobileMessages = true;
            User   user = CreateUser(username, password);

            MobileMessage message = new MobileMessage
            {
                device    = (int)MobileMessage.Device.ANDROID,
                argString = $"/Person2/{user.PeopleId}/Resources",
                instance  = msgInstance,
                key       = msgKey
            };

            MobileAccount account = new MobileAccount(db);

            account.setDeepLinkFields(message.device, message.instance, message.key, message.argString);
            account.sendDeepLink();

            MobileMessage response = account.getMobileResponse(useMobileMessages);

            response.ShouldNotBe(null);
        }
コード例 #2
0
        public void FetchInvolvementTest()
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            db.OrganizationMembers.InsertOnSubmit(new OrganizationMember
            {
                Organization = db.Organizations.First(),
                Person       = user.Person,
                MemberTypeId = MemberTypeCode.Member
            });
            db.SubmitChanges();
            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage {
                argInt = user.PeopleId.Value
            };
            var data   = message.ToString();
            var result = controller.FetchInvolvement(data) as MobileMessage;

            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            var orgs = JsonConvert.DeserializeObject <List <MobileInvolvement> >(result.data);

            orgs.Count.ShouldBe(1);
        }
コード例 #3
0
        public void UpdatePersonTest(int electronic, int statement, int envelope)
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                argInt   = user.PeopleId.Value,
                instance = RandomString(),
                data     = $@"[{{""type"":62,""value"":{electronic}}},{{""type"":63,""value"":{statement}}},{{""type"":64,""value"":{envelope}}}]",
            };
            var data   = message.ToString();
            var result = controller.UpdatePerson(data) as MobileMessage;

            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            db.Refresh(RefreshMode.OverwriteCurrentValues, user.Person);
            user.Person.EnvelopeOptionsId.ShouldBe(envelope);
            user.Person.ElectronicStatement.ShouldBe(electronic != 0);
            user.Person.ContributionOptionsId.ShouldBe(statement);
        }
コード例 #4
0
        public void FetchGivingSummaryTest(decimal contribution, string count, string comment, string total, string contribCount)
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var year = DateTime.Now.Year;

            if (contribution > 0)
            {
                var c = new Contribution()
                {
                    PeopleId             = user.PeopleId,
                    ContributionAmount   = contribution,
                    ContributionDate     = new DateTime(year, 7, 2),
                    ContributionStatusId = ContributionStatusCode.Recorded,
                    ContributionTypeId   = ContributionTypeCode.Online,
                    CreatedDate          = DateTime.Now,
                    FundId = 1
                };
                db.Contributions.InsertOnSubmit(c);
                db.SubmitChanges();
            }
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                argInt = 0
            };
            var data   = message.ToString();
            var result = controller.FetchGivingSummary(data) as MobileMessage;

            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            var summary = JsonConvert.DeserializeObject <MobileGivingSummary>(result.data);

            summary.Count.ShouldBe(1);
            var current = summary[$"{year}"];

            current.ShouldNotBeNull();
            current.title.ShouldBe($"{year}");
            current.comment.ShouldBe(comment);
            current.count.ShouldBe(count);
            current.loaded.ShouldBe(1);
            current.total.ShouldBe(total);
            current.summary[0].title.ShouldBe("Contributions");
            current.summary[0].comment.ShouldBe(comment);
            current.summary[0].count.ShouldBe(contribCount);
            current.summary[0].showAsPledge.ShouldBe(0);
        }
コード例 #5
0
ファイル: MobileMessageVo.cs プロジェクト: jesumarquez/lt
        public MobileMessageVo(MobileMessage message, bool verDirecciones)
        {
            _verDirecciones = verDirecciones;
            _movilId        = message.MovilId;

            FechaHora   = message.FechaYHora;
            Mensaje     = message.Mensaje;
            Velocidad   = message.Velocidad;
            Chofer      = message.Chofer;
            Responsable = message.Responsable;
            Hora        = message.Hora;
            Indice      = message.Indice;
        }
コード例 #6
0
        /// <summary>
        /// 用户申请审核(通过)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ActionResult AuditUserApplyAdopt(UserApplyOperateDTO dto)
        {
            ResultData <UserApplyOperateDTO> result = new ResultData <UserApplyOperateDTO>();
            UserLoginDTO user = (UserLoginDTO)Session["UserLoginInfo"];

            try
            {
                dto.CreateUser  = user.FullName;
                dto.RoleIDlist  = user.CurrentRoleIDList;
                dto.AuditStatus = 1;
                result          = UserAuthorityProvider.AuditUserApplyAdopt(dto);
                if (result.SubmitResult)
                {
                    result.Object.StopTime = DateTime.Now.AddYears(1);
                    UserAuthorityProvider.AuditUserApplyAdoptAut(result.Object);

                    //通过的模块名称
                    var    aut       = result.Object.ApplyUserAuthority.Select(s => s.StructureID).ToList();
                    var    modelname = ModelRoleModel.ModelRolelist.Where(m => aut.Contains(m.ModelID)).Select(s => s.ModelName).ToList();
                    string modelstr  = string.Join(",", modelname);

                    //取得申请人邮箱
                    UserApplySearchDTO batchdto = new UserApplySearchDTO();
                    batchdto.BatchID = result.Object.BatchID;
                    batchdto.Query   = 1;
                    batchdto.page    = 1;
                    batchdto.rows    = 1;
                    var pp = UserAuthorityProvider.GetBatchUser(batchdto);

                    //发送邮件通知申请人
                    EmailHelper.SendMessage("用户审核通过", string.Format(WebConfiger.UserAuditPassEmailMessage, result.Object.UserApplyName, dto.Distributor, modelstr), new List <string> {
                        pp.Object.ApplyUserEamil
                    }, null, null);
                    // 发送短信通知申请人
                    MobileMessage.SendMessage(new List <string> {
                        pp.Object.ApplyUserPhone
                    }, String.Format(WebConfiger.UserAuditPassShortMessage, modelstr));
                }
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message      = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        public void AuthenticatedLinkTest()
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            db.OrganizationMembers.InsertOnSubmit(new OrganizationMember
            {
                Organization = db.Organizations.First(),
                Person       = user.Person,
                MemberTypeId = MemberTypeCode.Member
            });
            db.SubmitChanges();
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                device    = (int)MobileMessage.Device.ANDROID,
                argString = $"/Person2/{user.PeopleId}/Resources"
            };
            var data   = message.ToString();
            var result = controller.AuthenticatedLink(data) as MobileMessage;
            var token  = db.OneTimeLinks
                         .Where(t => t.Querystring == username && t.Expires < DateTime.Now.AddMinutes(16))
                         .OrderByDescending(t => t.Expires).First().Id.ToCode();

            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            result.data.ShouldEndWith($"/Logon?otltoken={token}&ReturnUrl=%2fPerson2%2f{user.PeopleId}%2fResources%3fsource%3dAndroid");
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var mobile = new MobileMessage();

            mobile.WriteMessage("Hello how are you? This is a sms marketing, do you wanna buy something?");
            mobile.AddRecipient("+39-319-555-7749685");
            mobile.AddRecipient("+39-320-555-7828092");
            mobile.Send();

            Console.WriteLine();

            var email = new EmailMessage();

            email.WriteMessage("Please this is an e-mail verification.");
            email.AddSubject();
            email.AddAttach();
            email.AddRecipient("*****@*****.**");
            email.AddRecipient("*****@*****.**");
            email.AddRecipient("*****@*****.**");
            email.RequestReadReceipt();
            email.Send();

            Console.ReadLine();
        }
コード例 #9
0
 public async Task <ActionResult> MobileNotificationPost(MobileMessage model)
 {
     return(RentoJson(await CallApiTask("Message/CreateMobileNotificationMultiple", model)));
 }
コード例 #10
0
        /// <summary>
        /// 用户申请
        /// </summary>
        /// <param name="uam"></param>
        /// <returns></returns>
        public ActionResult Apply(UserApplyModel uam)
        {
            ResultData <object> result = new ResultData <object>();
            short shtStatuscode        = -1;

            if (HomeProvider.CheckPhoneNumber(uam.UserApplyTelNumber, ref shtStatuscode))
            {
                result.SubmitResult = false;
                result.Message      = "手机号已存在,不可重复申请!";

                return(Json(result));
            }

            uam.ApplyAuth     = uam.ApplyAuth.Where(p => p.IsChecked).ToList();
            uam.UserApplyTime = DateTime.Now;
            uam.AuditStatus   = 0;
            if (UserApplyProvider.AuthApply(uam))
            {
                List <MasterData.DTO.Common.AdminDTO> lstadmin = UserApplyProvider.GetAdminInfo(new MasterData.DTO.Common.AdminSearchDTO {
                    RoleIdList = new List <int> {
                        1
                    }
                });
                // 发送短信通知系统管理员
                string UserApplyShortMessage = String.Format(WebConfiger.UserApplyShortMessage, uam.UserApplyName, uam.DistributorNamestr);
                if (string.IsNullOrEmpty(uam.DistributorNamestr))
                {
                    UserApplyShortMessage = UserApplyShortMessage.Replace("经销商:", "");
                }
                MobileMessage.SendMessage(lstadmin.Select(g => g.PhoneNumber).ToList(), UserApplyShortMessage);
                //记录短信日志
                var useridlist = lstadmin.Select(g => g.UserID).ToList();
                if (useridlist.Count > 0)
                {
                    List <MessageOperateDTO> msgdtolist = new List <MessageOperateDTO>();
                    foreach (var uid in useridlist)
                    {
                        msgdtolist.Add(new MessageOperateDTO
                        {
                            UserID      = uid,
                            SendTime    = DateTime.Now,
                            MessageType = 1
                        });
                    }
                    TCSOFT.DMS.WebMain.Models.Provider.CommonProvider.AddMessageStat(msgdtolist);
                }
                // 发送邮件通知系统管理员
                string UserApplyEmailMessage = String.Format(WebConfiger.UserApplyEmailMessage, uam.UserApplyName, uam.DistributorNamestr);
                if (string.IsNullOrEmpty(uam.DistributorNamestr))
                {
                    UserApplyEmailMessage = UserApplyEmailMessage.Replace("经销商:", "");
                }
                EmailHelper.SendMessage("新用户申请", UserApplyEmailMessage, lstadmin.Select(g => g.Email).ToList(), null, null);
                result.SubmitResult = true;
                result.Message      = "申请成功!";
            }
            else
            {
                result.SubmitResult = false;
                result.Message      = "申请失败!";
            }

            return(Json(result));
        }
コード例 #11
0
        public ActionResult SendMobileMessage(string PhoneNumber, string ValidateCode)
        {
            ResultData <object> result = new ResultData <object>();

            if (Session["ValidateCode"] == null || Session["ValidateCode"].ToString() != ValidateCode)
            {
                result.SubmitResult = false;
                result.Message      = "图形码不正确!";
                return(Json(result));
            }
            //检测手机号是否存在
            short shtStatuscode = 0;

            if (!HomeProvider.CheckPhoneNumber(PhoneNumber, ref shtStatuscode))
            {
                result.SubmitResult = false;
                switch (shtStatuscode)
                {
                case 1:
                    result.Message = "1";
                    break;

                case 2:
                    result.Message = WebConfiger.NoAuthMessage;
                    break;

                case 3:
                    result.Message = "该手机号已停用!";
                    break;

                case 4:
                    result.Message = "该手机号已到期!";
                    break;
                }

                return(Json(result));
            }

            // 检测是否有权限

            string strDymicPassword = new RandomCode().CreateValidateCode(6);
            string strMessage       = WebConfiger.ShortMessage;

            strMessage = String.Format(strMessage, strDymicPassword);
            string strResult = MobileMessage.SendMessage(new List <string> {
                PhoneNumber
            }, strMessage);

            if (String.IsNullOrEmpty(strResult))
            {
                // 发完,成功发送进库保存304秒(融入4秒误差)
                result.SubmitResult = HomeProvider.SaveDymicPassword(new MoblieLoginDTO {
                    PhoneNumber = PhoneNumber, DymicPassword = strDymicPassword, ValidDate = 304
                });
                HomeProvider.SaveMessageLog(PhoneNumber);
            }
            else
            {
                result.SubmitResult = false;
                result.Message      = strResult;
            }

            return(Json(result));
        }
コード例 #12
0
        public void FetchGivingSummaryTest(decimal contribution, string count, string comment, string total, string prevTotal, string contribCount, int yearCount)
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var Now       = DateTime.Now;
            var year      = Now.Year;
            var fund1Name = db.ContributionFunds.Where(c => c.FundId == 1).Select(c => c.FundName).Single();

            if (contribution > 0)
            {
                GenerateContribution(contribution, user, Now);
                GenerateContribution(contribution * 4m, user, Now.AddYears(-1));
            }
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                argInt = 0
            };
            var data   = message.ToString();
            var result = controller.FetchGivingSummary(data) as MobileMessage;

            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            var summary = JsonConvert.DeserializeObject <MobileGivingSummary>(result.data);

            summary.Count.ShouldBe(yearCount);
            var current = summary[$"{year}"];

            current.ShouldNotBeNull();
            current.title.ShouldBe($"{year}");
            current.comment.ShouldBe(comment);
            current.count.ShouldBe(count);
            current.loaded.ShouldBe(1);
            current.total.ShouldBe(total);
            current.summary[0].title.ShouldBe("Contributions");
            current.summary[0].comment.ShouldBe(comment);
            current.summary[0].count.ShouldBe(contribCount);
            current.summary[0].showAsPledge.ShouldBe(0);
            if (contribution > 0)
            {
                current.summary[0].funds[0].name.ShouldBe(fund1Name);
                current.summary[0].funds[0].given.ShouldBe(total);
            }
            message = new MobileMessage
            {
                argInt = Now.Year - 1
            };
            data   = message.ToString();
            result = controller.FetchGivingSummary(data) as MobileMessage;
            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            summary = JsonConvert.DeserializeObject <MobileGivingSummary>(result.data);
            summary.Count.ShouldBe(yearCount);
            if (contribution > 0)
            {
                var previous = summary[$"{year - 1}"];
                previous.ShouldNotBeNull();
                previous.title.ShouldBe($"{year - 1}");
                previous.comment.ShouldBe(comment);
                previous.count.ShouldBe(count);
                previous.loaded.ShouldBe(1);
                previous.total.ShouldBe(prevTotal);
                previous.summary[0].title.ShouldBe("Contributions");
                previous.summary[0].comment.ShouldBe(comment);
                previous.summary[0].count.ShouldBe(contribCount);
                previous.summary[0].showAsPledge.ShouldBe(0);
                previous.summary[0].funds[0].name.ShouldBe(fund1Name);
                previous.summary[0].funds[0].given.ShouldBe(prevTotal);
            }
        }
コード例 #13
0
        public void QuickSignInTest(bool useEmail)
        {
            var requestManager = FakeRequestManager.Create();

            db = requestManager.CurrentDatabase;
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();
            var build        = "2020.2.1";

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            var person = CreatePerson();

            person.CellPhone    = RandomPhoneNumber();
            person.EmailAddress = RandomEmailAddress();
            db.SetSetting("UseMobileQuickSignInCodes", "true");
            db.SetSetting("TwilioToken", RandomString());
            db.SetSetting("TwilioSid", RandomString());
            var group = db.SMSGroups.FirstOrDefault(g => g.SystemFlag == true);

            if (group == null)
            {
                group = new SMSGroup {
                    SystemFlag = true, Name = "System Group", Description = ""
                };
                db.SMSGroups.InsertOnSubmit(group);
                db.SubmitChanges();
            }
            db.SMSNumbers.InsertOnSubmit(new SMSNumber {
                GroupID = group.Id, Number = RandomPhoneNumber(), LastUpdated = DateTime.Now
            });
            db.SubmitChanges();
            string messageBody = "";

            if (useEmail)
            {
                db.SMTPClient = new MockEmailClient
                {
                    Receive = (to, from, subject, body) => {
                        messageBody = body;
                    }
                };
            }
            else
            {
                TwilioHelper.MockSender = (to, from, body, statusCallback) => {
                    messageBody = body;
                    return(new TwilioMessageResult {
                        Status = "Sent"
                    });
                };
            }

            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                device    = (int)MobileMessage.Device.ANDROID,
                instance  = RandomString(),
                argString = useEmail ? person.EmailAddress : person.CellPhone,
                build     = build,
            };

            var data   = message.ToString();
            var result = controller.QuickSignIn(data) as MobileMessage;

            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            messageBody.ShouldNotBeEmpty();

            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = "Quick " + FindCode(messageBody);
            message = new MobileMessage
            {
                device   = (int)MobileMessage.Device.ANDROID,
                instance = message.instance,
                build    = build,
            };
            data   = message.ToString();
            result = controller.QuickSignInUsers(data) as MobileMessage;
            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            result.count.ShouldBeGreaterThan(0);
            result.data.ShouldNotBeEmpty();

            var list = JsonConvert.DeserializeObject <IEnumerable <MobileQuickSignInUser> >(result.data);
            var user = list.First();

            user.userID.ShouldBe(0);
            user.peopleID.ShouldBe(person.PeopleId);
            user.name.ShouldBe(person.Name);
            user.user.ShouldBe("Create User");
            var device = db.MobileAppDevices.SingleOrDefault(m => m.InstanceID == message.instance);

            device.ShouldNotBeNull();
            device.AppVersion.ShouldBe(build);
            Should.Equals(device.DeviceTypeID, MobileMessage.Device.ANDROID);

            //Test QuickSignInCreateUser
            message = new MobileMessage
            {
                device   = (int)MobileMessage.Device.ANDROID,
                instance = device.InstanceID,
                build    = build,
                argInt   = person.PeopleId,
            };
            data   = message.ToString();
            result = controller.QuickSignInCreateUser(data) as MobileMessage;
            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            result.count.ShouldBe(0);
            result.data.ShouldNotBeEmpty();
            result.id.ShouldBeGreaterThan(0);
            var userId   = result.id;
            var username = result.data;

            //Test SetDevicePIN
            var pin = "1234";

            message = new MobileMessage
            {
                device    = (int)MobileMessage.Device.ANDROID,
                instance  = device.InstanceID,
                build     = build,
                argInt    = userId,
                argString = pin.Sha256Hash(),
            };
            data   = message.ToString();
            result = controller.SetDevicePIN(data) as MobileMessage;
            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            result.count.ShouldBe(0);
            result.data.ShouldNotBeEmpty();

            //Test PIN authorization by getting the user's own profile
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = "PIN " + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{pin.Sha256Hash()}"));
            message = new MobileMessage
            {
                device   = (int)MobileMessage.Device.ANDROID,
                instance = device.InstanceID,
                build    = build,
                argInt   = person.PeopleId,
            };
            data   = message.ToString();
            result = controller.FetchPerson(data) as MobileMessage;
            result.ShouldNotBeNull();
            result.error.ShouldBe(0);
            result.count.ShouldBe(1);
            result.data.ShouldNotBeEmpty();
        }
コード例 #14
0
        public void FetchGivingHistoryTest(decimal contribution, int total, int prevTotal, int yearCount, int prevYearCount)
        {
            var username           = RandomString();
            var password           = RandomString();
            var user               = CreateUser(username, password);
            var requestManager     = FakeRequestManager.Create();
            var membershipProvider = new MockCMSMembershipProvider {
                ValidUser = true
            };
            var roleProvider = new MockCMSRoleProvider();

            CMSMembershipProvider.SetCurrentProvider(membershipProvider);
            CMSRoleProvider.SetCurrentProvider(roleProvider);
            requestManager.CurrentHttpContext.Request.Headers["Authorization"] = BasicAuthenticationString(username, password);
            var Now  = DateTime.Now;
            var year = Now.Year;

            if (contribution > 0)
            {
                GenerateContribution(contribution, user, Now);
                GenerateContribution(contribution * 10m, user, Now, ContributionTypeCode.Stock);
                GenerateContribution(contribution * 4m, user, Now.AddYears(-1));
            }
            var controller = new MobileAPIv2Controller(requestManager);
            var message    = new MobileMessage
            {
                argInt = 0
            };
            var data   = message.ToString();
            var result = controller.FetchGivingHistory(data) as BaseMessage;

            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            var history = JsonConvert.DeserializeObject <MobileGivingHistory>(result.data);

            history.lastYear.ShouldBe(year - 1);
            history.lastYearTotal.ShouldBe(prevTotal);
            history.thisYear.ShouldBe(year);
            if (contribution > 0)
            {
                history.yearToDateTotal.ShouldBe(total);
            }
            history.entries.Count.ShouldBe(yearCount);
            if (yearCount > 1)
            {
                var sum = history.entries.Sum(e => e.amount);
                sum.ShouldBe(total);
            }

            message = new MobileMessage
            {
                argInt  = Now.Year - 1,
                version = 9
            };
            data   = message.ToString();
            result = controller.FetchGivingHistory(data) as BaseMessage;
            result.ShouldNotBeNull();
            result.count.ShouldBe(1);
            result.error.ShouldBe(0);
            history = JsonConvert.DeserializeObject <MobileGivingHistory>(result.data);
            history.lastYear.ShouldBe(year - 2);
            history.lastYearTotal.ShouldBe(0);
            history.thisYear.ShouldBe(year - 1);
            if (contribution > 0)
            {
                history.yearToDateTotal.ShouldBe(prevTotal);
            }
            history.entries.Count.ShouldBe(prevYearCount);
            if (yearCount > 1)
            {
                var sum = history.entries.Sum(e => e.amount);
                sum.ShouldBe(prevTotal);
            }
        }