Ejemplo n.º 1
0
        public async Task TestPostAddOrganizationParticipantAsync_InvalidModel()
        {
            var model = new AdditionalOrganizationProjectPariticipantBindingModel();

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

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

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

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

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

            Assert.AreEqual(model.OrganizationId, businessEntity.OrganizationId);
            Assert.AreEqual(model.ProjectId, businessEntity.ProjectId);
            Assert.AreEqual(model.ParticipantTypeId, businessEntity.ParticipantTypeId);
            Assert.IsTrue(Object.ReferenceEquals(user, businessEntity.Audit.User));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> PostAddOrganizationParticipantAsync(AdditionalOrganizationProjectPariticipantBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = userProvider.GetCurrentUser();
                var businessUser = userProvider.GetBusinessUser(currentUser);
                await projectService.AddParticipantAsync(model.ToAdditionalOrganizationProjectParticipant(businessUser));

                await projectService.SaveChangesAsync();

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