public void AddLink(string linkName, string linkEndpoint) { Uri uri = null; try { uri = new Uri(linkEndpoint); } catch (Exception e) { Clients.All.error(e.Message); return; } var dto = new LinksConfigurationDto { LinkEndpoint = linkEndpoint, LinkName = linkName }; var result = LinksService.AddLink(dto); if (result != null) { Clients.All.success(string.Format("You have added {0}!", dto.LinkName)); Clients.All.addLink(result.Id); } }
public void UpdateLink() { var dto = new LinksConfigurationDto { Id = 1, LinkEndpoint = "www.microsoft.com", LinkName = "Microsoft" }; var result = Service.UpdateLink(dto); Assert.That(result, Is.True); MockRepo.Verify(x => x.Get(1), Times.Once); MockRepo.Verify(x => x.Update(It.IsAny <LinksConfiguration>()), Times.Once); }
public bool UpdateLink(LinksConfigurationDto dto) { var entity = Repo.Get(dto.Id); entity.LinkEndpoint = dto.LinkEndpoint; entity.LinkName = dto.LinkName; var result = Repo.Update(entity); return(result); }
public void AddLink() { var dto = new LinksConfigurationDto { Id = 1, LinkEndpoint = "google.com", LinkName = "Google" }; var result = Service.AddLink(dto); Assert.That(result, Is.Not.Null); Assert.That(result.Id, Is.EqualTo(ExpectedLink.Id)); Assert.That(result.LinkEndpoint, Is.EqualTo(ExpectedLink.LinkEndpoint)); Assert.That(result.LinkName, Is.EqualTo(ExpectedLink.LinkName)); MockRepo.Verify(x => x.Insert(It.IsAny <LinksConfiguration>()), Times.Once); }
public LinksConfigurationDto AddLink(LinksConfigurationDto link) { var entity = new LinksConfiguration { LinkEndpoint = link.LinkEndpoint, LinkName = link.LinkName }; var id = Repo.Insert(entity); var result = Repo.Get(id); return(new LinksConfigurationDto { Id = result.Id, LinkName = result.LinkName, LinkEndpoint = result.LinkEndpoint }); }
public void MockSetup() { var f = new Fixture(); var mockLinks = new Mock <ILinksConfiguration>(); _dto = f.Create <LinksConfigurationDto>(); _dtos = f.Build <LinksConfigurationDto>().With(x => x.LinkEndpoint, "http://www.google.com").CreateMany(); mockLinks.Setup(x => x.AddLink(It.IsAny <LinksConfigurationDto>())).Returns(_dto); mockLinks.Setup(x => x.GetLinks()).Returns(_dtos); mockLinks.Setup(x => x.RemoveLink(It.IsAny <int>())); mockLinks.Setup(x => x.UpdateLink(It.IsAny <LinksConfigurationDto>())).Returns(true); _controller = new LinksConfigurationController(mockLinks.Object); }
public ActionResult UpdateLink(LinksViewModel config) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var dto = new LinksConfigurationDto { Id = config.Id, LinkName = config.LinkName, LinkEndpoint = config.LinkEndpoint.ToString() }; var result = Service.UpdateLink(dto); if (result) { return(RedirectToAction("Index")); } return(View("Error")); }