public void CanIAddtoStorage() { var url = new Url(); url.OriginalUrl = "http://cool.xyz"; url.Active = true; var inserted = MockStorage.Add(url); Assert.NotNull(inserted); Assert.Equal(url.OriginalUrl, inserted.OriginalUrl); }
public void CannotGetFromStorage() { var url = new Url(); url.OriginalUrl = "long URL"; url.Active = true; var inserted = MockStorage.Add(url); Assert.NotNull(inserted); Assert.Equal(url.OriginalUrl, inserted.OriginalUrl); var retrieved = MockStorage.GetById(999); Assert.Null(retrieved); }
public IActionResult CreateURL(UrlViewModel model) { if (!ModelState.IsValid) { return(BadRequest(model)); } //string shortenUrl = _shortenerService.Shorten(model.OriginalUrl); var url = new Url(); url.OriginalUrl = model.OriginalUrl; url.Active = true; var inserted = MockStorage.Add(url); var result = new UrlViewModel { Id = inserted.Id, ShortenUrl = $"{HttpContext.Request.Path}/{inserted.Id}" }; return(View("Success", result)); }
public void CannotAddToStorage() { Url url = null; Assert.Throws <ArgumentNullException>(() => MockStorage.Add(url)); }