Exemplo n.º 1
0
 public ActionResult DenyDogOwner(string RequestFromID)
 {
     if (string.IsNullOrWhiteSpace(RequestFromID))
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         var ReciverID = User.Identity.GetUserId();
         if (dogOwnerService.DenyUser(ReciverID, RequestFromID))
         {
             return(Json(true));
         }
         else
         {
             return(Json(false));
         }
     }
 }
        public void ShouldDeleteRequestMessageOnDeny()
        {
            //Arrange:
            IEnumerable <RequestMessage> msgToDelete = list.Where(l => l.SendFromID == UserToVerifyOrDeny.Id && l.ReciverID == appUser.Id);

            mockRequestMessageRepo.Setup(x => x.Get(
                                             It.IsAny <Expression <Func <RequestMessage, bool> > >(),
                                             It.IsAny <Func <IQueryable <RequestMessage>, IOrderedQueryable <RequestMessage> > >(), It.IsAny <string>()))
            .Returns(msgToDelete).Verifiable();

            mockRequestMessageRepo.Setup(x => x.Delete(
                                             It.Is <RequestMessage>(m => m.SendFromID == UserToVerifyOrDeny.Id && m.ReciverID == appUser.Id)))
            .Callback(() => list.Remove(msgToDelete.FirstOrDefault())).Verifiable();
            //-----------//

            //Act:
            IDogOwnerService dogService = InitializeNewService();
            bool             isItTrue   = dogService.DenyUser(appUser.Id, UserToVerifyOrDeny.Id);

            //-----------//

            //Assert:
            mockRequestMessageRepo.Verify(mock => mock.Get(
                                              It.IsAny <Expression <Func <RequestMessage, bool> > >(),
                                              It.IsAny <Func <IQueryable <RequestMessage>, IOrderedQueryable <RequestMessage> > >(), It.IsAny <string>()), Times.Once);

            mockRequestMessageRepo.Verify(mock => mock.Delete(
                                              It.IsAny <RequestMessage>()), Times.Once);

            mockUnitOfWork.Verify(mock => mock.Commit(), Times.Once);

            Assert.That(UserToVerifyOrDeny.IsConfirmed, Is.False);
            Assert.That(list.Count, Is.EqualTo(3));
            Assert.That(isItTrue, Is.True);
            //-----------//
        }