public void TestToUpdatedMoneyFlow()
        {
            var sourceEntityId = 2;
            var entityTypeId   = MoneyFlowSourceRecipientType.Project.Id;
            var model          = new UpdatedMoneyFlowBindingModel
            {
                Description       = "desc",
                FiscalYear        = 2015,
                Id                = 1,
                MoneyFlowStatusId = MoneyFlowStatus.Actual.Id,
                TransactionDate   = DateTimeOffset.UtcNow,
                Amount            = 1.00m,
                GrantNumber       = "grant",
                IsDirect          = true
            };
            var user     = new User(1);
            var instance = model.ToUpdatedMoneyFlow(user, sourceEntityId, entityTypeId);

            Assert.IsTrue(Object.ReferenceEquals(user, instance.Audit.User));
            Assert.AreEqual(model.Description, instance.Description);
            Assert.AreEqual(model.FiscalYear, instance.FiscalYear);
            Assert.AreEqual(model.Id, instance.Id);
            Assert.AreEqual(model.MoneyFlowStatusId, instance.MoneyFlowStatusId);
            Assert.AreEqual(model.TransactionDate, instance.TransactionDate);
            Assert.AreEqual(model.Amount, instance.Value);
            Assert.AreEqual(sourceEntityId, instance.SourceOrRecipientEntityId);
            Assert.AreEqual(entityTypeId, instance.SourceOrRecipientEntityTypeId);
            Assert.AreEqual(model.GrantNumber, instance.GrantNumber);
            Assert.AreEqual(model.IsDirect, instance.IsDirect);
        }
        public async Task TestPutUpdateProgramMoneyFlowAsync_InvalidModel()
        {
            controller.ModelState.AddModelError("key", "error");
            var entityId = 100;
            var model    = new UpdatedMoneyFlowBindingModel
            {
                MoneyFlowStatusId = MoneyFlowStatus.Actual.Id,
            };
            var response = await controller.PutUpdateProgramMoneyFlowAsync(model, entityId);

            Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult));
        }
Exemplo n.º 3
0
        private async Task <IHttpActionResult> DoUpdateAsync(UpdatedMoneyFlowBindingModel model, int sourceEntityId, int sourceEntityTypeId)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = this.userProvider.GetCurrentUser();
                var businessUser = this.userProvider.GetBusinessUser(currentUser);
                await this.moneyFlowService.UpdateAsync(model.ToUpdatedMoneyFlow(businessUser, sourceEntityId, sourceEntityTypeId));

                await this.moneyFlowService.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task TestPutUpdateProgramMoneyFlowAsync()
        {
            var entityId = 100;
            var model    = new UpdatedMoneyFlowBindingModel
            {
                MoneyFlowStatusId = MoneyFlowStatus.Actual.Id,
            };

            userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(new User(1));
            SetExpectedEditedMoneyFlow(model.Id, entityId, MoneyFlowSourceRecipientType.Program.Id);
            var response = await controller.PutUpdateProgramMoneyFlowAsync(model, entityId);

            Assert.IsInstanceOfType(response, typeof(OkResult));
            userProvider.Verify(x => x.GetBusinessUser(It.IsAny <IWebApiUser>()), Times.Once());
            userProvider.Verify(x => x.GetCurrentUser(), Times.Once());
            moneyFlowService.Verify(x => x.UpdateAsync(It.IsAny <UpdatedMoneyFlow>()), Times.Once());
            moneyFlowService.Verify(x => x.SaveChangesAsync(), Times.Once());
        }
Exemplo n.º 5
0
 public Task <IHttpActionResult> PutUpdateProgramMoneyFlowAsync([FromBody] UpdatedMoneyFlowBindingModel model, int programId)
 {
     return(DoUpdateAsync(model, programId, MoneyFlowSourceRecipientType.Program.Id));
 }
Exemplo n.º 6
0
 public Task <IHttpActionResult> PutUpdateOfficeMoneyFlowAsync([FromBody] UpdatedMoneyFlowBindingModel model, int officeId)
 {
     return(DoUpdateAsync(model, officeId, MoneyFlowSourceRecipientType.Office.Id));
 }
Exemplo n.º 7
0
 public Task <IHttpActionResult> PutUpdateOrganizationMoneyFlowAsync([FromBody] UpdatedMoneyFlowBindingModel model, int organizationId)
 {
     return(DoUpdateAsync(model, organizationId, MoneyFlowSourceRecipientType.Organization.Id));
 }