public void 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" }; _externalLinkService.UpdateLinks(updateDto); _externalLinkDbSet.Received(2).Remove(Arg.Any <ExternalLink>()); _externalLinkDbSet.Received(1).Add(Arg.Any <ExternalLink>()); Assert.AreEqual("modifiedLink3", _externalLinkDbSet.First(x => x.Id == 3).Name); Assert.AreEqual("http://link3modified.com", _externalLinkDbSet.First(x => x.Id == 3).Url); }
public IHttpActionResult UpdateLinks(AddEditDeleteExternalLinkViewModel updateLinksViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updateLinksDto = _mapper.Map <AddEditDeleteExternalLinkViewModel, AddEditDeleteExternalLinkDTO>(updateLinksViewModel); SetOrganizationAndUser(updateLinksDto); try { _externalLinkService.UpdateLinks(updateLinksDto); } catch (ValidationException e) { return(BadRequestWithError(e)); } var cache = Configuration.CacheOutputConfiguration().GetCacheOutputProvider(Request); cache.RemoveStartsWith(Configuration.CacheOutputConfiguration().MakeBaseCachekey((ExternalLinkController t) => t.GetAll())); return(Ok()); }
public IHttpActionResult UpdateLinks(AddEditDeleteExternalLinkViewModel updateLinksViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updateLinksDto = _mapper.Map <AddEditDeleteExternalLinkViewModel, AddEditDeleteExternalLinkDTO>(updateLinksViewModel); SetOrganizationAndUser(updateLinksDto); try { _externalLinkService.UpdateLinks(updateLinksDto); } catch (ValidationException e) { return(BadRequestWithError(e)); } return(Ok()); }