Ejemplo n.º 1
0
            public void ToBool_OnNonNumericString_ThrowsFormatException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.To<bool>(), Throws.TypeOf<FormatException>());
            }
Ejemplo n.º 2
0
            public void ToByteArray_OnNonHexString_ThrowsValidationException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.ToByteArray(), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<FormatException>());
            }
Ejemplo n.º 3
0
            public void IsNullOrEmpty_OnValidString_ReturnsFalse()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.IsNullOrEmpty(), Is.False);
            }
Ejemplo n.º 4
0
            public void IsValidUrl_OnNormalTextString_ReturnsFalse()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.IsValidUrl(), Is.False);
            }
Ejemplo n.º 5
0
            public void SHA1Hash_OnAllLatinString_HandlesAllLatinCharacters()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.SHA1Hash(), Throws.Nothing);
            }
Ejemplo n.º 6
0
            public void ToConvertible_OnNonNumericString_ThrowsInvalidCastException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.To<IConvertible>(), Throws.TypeOf<InvalidCastException>());
            }
Ejemplo n.º 7
0
            public void TryToGuid_OnInvalidString_ReturnsFalse()
            {
                Guid guid;
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.TryToGuid(out guid), Is.False);
            }
Ejemplo n.º 8
0
            public void Decrypt_OnBadString_WithGoodKey_DoesNotDecrypt()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var validKey = fixture.Create<string>();

                Assert.That(() => stringValue.Decrypt(validKey), Is.Not.EqualTo(stringValue));
            }
Ejemplo n.º 9
0
            public void Left_OnString_LengthGreaterThanStringLength_ReturnsCorrectSubstring()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var length = stringValue.Length + 1;

                Assert.That(() => stringValue.Left(length), Is.EqualTo(stringValue));
            }
Ejemplo n.º 10
0
            public void Decrypt_OnBadString_WithGoodKey_ReturnsNull()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var validKey = fixture.Create<string>();

                Assert.That(() => stringValue.Decrypt(validKey), Is.Null);
            }
Ejemplo n.º 11
0
            public void TryToGuid_OnInvalidString_OutputsEmptyGuid()
            {
                Guid guid;
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                stringValue.TryToGuid(out guid);

                Assert.That(() => guid, Is.EqualTo(Guid.Empty));
            }
Ejemplo n.º 12
0
            public void ToString_OnEmptySequence_WithProjection_WithSeparator_ReturnsEmptyString()
            {
                var emptySequence = Enumerable.Empty<object>();
                var fixture = new LatinStringFixture();
                var projection = fixture.Create<Func<object, string>>();
                var separator = fixture.Create<string>();

                Assert.That(() => emptySequence.ToString(projection, separator), Is.Empty);
            }
Ejemplo n.º 13
0
            public void ContainsAny_OnCharacter_OnStringWithMany_ReturnsTrue()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var charValue = fixture.Create<char>();
                stringValue += new string(charValue, 10);

                Assert.That(() => stringValue.ContainsAny(charValue), Is.True);
            }
Ejemplo n.º 14
0
            public void ContainsAny_OnCharacter_OnStringWithNone_ReturnsFalse()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var charValue = fixture.Create<char>();
                stringValue = new string(stringValue.Exclude(charValue).ToArray());

                Assert.That(() => stringValue.ContainsAny(charValue), Is.False);
            }
Ejemplo n.º 15
0
            public void ToString_OnEmptySequence_WithNullProjection_WithSeparator_ThrowsValidationException()
            {
                var emptySequence = Enumerable.Empty<object>();
                var fixture = new LatinStringFixture();
                Func<object, string> nullProjection = null;
                var separator = fixture.Create<string>();

                Assert.That(() => emptySequence.ToString(nullProjection, separator), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
Ejemplo n.º 16
0
            public void Decrypt_OnEncryptedString_KeyIsCaseSensitive()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var upperKey = stringValue.ToUpperInvariant();
                var lowerKey = stringValue.ToLowerInvariant();
                var encryptedWithUpper = stringValue.Encrypt(upperKey);

                Assert.That(() => encryptedWithUpper.Decrypt(lowerKey), Is.Not.EqualTo(stringValue));
            }
Ejemplo n.º 17
0
            public void AddLine_OnGoodStringBuilderWithGoodString_WithLineWriter_ReturnsStringBuilder()
            {
                var fixture = new LatinStringFixture();
                var testString = fixture.Create<string>();
                var stringBuilder = fixture.Create<StringBuilder>();
                var mockLineWriter = new Mock<ILineWriter>();
                ILineWriter lineWriter = mockLineWriter.Object;
                var actual = stringBuilder.AddLine(testString, lineWriter);

                Assert.That(() => actual, Is.EqualTo(stringBuilder));
            }
Ejemplo n.º 18
0
            public void Encrypt_OnString_EncryptIsCalled()
            {
                var mockEncryptor = new Mock<IEncrypt>();
                mockEncryptor.Setup(m => m.EncryptAES(It.IsAny<string>(), It.IsAny<string>())).Returns(It.IsAny<string>());
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                IEncrypt encrypt = mockEncryptor.Object;
                stringValue.Encrypt(stringValue, encrypt);

                mockEncryptor.Verify(m => m.EncryptAES(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
            }
Ejemplo n.º 19
0
            public void Encrypt_OnString_StringIsEncrypted()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var output = stringValue.Encrypt(stringValue);

                Assert.That(() => output, Is.Not.EqualTo(stringValue));
            }
Ejemplo n.º 20
0
            public void ContainsAny_OnCharacter_OnString_IsCaseSensitive()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var upperCaseChar = stringValue.First(char.IsUpper);
                stringValue = stringValue.ToLowerInvariant();

                Assert.That(() => stringValue.ContainsAny(upperCaseChar), Is.False);
            }
Ejemplo n.º 21
0
            public void Parse_UnsupportedConversionType_OnBogusString_ThrowsNotSupportedException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.Parse<ParseTest>(), Throws.TypeOf<NotSupportedException>());
            }
