Example #1
0
        public void GetEnumerator_ShouldEnumerate_WhenTypeIsNotSpecified()
        {
            // Arrange
            const string data = "Data with - oh no - UNICODE!!  이 테스트는 대단합니다";
            var          i    = 0;

            using (var secureData = new SecureString())
            {
                secureData.Append(data);
                secureData.MakeReadOnly();
                using (var subject = new InsecureString(secureData))
                {
                    // Act
                    foreach (var o in (IEnumerable)subject)
                    {
                        // Assert
                        o.Should().BeOfType <char>();

                        var c = (char)o;
                        c.Should().Be(data[i]);
                        i++;
                    }

                    i.Should().Be(data.Length);
                }
            }
        }
Example #2
0
 public void GetEnumerator_ShouldNotEnumerate_WhenSecureStringHasNoData()
 {
     // Arrange
     using (var secureData = new SecureString())
     {
         secureData.MakeReadOnly();
         using (var subject = new InsecureString(secureData))
         {
             // Act
             foreach (var c in subject)
             {
                 // Assert
                 Assert.True(false, "Should not enumerate.");
             }
         }
     }
 }
Example #3
0
        public void Constructor_ShouldDecryptSecureString_WhenUnicodeIsPresent()
        {
            // Arrange
            const string data = "This is some random data, including unicode characters: ѬѾ";

            using (var secureData = new SecureString())
            {
                secureData.Append(data);
                secureData.MakeReadOnly();

                // Act
                using (var subject = new InsecureString(secureData))
                {
                    // Assert
                    subject.Value.Should().Be(data);
                }
            }
        }
Example #4
0
        public void Constructor_ShouldDecryptSecureString()
        {
            // Arrange
            const string data = "This is some random data";

            using (var secureData = new SecureString())
            {
                secureData.Append(data);
                secureData.MakeReadOnly();

                // Act
                using (var subject = new InsecureString(secureData))
                {
                    // Assert
                    subject.Value.Should().Be(data);
                }
            }
        }
Example #5
0
        public void GetEnumerator_ShouldEnumerate()
        {
            // Arrange
            const string data = "Data with - oh no - UNICODE!!  이 테스트는 대단합니다";
            var          i    = 0;

            using (var secureData = new SecureString())
            {
                secureData.Append(data);
                secureData.MakeReadOnly();
                using (var subject = new InsecureString(secureData))
                {
                    // Act
                    foreach (var c in subject)
                    {
                        // Assert
                        c.Should().Be(data[i]);
                        i++;
                    }

                    i.Should().Be(data.Length);
                }
            }
        }