public async Task Add_ReturnsFaceShapeLinkAdded()
        {
            // Arrange
            _faceShapeLinksContext = _db.SeedFaceShapeLinksContext();
            int currentFaceShapeLinksCount = _db.FaceShapeLinks.Count;
            List <FaceShapeLinks> currentFaceShapeLinks = _db.FaceShapeLinks;

            FaceShapeLinks expected = new FaceShapeLinks
            {
                Id          = 3,
                LinkName    = "rectangular link 2",
                LinkUrl     = "https://www.prettyyourworld.com/assets/public/images/rectangle%20-%20face%20-Depositphotos_4210529_xl-2015.jpg",
                FaceShapeId = 2
            };

            // Act
            FaceShapeLinks actual = await _faceShapeLinksContext.Add(expected);

            int updatedFaceShapeLinksCount = _db.FaceShapeLinks.Count;

            _db.FaceShapeLinks = new List <FaceShapeLinks>(currentFaceShapeLinks);

            // Assert
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(currentFaceShapeLinksCount + 1, updatedFaceShapeLinksCount);
        }
        public async Task Edit_ReturnsTrue()
        {
            // Arrange
            _faceShapeLinksContext = _db.SeedFaceShapeLinksContext();
            ulong id = 2;
            List <FaceShapeLinks> currentFaceShapeLinks = _db.FaceShapeLinks;
            FaceShapeLinks        current = currentFaceShapeLinks.FirstOrDefault(c => c.Id == id);
            FaceShapeLinks        updated = current.ShallowCopy();

            updated.LinkName = "square links";
            updated.LinkUrl  = "https://scstylecaster.files.wordpress.com/2016/05/olivia-wilde-square-face.jpg";

            FaceShapeLinks updatedFaceShapeLink = new FaceShapeLinks
            {
                Id          = id,
                LinkName    = updated.LinkName,
                LinkUrl     = updated.LinkUrl,
                FaceShapeId = updated.FaceShapeId
            };

            bool expected = true;

            // Act
            bool actual = await _faceShapeLinksContext.Edit(id, updatedFaceShapeLink);

            FaceShapeLinks u = _db.FaceShapeLinks.FirstOrDefault(fs => fs.Id == id);

            _db.FaceShapeLinks = new List <FaceShapeLinks>(currentFaceShapeLinks);

            // Assert
            Assert.Equal(expected, actual);
            Assert.Equal(updatedFaceShapeLink.LinkUrl, u.LinkUrl);
        }
        /// <summary>
        /// Deletes a faceShapeLink by ID
        /// </summary>
        /// <param name="id">ID of the faceShapeLink to be deleted</param>
        /// <exception cref="ResourceNotFoundException">
        ///     Thrown if the user with the corresponding <seealso cref="id"/> is not found
        /// </exception>
        /// <returns>FaceShapeLink deleted</returns>
        public async Task <FaceShapeLinks> Delete(ulong id)
        {
            FaceShapeLinks faceShapeLink = null;

            if (_context != null)
            {
                faceShapeLink = await _context.FaceShapeLinks.FindAsync(id);

                if (faceShapeLink != null)
                {
                    _context.FaceShapeLinks.Remove(faceShapeLink);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    throw new ResourceNotFoundException("FaceShapeLink not found");
                }
            }
            else
            {
                faceShapeLink = FaceShapeLinks.Where(u => u.Id == id).FirstOrDefault();

                if (faceShapeLink != null)
                {
                    FaceShapeLinks.Remove(faceShapeLink);
                }
                else
                {
                    throw new ResourceNotFoundException("FaceShapeLink not found");
                }
            }

            return(faceShapeLink);
        }
        public async Task Read_ReturnsFaceShapeLinksById()
        {
            // Arrange
            _faceShapeLinksContext = _db.SeedFaceShapeLinksContext();
            ulong          id       = 1;
            FaceShapeLinks expected = _db.FaceShapeLinks.FirstOrDefault(c => c.Id == id);

            // Act
            FaceShapeLinks actual = await _faceShapeLinksContext.ReadById(id);

            // Assert
            Assert.Equal(expected, actual);
        }
        /// <summary>
        /// Adds a new faceShapeLink
        /// <para>
        ///     NOTE: Currently this method is not restricted to unique faceShapeLinks, so the operation always succeeds
        /// </para>
        /// </summary>
        /// <param name="faceShapeLink">FaceShapeLink to be added</param>
        /// <returns>FaceShapeLink added</returns>
        public Task <FaceShapeLinks> Add(FaceShapeLinks faceShapeLink)
        {
            FaceShapeLinks faceShapeLinkAdded = null;

            if (_context != null)
            {
                _context.FaceShapeLinks.Add(faceShapeLink);
                faceShapeLinkAdded = faceShapeLink;
            }
            else
            {
                FaceShapeLinks.Add(faceShapeLink);
                faceShapeLinkAdded = faceShapeLink;
            }

            return(Task.FromResult(faceShapeLinkAdded));
        }
        /// <summary>
        /// Updates an existing faceShapeLink
        /// </summary>
        /// <param name="id">ID of the faceShapeLink to be updated</param>
        /// <param name="updatedFaceShapeLink">Updated faceShapeLink object</param>
        /// <exception cref="ResourceNotFoundException">
        ///     Thrown if <seealso cref="updatedFaceShapeLink"/> does not exist
        /// </exception>
        /// <exception cref="DbUpdateConcurrencyException">
        /// </exception>
        /// <returns>Result of the operation</returns>
        public async Task <bool> Edit(ulong id, FaceShapeLinks updatedFaceShapeLink)
        {
            bool faceShapeLinkUpdated = false;

            if (_context != null)
            {
                FaceShapeLinks currentFaceShapeLink = await _context.FaceShapeLinks.FindAsync(id);

                try
                {
                    if (currentFaceShapeLink != null)
                    {
                        currentFaceShapeLink.LinkName = updatedFaceShapeLink.LinkName;
                        currentFaceShapeLink.LinkUrl  = updatedFaceShapeLink.LinkUrl;
                        _context.Entry(currentFaceShapeLink).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        faceShapeLinkUpdated = true;
                    }

                    throw new ResourceNotFoundException("FaceShapeLink not found");
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    throw ex;
                }
            }
            else
            {
                FaceShapeLinks currentFaceShapeLink = FaceShapeLinks.FirstOrDefault(fs => fs.Id == id);

                if (currentFaceShapeLink != null)
                {
                    int currentFaceShapeLinkIndex = FaceShapeLinks.FindIndex(c => c.Id == id);
                    FaceShapeLinks[currentFaceShapeLinkIndex] = updatedFaceShapeLink;
                    faceShapeLinkUpdated = true;
                }
                else
                {
                    throw new ResourceNotFoundException("FaceShapeLink not found");
                }
            }

            return(faceShapeLinkUpdated);
        }
