Exemple #1
0
        public void Logout_ExpectsOk()
        {
            sessionRepository.Setup(x => x.Exists(It.IsAny <Expression <Func <SessionEntity, bool> > >())).Returns(true);
            unitOfWork.Setup(x => x.UserRepository.FirstOrDefault(It.IsAny <Expression <Func <UserEntity, bool> > >())).Returns(adminEntity);
            sessionRepository.Setup(u => u.Add(It.IsAny <SessionEntity>())).Verifiable();
            var guid = sessionLogic.Login(adminEntity.Mail, adminEntity.Password);

            SessionEntity sessionEntity = new SessionEntity {
                Token = guid, Mail = adminEntity.Mail
            };

            sessionRepository.Setup(x => x.FirstOrDefault(It.IsAny <Expression <Func <SessionEntity, bool> > >())).Returns(sessionEntity);
            sessionRepository.Setup(u => u.Delete(It.IsAny <SessionEntity>())).Verifiable();

            sessionLogic.Logout(adminEntity.Id);

            sessionRepository.VerifyAll();
        }
Exemple #2
0
 public IActionResult Logout(int id)
 {
     if (ModelState.IsValid)
     {
         try
         {
             sessionLogic.Logout(id);
             return(Ok());
         }
         catch (ArgumentException e)
         {
             return(BadRequest(e.Message));
         }
         catch (Exception ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }