示例#1
0
        public static void ToBytes_EncodingIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            const string ToEncode = "my string";

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => ToEncode.ToBytes(null));
        }
示例#2
0
        public static void ToAsciiBytes_StringToEncodeIsNotEmpty_ReturnsAsciiBytes()
        {
            // Arrange
            const string ToEncode = "Ascii";
            const string Expected = "[65][115][99][105][105]";

            // Act
            byte[] asciiBytes = ToEncode.ToAsciiBytes();

            // Assert
            var bytesPrintout = new StringBuilder();

            foreach (byte b in asciiBytes)
            {
                bytesPrintout.Append("[" + b.ToString(CultureInfo.CurrentCulture) + "]");
            }

            Assert.Equal(Expected, bytesPrintout.ToString());
        }
示例#3
0
        public static void ToUtf8Bytes_StringToEncodeIsNotEmpty_ReturnsUtf8Bytes()
        {
            // Arrange
            const string ToEncode = "This unicode string contains two characters " +
                                    "with codes outside an 8-bit code range, " +
                                    "Pi (\u03a0) and Sigma (\u03a3).";
            const string Expected = "[84][104][105][115][32][117][110][105][99][111][100][101][32][115][116][114][105][110][103][32][99][111][110][116][97][105][110][115][32][116][119][111][32][99][104][97][114][97][99][116][101][114][115][32][119][105][116][104][32][99][111][100][101][115][32][111][117][116][115][105][100][101][32][97][110][32][56][45][98][105][116][32][99][111][100][101][32][114][97][110][103][101][44][32][80][105][32][40][206][160][41][32][97][110][100][32][83][105][103][109][97][32][40][206][163][41][46]";

            // Act
            byte[] utf8Bytes = ToEncode.ToUtf8Bytes();

            // Assert
            var bytesPrintout = new StringBuilder();

            foreach (byte b in utf8Bytes)
            {
                bytesPrintout.Append("[" + b.ToString(CultureInfo.CurrentCulture) + "]");
            }

            Assert.Equal(Expected, bytesPrintout.ToString());
        }