public async Task TestPutUpdateParticipantPersonAsync_InvalidModel()
        {
            var model = new UpdatedParticipantPersonBindingModel();

            model.ParticipantTypeId = ParticipantType.Individual.Id;

            controller.ModelState.AddModelError("key", "error");
            var result = await controller.PutCreateOrUpdateParticipantPersonAsync(1, model);

            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
        }
Ejemplo n.º 2
0
        private Task <SimpleParticipantPersonDTO> DoCreateOrUpdateParticipantPersonAsync(int projectId, ParticipantDTO participant)
        {
            var model = new UpdatedParticipantPersonBindingModel
            {
                HomeInstitutionAddressId = null,
                HomeInstitutionId        = null,
                HostInstitutionAddressId = null,
                HostInstitutionId        = null,
                ParticipantStatusId      = participant.StatusId,
                ParticipantId            = participant.ParticipantId,
                ParticipantTypeId        = participant.ParticipantTypeId,
            };

            return(DoCreateOrUpdateParticipantPersonAsync(projectId, model));
        }
        public async Task TestPutUpdateParticipantPersonAsync()
        {
            var user         = new DebugWebApiUser();
            var businessUser = new User(1);

            userProvider.Setup(x => x.GetCurrentUser()).Returns(user);
            userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(businessUser);

            var model = new UpdatedParticipantPersonBindingModel();

            model.ParticipantTypeId = ParticipantType.Individual.Id;

            var result = await controller.PutCreateOrUpdateParticipantPersonAsync(1, model);

            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <SimpleParticipantPersonDTO>));
            service.Verify(x => x.CreateOrUpdateAsync(It.IsAny <UpdatedParticipantPerson>()), Times.Once());
            service.Verify(x => x.SaveChangesAsync(), Times.Once());
            service.Verify(x => x.GetParticipantPersonByIdAsync(It.IsAny <int>(), It.IsAny <int>()), Times.Once());
            userProvider.Verify(x => x.GetBusinessUser(It.IsAny <IWebApiUser>()), Times.Once());
            userProvider.Verify(x => x.GetCurrentUser(), Times.Once());
        }
Ejemplo n.º 4
0
        public void TestToUpdatedParticipantPerson()
        {
            var model = new UpdatedParticipantPersonBindingModel();

            model.HomeInstitutionAddressId = 100;
            model.HomeInstitutionId        = 20;
            model.HostInstitutionAddressId = 33;
            model.HostInstitutionId        = 40;
            model.ParticipantId            = 50;
            model.ParticipantStatusId      = ParticipantStatus.Active.Id;
            model.ParticipantTypeId        = ParticipantType.ForeignTravelingParticipant.Id;

            var user      = new User(1);
            var projectId = 1000;
            var instance  = model.ToUpdatedParticipantPerson(user, projectId);

            Assert.AreEqual(model.HomeInstitutionAddressId, instance.HomeInstitutionAddressId);
            Assert.AreEqual(model.HomeInstitutionId, instance.HomeInstitutionId);
            Assert.AreEqual(model.HostInstitutionAddressId, instance.HostInstitutionAddressId);
            Assert.AreEqual(model.HostInstitutionId, instance.HostInstitutionId);
            Assert.AreEqual(model.ParticipantId, instance.ParticipantId);
            Assert.AreEqual(model.ParticipantStatusId, instance.ParticipantStatusId);
            Assert.AreEqual(model.ParticipantTypeId, instance.ParticipantTypeId);
        }
Ejemplo n.º 5
0
        private async Task <SimpleParticipantPersonDTO> DoCreateOrUpdateParticipantPersonAsync(int projectId, UpdatedParticipantPersonBindingModel model)
        {
            var currentUser  = this.userProvider.GetCurrentUser();
            var businessUser = this.userProvider.GetBusinessUser(currentUser);

            await this.service.CreateOrUpdateAsync(model.ToUpdatedParticipantPerson(businessUser, projectId));

            await this.service.SaveChangesAsync();

            var participantPerson = await this.service.GetParticipantPersonByIdAsync(projectId, model.ParticipantId);

            return(participantPerson);
        }
Ejemplo n.º 6
0
        public async Task <IHttpActionResult> PutCreateOrUpdateParticipantPersonAsync(int projectId, [FromBody] UpdatedParticipantPersonBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var participantPerson = await DoCreateOrUpdateParticipantPersonAsync(projectId, model);

                return(Ok(participantPerson));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }