pa2.Testat/LoggingClient/LoggingClientUnitTest/RegEx.cs

285 lines
9.4 KiB
C#
Raw Normal View History

2020-08-29 14:58:49 +02:00
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LoggingClient.Validators;
namespace LoggingClientUnitTest
{
[TestClass]
public class RegEx
{
[TestMethod]
public void TestCustomerNumberRegex_True()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("CU12345", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestCustomerNumberRegex_False()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("CU123456", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestCustomerNumberRegex_lower_False()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("cu12345", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestCustomerNumberRegex_wrongChar_False()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("ab12345", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestCustomerNumberRegex_wrongCharUpper_False()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("ZZ12345", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestCustomerNumberRegex_onlyDigit_False()
{
// arrange
var customerNumberValidationRule = new CustomerNumberValidationRule();
// act
var result = customerNumberValidationRule.Validate("0012345", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestEmailRegex_True()
{
// arrange
var emailValidationRule = new EmailValidationRule();
// act
var result = emailValidationRule.Validate("test.test@test.com", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestEmailRegex_False()
{
// arrange
var emailValidationRule = new EmailValidationRule();
// act
var result = emailValidationRule.Validate("test.test@.com", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestEmailRegex_2_False()
{
// arrange
var emailValidationRule = new EmailValidationRule();
// act
var result = emailValidationRule.Validate("test..test@a.com", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestEmailRegex_3_False()
{
// arrange
var emailValidationRule = new EmailValidationRule();
// act
var result = emailValidationRule.Validate("test.test@a_com", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestIntRangeValidation_True()
{
// arrange
var intRangeValidationRule = new IntRangeValidationRule();
// act
var result = intRangeValidationRule.Validate("8", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestIntRangeValidation_False()
{
// arrange
var intRangeValidationRule = new IntRangeValidationRule();
// act
var result = intRangeValidationRule.Validate("100", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestPasswordRegex_True()
{
// arrange
var passwordValidationRule = new PasswordValidationRule();
// act
var result = passwordValidationRule.Validate("Test1234?", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestPasswordRegex_noLenght_False()
{
// arrange
var passwordValidationRule = new PasswordValidationRule();
// act
var result = passwordValidationRule.Validate("Test12!", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestPasswordRegex_nolower_False()
{
// arrange
var passwordValidationRule = new PasswordValidationRule();
// act
var result = passwordValidationRule.Validate("TWST1234!", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestPasswordRegex_noUpper_False()
{
// arrange
var passwordValidationRule = new PasswordValidationRule();
// act
var result = passwordValidationRule.Validate("test1234!", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestPasswordRegex_noSpecials_False()
{
// arrange
var passwordValidationRule = new PasswordValidationRule();
// act
var result = passwordValidationRule.Validate("test1234", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestStringRangeValidation_True()
{
// arrange
var stringRangeValidationRule = new StringRangeValidationRule();
// act
var result = stringRangeValidationRule.Validate("Test", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestStringRangeValidation_False()
{
// arrange
var stringRangeValidationRule = new StringRangeValidationRule();
// act
var result = stringRangeValidationRule.Validate("", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_subdomain_True()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("www.google.com", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_prefix_True()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("https://google.com", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_prefix_subdomain_True()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("https://www.google.com", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_prefix_subdomain_endpoint_True()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("https://www.google.com/passwords", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_prefix_subdomain_endpoint_query_True()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("https://www.google.com/passwords?lernen.zbw=rafr1", CultureInfo.CurrentCulture);
// assert
Assert.IsTrue(result.IsValid);
}
[TestMethod]
public void TestUrlRegex_False()
{
// arrange
var urlValidationRule = new UrlValidationRule();
// act
var result = urlValidationRule.Validate("google", CultureInfo.CurrentCulture);
// assert
Assert.IsFalse(result.IsValid);
}
}
}