Example #1
0
        public ActionResult <SuccessMessageModel> AddFavorite(FavoriteModel mate)
        {
            int?EmployerId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (EmployerId == null)
            {
                return(Unauthorized("Sem Autorização ou sem sessão inciada"));
            }

            EmployerDAO employerDAO = new EmployerDAO(_connection);
            int?        mateID      = employerDAO.FindMateByEmail(mate.Email);

            if (mateID == null)
            {
                return(NotFound(new ErrorMessageModel("Utilizador não existe!")));
            }

            int?returnedId = employerDAO.AddFavorite((int)EmployerId, (int)mateID);

            return(Ok(new SuccessMessageModel("ID do Mate adicionado: " + returnedId)));
        }
        public void CanEmployerListFavoriteMatesTest()
        {
            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Jessica";
            testMate.LastName    = "Coelho";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Ordem";
            testMate.Categories  = new[] { Categories.FURNITURE_ASSEMBLE, Categories.TRANSPORTATION };
            testMate.Rank        = Ranks.MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            IEmployerDAO <Employer> employerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Ema";
            testEmployer.LastName    = "Coelho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lousada";

            Employer returnedEmployer = employerDAO.Create(testEmployer);

            employerDAO.AddFavorite(returnedEmployer.Id, returnedMate.Id);

            List <FavoriteModel> favoriteModels = employerDAO.FavoritesList(returnedEmployer.Id).ToList();

            Assert.Equal(returnedMate.Email, favoriteModels.Find(a => a.Email == returnedMate.Email).Email);

            _fixture.Dispose();
        }
        public void CanEmployerRemoveFavoriteMateTest()
        {
            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Jessica";
            testMate.LastName    = "Coelho";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Ordem";
            testMate.Categories  = new[] { Categories.FURNITURE_ASSEMBLE, Categories.TRANSPORTATION };
            testMate.Rank        = Ranks.MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            IEmployerDAO <Employer> employerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Ema";
            testEmployer.LastName    = "Coelho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lousada";

            Employer returnedEmployer = employerDAO.Create(testEmployer);

            int?returnedId = employerDAO.AddFavorite(returnedEmployer.Id, returnedMate.Id);

            int?deletedID = employerDAO.RemoveFavorite(returnedEmployer.Id, returnedMate.Id);

            Assert.Equal(returnedMate.Id, deletedID);

            _fixture.Dispose();
        }