Exemplo n.º 7
0
        public async Task <ActionResult <FaceShapeLinks> > PostFaceShapeLinks([FromBody] FaceShapeLinks faceShapeLinks)
        {
            if (!_authorizationService.ValidateJWTToken(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            var correspondingFaceShape = await _context.FaceShapes.FirstOrDefaultAsync(f => f.Id == faceShapeLinks.FaceShapeId);

            if (correspondingFaceShape == null)
            {
                return(BadRequest(new { errors = new { FaceShapeId = new string[] { "No matching face shape entry was found" } }, status = 400 }));
            }

            _context.FaceShapeLinks.Add(faceShapeLinks);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFaceShapeLinks", new { id = faceShapeLinks.Id }, faceShapeLinks));
        }
        public async Task Delete_ReturnsFaceShapeDeleted()
        {
            // Arrange
            _faceShapeLinksContext = _db.SeedFaceShapeLinksContext();
            ulong id = 2;
            List <FaceShapeLinks> currentFaceShapeLinks = _db.FaceShapeLinks;
            int            currentFaceShapeLinksCount   = _db.FaceShapeLinks.Count;
            FaceShapeLinks expected = _db.FaceShapeLinks.FirstOrDefault(u => u.Id == id);

            // Act
            FaceShapeLinks actual = await _faceShapeLinksContext.Delete(id);

            int updatedFaceShapeLinksCount = _db.FaceShapeLinks.Count;

            _db.FaceShapeLinks = new List <FaceShapeLinks>(currentFaceShapeLinks);

            // Assert
            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(currentFaceShapeLinksCount - 1, updatedFaceShapeLinksCount);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PutFaceShapeLinks(ulong id, [FromBody] FaceShapeLinks faceShapeLinks)
        {
            if (!_authorizationService.ValidateJWTToken(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (id != faceShapeLinks.Id)
            {
                return(BadRequest(new { errors = new { Id = new string[] { "ID sent does not match the one in the endpoint" } }, status = 400 }));
            }

            var correspondingFaceShape = await _context.FaceShapes.FirstOrDefaultAsync(f => f.Id == faceShapeLinks.FaceShapeId);

            if (correspondingFaceShape == null)
            {
                return(NotFound(new { errors = new { FaceShapeId = new string[] { "No matching face shape entry was found" } }, status = 404 }));
            }

            FaceShapeLinks fsl = await _context.FaceShapeLinks.FindAsync(id);

            try
            {
                if (fsl != null)
                {
                    fsl.LinkName    = faceShapeLinks.LinkName;
                    fsl.LinkUrl     = faceShapeLinks.LinkUrl;
                    fsl.FaceShapeId = faceShapeLinks.FaceShapeId;

                    _context.Entry(fsl).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                return(NotFound());
            }
            catch (DbUpdateConcurrencyException)
            {
                return(StatusCode(500));
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> PutFaceShapeLinks(ulong id, [FromBody] FaceShapeLinks faceShapeLinks)
        {
            if (!_authorizationService.ValidateJWTCookie(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (id != faceShapeLinks.Id)
            {
                return(BadRequest(new { errors = new { Id = new string[] { "ID sent does not match the one in the endpoint" } }, status = 400 }));
            }

            var correspondingFaceShape = await _context.FaceShapes.FirstOrDefaultAsync(f => f.Id == faceShapeLinks.FaceShapeId);

            if (correspondingFaceShape == null)
            {
                return(NotFound(new { errors = new { FaceShapeId = new string[] { "No matching face shape entry was found" } }, status = 404 }));
            }

            _context.Entry(faceShapeLinks).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FaceShapeLinksExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }