Beispiel #1
0
        public void ReadSection_IfContentEmpty_ReturnsEmptyResult()
        {
            using (var stream = new MemoryStream())
                using (var reader = new KeyPairFileReader(stream, _encoding))
                {
                    var section = reader.ReadSection();

                    Assert.Empty(section);
                }
        }
Beispiel #2
0
        public void ReadSection_IfSectionIsNotNewLineTerminated_Throws(string content)
        {
            var bytes = Encoding.UTF8.GetBytes(content);

            using (var stream = new MemoryStream(bytes))
                using (var reader = new KeyPairFileReader(stream, _encoding))
                {
                    var exception = Assert.Throws <SignatureException>(() => reader.ReadSection());

                    Assert.Equal("The package signature content is invalid.", exception.Message);
                }
        }
Beispiel #3
0
        public void Dispose_DisposesStreamReader()
        {
            using (var stream = new MemoryStream())
            {
                Assert.True(stream.CanRead);

                using (var reader = new KeyPairFileReader(stream, _encoding))
                {
                }

                Assert.False(stream.CanRead);
            }
        }
Beispiel #4
0
        public void ReadSection_ReadsMultipleSections()
        {
            var bytes = Encoding.UTF8.GetBytes("a:b\r\n\r\nc:d\r\n\r\n");

            using (var stream = new MemoryStream(bytes))
                using (var reader = new KeyPairFileReader(stream, _encoding))
                {
                    var headerSection = reader.ReadSection();

                    Assert.Equal(1, headerSection.Count);
                    Assert.Equal("b", headerSection["a"]);

                    var section = reader.ReadSection();

                    Assert.Equal(1, section.Count);
                    Assert.Equal("d", section["c"]);

                    section = reader.ReadSection();

                    Assert.Empty(section);
                }
        }