Beispiel #1
0
        public async Task TestPostAddPersonParticipantAsync_InvalidModel()
        {
            var model = new AdditionalPersonProjectParticipantBindingModel();

            controller.ModelState.AddModelError("key", "error");
            var response = await controller.PostAddPersonParticipantAsync(model);

            Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult));
        }
Beispiel #2
0
        public async Task TestPostAddPersonParticipantAsync()
        {
            userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(new Business.Service.User(0));
            service.Setup(x => x.SaveChangesAsync()).ReturnsAsync(1);
            var model = new AdditionalPersonProjectParticipantBindingModel();

            model.ParticipantTypeId = ParticipantType.Individual.Id;
            var response = await controller.PostAddPersonParticipantAsync(model);

            Assert.IsInstanceOfType(response, typeof(OkResult));
            service.Verify(x => x.SaveChangesAsync(), Times.Once());
            service.Verify(x => x.AddParticipantAsync(It.IsAny <AdditionalPersonProjectParticipant>()), Times.Once());
        }
        public void TestToAdditionalPersonProjectParticipant()
        {
            var model = new AdditionalPersonProjectParticipantBindingModel();

            model.PersonId          = 1;
            model.ProjectId         = 2;
            model.ParticipantTypeId = ParticipantType.Individual.Id;
            var user           = new User(10);
            var businessEntity = model.ToAdditionalPersonProjectParticipant(user);

            Assert.AreEqual(model.PersonId, businessEntity.PersonId);
            Assert.AreEqual(model.ProjectId, businessEntity.ProjectId);
            Assert.AreEqual(model.ParticipantTypeId, businessEntity.ParticipantTypeId);
            Assert.IsTrue(Object.ReferenceEquals(user, businessEntity.Audit.User));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> PostAddPersonParticipantAsync(AdditionalPersonProjectParticipantBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = userProvider.GetCurrentUser();
                var businessUser = userProvider.GetBusinessUser(currentUser);
                await projectService.AddParticipantAsync(model.ToAdditionalPersonProjectParticipant(businessUser));

                await projectService.SaveChangesAsync();

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