Example #1
0
        public void Contract_can_be_closed_when_expired()
        {
            var contract = new Contract(1, DateTime.Now)
                               {
                                   AccountId = 1,
                                   ActivationDate = DateTime.Parse("2007-01-04"),
                                   EndDate = DateTime.Parse("2009-01-04"),
                                   ContractStatus = ContractStatus.Active
                               };

            // if closed before contract end date "Contract cancelled before contract end date"
            // else "Contract closed".
            _contractRepository
                .Expect(c => c.GetContract(1))
                .Returns(contract);

            _contractRepository
                .Expect(c => c.UpdateContract(It.Is<Contract>(e => e.StatusChangedDate.Date == DateTime.Today && e.ContractStatus == ContractStatus.Closed)))
                .Returns(true);

            // Send email notifying of closed contract

            // write activity log for email send.
            _activityService
                .Expect(a => a.WriteActivity(contract, "Contract Closed"))
                .AtMostOnce();

            var request = new CloseContractRequest { ContractId = 1, User = CreateIUser() };
            var response = _service.CloseContract(request);
            Assert.IsTrue(response.IsSuccessful);
        }
Example #2
0
        protected void CloseContract(object sender, EventArgs e)
        {
            var contractId = Contract.ContractId;
            if (contractId == 0) return;

            var request = new CloseContractRequest { ContractId = contractId, User = Users.Current };
            var response = ContractService.CloseContract(request);

            if (response.IsSuccessful)
            {
                var responseContract = ContractService.ViewContract(new ViewContractRequest { ContractId = contractId, User = Users.Current });
                if (responseContract.IsSuccessful)
                {
                    // Set Contract
                    PopulateView(responseContract);

                    ConfirmCancelPopup.Hide();

                    UserMessage.SetSuccess("Contract has been closed");
                }
                else
                {
                    UserMessage.SetFailure(responseContract.Message);
                }
            }
            else
            {
                UserMessage.SetFailure(response.Message);
            }
        }