public async Task Should_Add_Update_Delete_Links_Successfully()
        {
            MockExternalLinksForCrud();
            var updateDto = new AddEditDeleteExternalLinkDto
            {
                LinksToDelete = new[] { 1, 2 },
                LinksToCreate = new List <NewExternalLinkDto>
                {
                    new NewExternalLinkDto
                    {
                        Name = "newLink1",
                        Url  = "newLink2"
                    }
                },
                LinksToUpdate = new List <ExternalLinkDto>
                {
                    new ExternalLinkDto
                    {
                        Id   = 3,
                        Name = "modifiedLink3",
                        Url  = "http://link3modified.com"
                    }
                },
                OrganizationId = 2,
                UserId         = "testUser"
            };

            await _externalLinkService.UpdateLinksAsync(updateDto);

            _externalLinkDbSet.Received(2).Remove(Arg.Any <ExternalLink>());
            _externalLinkDbSet.Received(1).Add(Arg.Any <ExternalLink>());
            var externalLink = await _externalLinkDbSet.FirstAsync(x => x.Id == 3);

            Assert.AreEqual("modifiedLink3", externalLink.Name);
            Assert.AreEqual("http://link3modified.com", externalLink.Url);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> UpdateLinks(AddEditDeleteExternalLinkViewModel updateLinksViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updateLinksDto = _mapper.Map <AddEditDeleteExternalLinkViewModel, AddEditDeleteExternalLinkDto>(updateLinksViewModel);

            SetOrganizationAndUser(updateLinksDto);

            try
            {
                await _externalLinkService.UpdateLinksAsync(updateLinksDto);
            }
            catch (ValidationException e)
            {
                return(BadRequestWithError(e));
            }

            return(Ok());
        }