public void ShouldReturnFalseForIncorrectDateformat() { string[] testValues = new string[] { "11032018", "some text", string.Empty }; foreach (string item in testValues) { Assert.IsFalse(ValidateRegex.IsValidDateFormat(item)); } }
public void ShouldReturnFalseForIncorrectEmail() { string[] testValues = new string[] { "jan.kowalski", "jan@kowalski", "jan@kowalski@com" }; foreach (string item in testValues) { Assert.IsFalse(ValidateRegex.IsEmail(item)); } }
public void ShouldReturnFalseForIncorrectMobilePhone() { string[] testValues = new string[] { "+48696588", "+4869658813", "+486965881", "+48 696 588", "+48 696 588 13", "+48 696 588 1", "some text", string.Empty }; foreach (string item in testValues) { Assert.IsFalse(ValidateRegex.IsMobilePhone(item)); } }
public void ShouldReturnTrueForCorrectMobilePhone() { string[] testValues = new string[] { "+48696588133", "48696588133", "48 696 588 133", "+48 696 588 133", "+48 696 588 133" }; foreach (string item in testValues) { Assert.IsTrue(ValidateRegex.IsMobilePhone(item)); } }
public void ShouldReturnTrueForCorrectPolishZipCode() { string[] testValues = new string[] { "30-816", "75-123", "23-315" }; foreach (string item in testValues) { Assert.IsTrue(ValidateRegex.IsZipCode(item)); } }
public void ShouldReturnFalseForIncorrectWebPageName() { string[] testValues = new string[] { "test.com.pl", "test.com", "some random text", string.Empty }; foreach (string item in testValues) { Assert.IsFalse(ValidateRegex.IsWebPage(item)); } }
public void ShouldReturnTrueForCorrectWebPageName() { string[] testValues = new string[] { "www.test.com", "http://test.com", "https://test.com", "http://www.test.com", "https://www.test.com", "www.test.com.pl", "http://test.com.pl", "https://test.com.pl", "http://www.test.com.pl", "https://www.test.com.pl" }; foreach (string item in testValues) { Assert.IsTrue(ValidateRegex.IsWebPage(item)); } }
public void ShouldReturnFalseForIncorrectPolishZipCode() { string[] testValues = new string[] { "30816", "308-16" }; foreach (string item in testValues) { Assert.IsFalse(ValidateRegex.IsZipCode(item)); } }
public void ShouldReturnTrueForCorrectEmail() { string[] testValues = new string[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }; foreach (string item in testValues) { Assert.IsTrue(ValidateRegex.IsEmail(item)); } }
public void ShouldReturnTrueForCorrectDateformat() { string[] testValues = new string[] { "11/03/2018", "11-3-2018", "11 03 2018", "11.03.2018", "11-03-2018" }; foreach (string item in testValues) { Assert.IsTrue(ValidateRegex.IsValidDateFormat(item)); } }
public void ValidateRegex_Test_NullContext_ExpectedException() { //ARRANGE //set matchpattern to nanp format of xxx-xxx-xxxx string matchPattern = @"^[2-9]\d{2}-\d{3}-\d{4}$"; //set string to validate to a valid phone number string stringToValidate = "334-867-5309"; //create our mocks var serviceMock = new Mock <IOrganizationService>(); var factoryMock = new Mock <IOrganizationServiceFactory>(); var tracingServiceMock = new Mock <ITracingService>(); var workflowContextMock = new Mock <IWorkflowContext>(); //set up a mock service to act like the CRM organization service IOrganizationService service = serviceMock.Object; //set up a mock workflowcontext var workflowUserId = Guid.NewGuid(); var workflowCorrelationId = Guid.NewGuid(); var workflowInitiatingUserId = Guid.NewGuid(); workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId); workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId); workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId); var workflowContext = workflowContextMock.Object; //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later? tracingServiceMock.Setup(t => t.Trace(It.IsAny <string>(), It.IsAny <object[]>())).Callback <string, object[]>((t1, t2) => Console.WriteLine(t1, t2)); var tracingService = tracingServiceMock.Object; //set up a mock servicefactory factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny <Guid>())).Returns(service); var factory = factoryMock.Object; //get new validateregex object ValidateRegex valRegex = new ValidateRegex(); var invoker = new WorkflowInvoker(valRegex); invoker.Extensions.Add <ITracingService>(() => tracingService); //below line commented out to generate exception //invoker.Extensions.Add<IWorkflowContext>(() => workflowContext); invoker.Extensions.Add <IOrganizationServiceFactory>(() => factory); var inputs = new Dictionary <string, object> { { "MatchPattern", matchPattern }, { "StringToValidate", stringToValidate } }; //ACT (assertion is implied) invoker.Invoke(inputs); }
public void ValidateRegex_Test_NullContext_ExpectedException() { //ARRANGE //set matchpattern to nanp format of xxx-xxx-xxxx string matchPattern = @"^[2-9]\d{2}-\d{3}-\d{4}$"; //set string to validate to a valid phone number string stringToValidate = "334-867-5309"; //create our mocks var serviceMock = new Mock<IOrganizationService>(); var factoryMock = new Mock<IOrganizationServiceFactory>(); var tracingServiceMock = new Mock<ITracingService>(); var workflowContextMock = new Mock<IWorkflowContext>(); //set up a mock service to act like the CRM organization service IOrganizationService service = serviceMock.Object; //set up a mock workflowcontext var workflowUserId = Guid.NewGuid(); var workflowCorrelationId = Guid.NewGuid(); var workflowInitiatingUserId = Guid.NewGuid(); workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId); workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId); workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId); var workflowContext = workflowContextMock.Object; //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later? tracingServiceMock.Setup(t => t.Trace(It.IsAny<string>(), It.IsAny<object[]>())).Callback<string, object[]>((t1, t2) => Console.WriteLine(t1, t2)); var tracingService = tracingServiceMock.Object; //set up a mock servicefactory factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny<Guid>())).Returns(service); var factory = factoryMock.Object; //get new validateregex object ValidateRegex valRegex = new ValidateRegex(); var invoker = new WorkflowInvoker(valRegex); invoker.Extensions.Add<ITracingService>(() => tracingService); //below line commented out to generate exception //invoker.Extensions.Add<IWorkflowContext>(() => workflowContext); invoker.Extensions.Add<IOrganizationServiceFactory>(() => factory); var inputs = new Dictionary<string, object> { { "MatchPattern", matchPattern}, { "StringToValidate", stringToValidate } }; //ACT (assertion is implied) invoker.Invoke(inputs); }
public void ShouldReturnFalseForEmptyObject() { object testValue = new object(); Assert.IsFalse(ValidateRegex.IsEmail(testValue)); }
public void ZipCode_ShouldReturnFalseForValueType() { decimal testValue = 30816; Assert.IsFalse(ValidateRegex.IsZipCode(testValue)); }
public void ZipCode_ShouldReturnFalseForEmptyObject() { object testValue = new object(); Assert.IsFalse(ValidateRegex.IsZipCode(testValue)); }
public void ValidateRegex_Test_NullContext_TryCatch() { //ARRANGE //set matchpattern to nanp format of xxx-xxx-xxxx string matchPattern = @"^[2-9]\d{2}-\d{3}-\d{4}$"; //set string to validate to a valid phone number string stringToValidate = "334-867-5309"; //create our mocks var serviceMock = new Mock<IOrganizationService>(); var factoryMock = new Mock<IOrganizationServiceFactory>(); var tracingServiceMock = new Mock<ITracingService>(); var workflowContextMock = new Mock<IWorkflowContext>(); //set up a mock service to act like the CRM organization service IOrganizationService service = serviceMock.Object; //set up a mock workflowcontext var workflowUserId = Guid.NewGuid(); var workflowCorrelationId = Guid.NewGuid(); var workflowInitiatingUserId = Guid.NewGuid(); workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId); workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId); workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId); var workflowContext = workflowContextMock.Object; //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later? tracingServiceMock.Setup(t => t.Trace(It.IsAny<string>(), It.IsAny<object[]>())).Callback<string, object[]>((t1, t2) => Console.WriteLine(t1, t2)); var tracingService = tracingServiceMock.Object; //set up a mock servicefactory factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny<Guid>())).Returns(service); var factory = factoryMock.Object; //get new validateregex object ValidateRegex valRegex = new ValidateRegex(); var invoker = new WorkflowInvoker(valRegex); invoker.Extensions.Add<ITracingService>(() => tracingService); //below line commented out to generate exception //invoker.Extensions.Add<IWorkflowContext>(() => workflowContext); invoker.Extensions.Add<IOrganizationServiceFactory>(() => factory); var inputs = new Dictionary<string, object> { { "MatchPattern", matchPattern}, { "StringToValidate", stringToValidate } }; //instantiate an expection object we can use to see if we threw the right thing Exception expectedException = null; //ACT try { invoker.Invoke(inputs); } catch (Exception ex) { expectedException = ex; } //ASSERT Assert.IsInstanceOfType(expectedException, typeof(InvalidPluginExecutionException)); Assert.AreEqual("Failed to retrieve workflow context.", expectedException.Message); }
public void Webpage_ShouldReturnFalseForEmptyObject() { object testValue = new object(); Assert.IsFalse(ValidateRegex.IsWebPage(testValue)); }
public void Webpage_ShouldReturnFalseForValueType() { decimal testValue = 12345; Assert.IsFalse(ValidateRegex.IsWebPage(testValue)); }
/// <summary> /// The method validates whether a supplied object is valid against a regex pattern. /// </summary> /// <param name="objectToValidate">An object to be valdiated against a regex pattern.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public override bool Validate(object objectToValidate) { return(ValidateRegex.Custom(objectToValidate, pattern)); }
public void ValidateRegex_Test_NullContext_TryCatch() { //ARRANGE //set matchpattern to nanp format of xxx-xxx-xxxx string matchPattern = @"^[2-9]\d{2}-\d{3}-\d{4}$"; //set string to validate to a valid phone number string stringToValidate = "334-867-5309"; //create our mocks var serviceMock = new Mock <IOrganizationService>(); var factoryMock = new Mock <IOrganizationServiceFactory>(); var tracingServiceMock = new Mock <ITracingService>(); var workflowContextMock = new Mock <IWorkflowContext>(); //set up a mock service to act like the CRM organization service IOrganizationService service = serviceMock.Object; //set up a mock workflowcontext var workflowUserId = Guid.NewGuid(); var workflowCorrelationId = Guid.NewGuid(); var workflowInitiatingUserId = Guid.NewGuid(); workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId); workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId); workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId); var workflowContext = workflowContextMock.Object; //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later? tracingServiceMock.Setup(t => t.Trace(It.IsAny <string>(), It.IsAny <object[]>())).Callback <string, object[]>((t1, t2) => Console.WriteLine(t1, t2)); var tracingService = tracingServiceMock.Object; //set up a mock servicefactory factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny <Guid>())).Returns(service); var factory = factoryMock.Object; //get new validateregex object ValidateRegex valRegex = new ValidateRegex(); var invoker = new WorkflowInvoker(valRegex); invoker.Extensions.Add <ITracingService>(() => tracingService); //below line commented out to generate exception //invoker.Extensions.Add<IWorkflowContext>(() => workflowContext); invoker.Extensions.Add <IOrganizationServiceFactory>(() => factory); var inputs = new Dictionary <string, object> { { "MatchPattern", matchPattern }, { "StringToValidate", stringToValidate } }; //instantiate an expection object we can use to see if we threw the right thing Exception expectedException = null; //ACT try { invoker.Invoke(inputs); } catch (Exception ex) { expectedException = ex; } //ASSERT Assert.IsInstanceOfType(expectedException, typeof(InvalidPluginExecutionException)); Assert.AreEqual("Failed to retrieve workflow context.", expectedException.Message); }
/// <summary> /// The method validates whether a supplied object is valid against a web page regex pattern. /// </summary> /// <param name="objectToValidate">An object to be valdiated against regex pattern of a web page address.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public override bool Validate(object objectToValidate) { return(ValidateRegex.IsWebPage(objectToValidate, pattern)); }
/// <summary> /// The method validates whether a supplied object is valid against a mobile phone pattern. /// </summary> /// <param name="objectToValidate">An object to be valdiated against regex pattern of a mobile phone number.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public override bool Validate(object objectToValidate) { return(ValidateRegex.IsMobilePhone(objectToValidate, pattern)); }
public void MobilePhone_ShouldReturnFalseForValueType() { decimal testValue = 12345; Assert.IsFalse(ValidateRegex.IsMobilePhone(testValue)); }
public static Validation <Error, string> ValidateEmail(string str) => ValidateRegex( @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase)(str);
public void DateFormat_ShouldReturnFalseForValueType() { decimal testValue = 12345; Assert.IsFalse(ValidateRegex.IsValidDateFormat(testValue)); }
public void MobilePhone_ShouldReturnFalseForEmptyObject() { object testValue = new object(); Assert.IsFalse(ValidateRegex.IsMobilePhone(testValue)); }
/// <summary> /// The method validates whether a supplied object is valid against a date format pattern. /// </summary> /// <param name="objectToValidate">An object to be valdiated against regex pattern of a date format.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public override bool Validate(object objectToValidate) { return(ValidateRegex.IsValidDateFormat(objectToValidate, pattern)); }
public void ShouldReturnFalseForValueType() { decimal testValue = 12345; Assert.IsFalse(ValidateRegex.IsEmail(testValue)); }
public void DateFormat_ShouldReturnFalseForEmptyObject() { object testValue = new object(); Assert.IsFalse(ValidateRegex.IsValidDateFormat(testValue)); }