예제 #1
0
 public IHttpActionResult DeleteOrganizationContactPersonContact(int id)
 {
     try
     {
         UnitOfWork unitOfWork = new UnitOfWork(factory);
         OrganizationContactPersonContact contact = unitOfWork.OrganizationContactPersonContactsRepository
                                                    .Get(d => d.Id == id, includeProperties: "ContactType")
                                                    .FirstOrDefault();
         contact.Deleted = true;
         unitOfWork.OrganizationContactPersonContactsRepository.Update(contact);
         OrganizationContactPersonContactDTO dto = contact.ToDTO();
         return(Ok(dto));
     }
     catch (NullReferenceException nre)
     {
         return(NotFound());
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #2
0
 public IHttpActionResult PostOrganizationContactPersonContact(OrganizationContactPersonContactDTO organizationContactPersonContact)
 {
     if (organizationContactPersonContact == null)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         OrganizationContactPersonContact contact = organizationContactPersonContact.FromDTO();
         UnitOfWork unitOfWork = new UnitOfWork(factory);
         contact.Id = contact.NewId(unitOfWork);
         unitOfWork.OrganizationContactPersonContactsRepository.Insert(contact);
         unitOfWork.Save();
         OrganizationContactPersonContact c = unitOfWork.OrganizationContactPersonContactsRepository
                                              .Get(d => d.Id == contact.Id, includeProperties: "ContactType").FirstOrDefault();
         OrganizationContactPersonContactDTO dto = c.ToDTO();
         return(CreatedAtRoute("GetOrganizationContactPersonContact", new { id = dto.Id }, dto));
     }
     catch (NullReferenceException nre)
     {
         return(NotFound());
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #3
0
        public void PostPassport_ShoulAddPassport()
        {
            var passportsTestData = new List <OrganizationContactPersonContact>()
            {
                new OrganizationContactPersonContact {
                    Id = 1, OrganizationContactPersonId = 2
                },
                new OrganizationContactPersonContact {
                    Id = 2, Deleted = true, OrganizationContactPersonId = 2
                },
                new OrganizationContactPersonContact {
                    Id = 3, OrganizationContactPersonId = 3
                }
            };
            var passports = MockHelper.MockDbSet(passportsTestData);

            passports.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(passports.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            passports.Setup(d => d.Add(It.IsAny <OrganizationContactPersonContact>())).Returns <OrganizationContactPersonContact>((contact) =>
            {
                passportsTestData.Add(contact);
                passports = MockHelper.MockDbSet(passportsTestData);
                return(contact);
            });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationContactPersonContacts).Returns(passports.Object);
            dbContext.Setup(d => d.Set <OrganizationContactPersonContact>()).Returns(passports.Object);

            dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <int> list = new List <int>();
                if (query.Contains("NewTableId"))
                {
                    int i = passports.Object.Max(d => d.Id) + 1;
                    list.Add(i);
                }
                else
                {
                    list.Add(0);
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            OrganizationContactPersonContact passport = new OrganizationContactPersonContact {
                Id = 0, OrganizationContactPersonId = 3
            };
            var controller = new OrganizationContactPersonContactsController(factory.Object);
            var result     = controller.PostOrganizationContactPersonContact(passport.ToDTO()) as CreatedAtRouteNegotiatedContentResult <OrganizationContactPersonContactDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Content.Id);
            Assert.AreEqual(3, result.Content.OrganizationContactPersonId);
        }
예제 #4
0
        public void PutDocument_ShouldReturnOk()
        {
            var passportsTestData = new List <OrganizationContactPersonContact>()
            {
                new OrganizationContactPersonContact {
                    Id = 1, OrganizationContactPersonId = 2
                },
                new OrganizationContactPersonContact {
                    Id = 2, Deleted = true, OrganizationContactPersonId = 2
                },
                new OrganizationContactPersonContact {
                    Id = 3, OrganizationContactPersonId = 3
                }
            };
            var passports = MockHelper.MockDbSet(passportsTestData);

            passports.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(passports.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationContactPersonContacts).Returns(passports.Object);
            dbContext.Setup(d => d.Set <OrganizationContactPersonContact>()).Returns(passports.Object);

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            OrganizationContactPersonContact passport = new OrganizationContactPersonContact {
                Id = 3, OrganizationContactPersonId = 3
            };
            var controller = new OrganizationContactPersonContactsController(factory.Object);
            var result     = controller.PutOrganizationContactPersonContact(3, passport.ToDTO()) as OkNegotiatedContentResult <OrganizationContactPersonContactDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }