public void LinkIsNotCreatedWhenAnInvalidUrlIsSupplied() { // Arrange var validator = new CreateLinkRequestValidator(); var urls = new List <string> { "http", "http://", "http://www", ".com", "SomeUrl", "SomeUrl.c", "http://someurl.##", "http://someurl.a", "1.1" }; // Act foreach (var url in urls) { var request = new CreateLinkRequest { Url = url }; var actual = validator.Validate(request); // Assert Assert.AreEqual(1, actual.Errors.Count); Assert.AreEqual("The URL provided is invalid. Please provide a valid URL.", actual.Errors.Last(x => x.PropertyName == "Url").ErrorMessage); } }
public void LinkIsCreatedWhenAValidUrlIsSupplied() { // Arrange var validator = new CreateLinkRequestValidator(); var urls = new List <string> { "someurl.com", "someurl.co", "www.someurl.com", "http://www.someurl.com", "https://www.someurl.com", "https://www.someurl.com/", "https://www.someurl.com/someroute", "https://www.someurl.com/someroute?q=", "https://www.someurl.com/someroute?q=asdasd", "192.168.1.1", "1.1.1.1" }; // Act foreach (var url in urls) { var request = new CreateLinkRequest { Url = url }; var actual = validator.Validate(request); // Assert Assert.AreEqual(0, actual.Errors.Count); } }
public void ErrorIfNullUrl() { var sut = new CreateLinkRequestValidator(null, new TagValidator(_tagRepo)); var results = sut.Validate(new CreateLinkRequest() { }); Assert.IsFalse(results.IsValid); Assert.IsTrue(results.Errors.Any(m => m.PropertyName == nameof(CreateLinkRequest.Url))); }
public void FailsUrlWithoutScheme() { var sut = new CreateLinkRequestValidator(null, new TagValidator(_tagRepo)); var results = sut.Validate(new CreateLinkRequest() { Url = "www.google.com" }); Assert.IsFalse(results.IsValid); Assert.IsTrue(results.Errors.Any(m => m.PropertyName == nameof(CreateLinkRequest.Url))); }
public void RequiresValidUrl() { var linkRepo = new Mock <ILinkRepository>(); linkRepo.Setup(m => m.KeyExists(It.IsAny <string>())).Returns(false); var sut = new CreateLinkRequestValidator(linkRepo.Object, new TagValidator(_tagRepo)); var results = sut.Validate(new CreateLinkRequest() { Key = "Test", Url = "bad url" }); Assert.IsFalse(results.IsValid); Assert.IsTrue(results.Errors.Any(m => m.PropertyName == nameof(CreateLinkRequest.Url))); }
public void LinkIsNotCreatedWhenNoUrlIsSupplied() { // Arrange var validator = new CreateLinkRequestValidator(); var request = new CreateLinkRequest { Url = string.Empty }; // Act var actual = validator.Validate(request); // Assert Assert.AreEqual(2, actual.Errors.Count); Assert.AreEqual("Please enter a URL", actual.Errors.First(x => x.PropertyName == "Url").ErrorMessage); Assert.AreEqual("The URL provided is invalid. Please provide a valid URL.", actual.Errors.Last(x => x.PropertyName == "Url").ErrorMessage); }
public void RequiresUniqueKey() { var linkRepo = new Mock <ILinkRepository>(); linkRepo.Setup(m => m.KeyExists(It.IsAny <string>())).Returns(true); _db.Insert(new Tag() { Key = "T1", Name = "Tag 1" }); var sut = new CreateLinkRequestValidator(linkRepo.Object, new TagValidator(_tagRepo)); var results = sut.Validate(new CreateLinkRequest() { Url = "http://www.google.com", Key = "werd", Tags = new HashSet <string>() { "T1" } }); Assert.IsFalse(results.IsValid); Assert.IsTrue(results.Errors.Any(m => m.PropertyName == nameof(CreateLinkRequest.Key))); }