Ejemplo n.º 22
0
            public void Left_OnString_WithNegativeLength_ThrowsValidationException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var intValue = fixture.Create<int>();
                intValue = -intValue;

                Assert.That(() => stringValue.Left(intValue), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentOutOfRangeException>());
            }
Ejemplo n.º 23
0
            public void ContainsAny_OnNullCharacters_OnString_ThrowsValidationException()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                IEnumerable<char> nullChars = null;

                Assert.That(() => stringValue.ContainsAny(nullChars), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
Ejemplo n.º 24
0
            public void ContainsAny_OnEmptyCharacters_OnString_ReturnsFalse()
            {
                var emptyCharacters = Enumerable.Empty<char>();
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();

                Assert.That(() => stringValue.ContainsAny(emptyCharacters), Is.False);
            }
Ejemplo n.º 25
0
 public void Encrypt_OnString_OutputIsInCorrectFormat()
 {
     var fixture = new LatinStringFixture();
     var stringValue = fixture.Create<string>();
     var output = stringValue.Encrypt(stringValue);
     Assert.That(() => Convert.FromBase64String(output), Throws.Nothing);
 }
Ejemplo n.º 26
0
            public void Encrypt_OnString_WithShortKey_ThrowsValidationError()
            {
                var mockEncryptor = new Mock<IEncrypt>();
                mockEncryptor.Setup(m => m.EncryptAES(It.IsAny<string>(), It.IsAny<string>())).Returns(It.IsAny<string>());
                mockEncryptor.Setup(m => m.MinimumPasswordLength).Returns(12);
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var shortKey = stringValue.Substring(0, 3);
                IEncrypt encrypt = mockEncryptor.Object;

                Assert.That(() => stringValue.Encrypt(shortKey, encrypt), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentOutOfRangeException>());
            }
Ejemplo n.º 27
0
            public void Encrypt_OnString_WithKey_ChecksMinimumSize()
            {
                var mockEncryptor = new Mock<IEncrypt>();
                mockEncryptor.Setup(m => m.EncryptAES(It.IsAny<string>(), It.IsAny<string>())).Returns(It.IsAny<string>());
                mockEncryptor.Setup(m => m.MinimumPasswordLength).Returns(12);
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                IEncrypt encryptor = mockEncryptor.Object;
                stringValue.Encrypt(stringValue, encryptor);

                mockEncryptor.VerifyGet(m => m.MinimumPasswordLength, Times.AtLeastOnce());
            }
Ejemplo n.º 28
0
            public void Left_OnString_LengthLessThanStringLength_ReturnsCorrectSubstring()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var length = stringValue.Length - 1;
                var expected = stringValue.Substring(0, length);

                Assert.That(() => stringValue.Left(length), Is.EqualTo(expected));
            }
Ejemplo n.º 29
0
            public void Encrypt_OnString_SourceIsCaseSensitive()
            {
                var fixture = new LatinStringFixture();
                var stringValue = fixture.Create<string>();
                var upperSource = stringValue.ToUpperInvariant();
                var lowerSource = stringValue.ToLowerInvariant();
                var encryptedWithUpper = upperSource.Encrypt(stringValue);
                var encryptedWithLower = lowerSource.Encrypt(stringValue);

                Assert.That(() => encryptedWithUpper, Is.Not.EqualTo(encryptedWithLower));
            }
Ejemplo n.º 30
0
 public void Encrypt_OnString_OutputMutatesOnSubsequentCallsWithSameInput()
 {
     var fixture = new LatinStringFixture();
     var stringValue = fixture.Create<string>();
     var lastTry = stringValue.Encrypt(stringValue);
     string currentTry = null;
     for (var i = 0; i < 10; i++)
     {
         currentTry = stringValue.Encrypt(stringValue);
         if (lastTry != currentTry)
         {
             break;
         }
     }
     Assert.That(() => lastTry, Is.Not.EqualTo(currentTry));
 }