Пример #1
0
        public object Put(AccountChargeRequest request)
        {
            var existing = _dao.FindByAccountNumber(request.AccountNumber);

            if (existing != null &&
                existing.Id != request.Id)
            {
                throw new HttpError(HttpStatusCode.Conflict, ErrorCode.AccountCharge_AccountAlreadyExisting.ToString());
            }

            var i = 0;

            foreach (var question in request.Questions)
            {
                question.Id        = i++;
                question.AccountId = request.Id;
            }
            var addUpdateAccountCharge = new AddUpdateAccountCharge
            {
                AccountChargeId         = request.Id,
                Name                    = request.Name,
                Number                  = request.AccountNumber,
                UseCardOnFileForPayment = request.UseCardOnFileForPayment,
                Questions               = request.Questions,
                CompanyId               = AppConstants.CompanyId
            };

            _commandBus.Send(addUpdateAccountCharge);

            return(new
            {
                Id = addUpdateAccountCharge.AccountChargeId
            });
        }
        public void when_adding_accountcharge_successfully()
        {
            var addUpdateAccountCharge = new AddUpdateAccountCharge
            {
                CompanyId       = _companyId,
                AccountChargeId = Guid.NewGuid(),
                Number          = "number",
                Name            = "VIP",
                Questions       = new []
                {
                    new AccountChargeQuestion
                    {
                        Answer   = "answer",
                        Id       = 1,
                        Question = "question"
                    }
                }
            };

            _sut.When(addUpdateAccountCharge);

            var evt = _sut.ThenHasSingle <AccountChargeAddedUpdated>();

            Assert.AreEqual(_companyId, evt.SourceId);
            Assert.AreEqual(addUpdateAccountCharge.Name, evt.Name);
            Assert.AreEqual(addUpdateAccountCharge.Number, evt.Number);
            Assert.AreEqual(addUpdateAccountCharge.AccountChargeId, evt.AccountChargeId);
            Assert.AreEqual(addUpdateAccountCharge.Questions[0].Question, evt.Questions[0].Question);
            Assert.AreEqual(addUpdateAccountCharge.Questions[0].Answer, evt.Questions[0].Answer);
        }
Пример #3
0
        public void Handle(AddUpdateAccountCharge command)
        {
            var company = _repository.Get(command.CompanyId);

            company.AddUpdateAccountCharge(command.AccountChargeId, command.Number, command.Name, command.UseCardOnFileForPayment, command.Questions);

            _repository.Save(company, command.Id.ToString());
        }