public void ConvertFromThrowsWhenNullOrEmptyString()
        {
            var    sut = new EncodingConverter();
            Action act = () => sut.ConvertFrom("");

            act.Should().Throw <NotSupportedException>().WithMessage($"Cannot parse a null or empty string into a {nameof(Encoding)}.");
        }
        public void ConvertFromThrowsWhenEncodingIsUnknown()
        {
            var    sut = new EncodingConverter();
            Action act = () => sut.ConvertFrom("utf-48");

            act.Should().Throw <ArgumentException>().WithMessage("'utf-48' is not a supported encoding name.*");
        }
        public void ConvertFromThrowsWhenInvalidFormat()
        {
            const string value = "utf-8, bam";
            var          sut   = new EncodingConverter();
            Action       act   = () => sut.ConvertFrom(value);

            act.Should().Throw <NotSupportedException>().WithMessage($"'{value}' format is invalid and cannot be parsed into a {nameof(Encoding)}.");
        }
Exemple #4
0
        public void ConvertFromThrowsWhenNullOrEmptyString()
        {
            var sut = new EncodingConverter();

            Assert.That(
                () => sut.ConvertFrom(""),
                Throws.TypeOf <NotSupportedException>().With.Message.EqualTo(string.Format("Cannot parse a null or empty string into a {0}.", typeof(Encoding).Name)));
        }
        public void ConvertToWithoutBom()
        {
            var encoding = new UTF8Encoding();

            var sut         = new EncodingConverter();
            var displayName = sut.ConvertTo(encoding, typeof(string));

            displayName.Should().Be($"{encoding.WebName}");
        }
        public void ConvertToWithBom()
        {
            var encoding = new UTF8Encoding(true);

            var sut         = new EncodingConverter();
            var displayName = sut.ConvertTo(encoding, typeof(string));

            displayName.Should().Be($"{encoding.WebName} {EncodingConverter.ENCODING_SIGNATURE_MODIFIER}");
        }
Exemple #7
0
        public void ConvertFromThrowsWhenInvalidFormat()
        {
            const string value = "utf-8, bam";
            var          sut   = new EncodingConverter();

            Assert.That(
                () => sut.ConvertFrom(value),
                Throws.TypeOf <NotSupportedException>().With.Message.EqualTo(string.Format("'{0}' format is invalid and cannot be parsed into a {1}.", value, typeof(Encoding).Name)));
        }
Exemple #8
0
        public void ConvertFromThrowsWhenEncodingIsUnknown()
        {
            const string value = "utf-48";
            var          sut   = new EncodingConverter();

            Assert.That(
                () => sut.ConvertFrom(value),
                Throws.TypeOf <ArgumentException>().With.Message.StartsWith("'utf-48' is not a supported encoding name."));
        }
Exemple #9
0
        public void ConvertToWithoutBom()
        {
            var encoding = new UTF8Encoding();

            var sut         = new EncodingConverter();
            var displayName = sut.ConvertTo(encoding, typeof(string));

            Assert.That(displayName, Is.EqualTo(string.Format("{0}", encoding.WebName)));
        }
Exemple #10
0
        public void ConvertToWithBom()
        {
            var encoding = new UTF8Encoding(true);

            var sut         = new EncodingConverter();
            var displayName = sut.ConvertTo(encoding, typeof(string));

            Assert.That(displayName, Is.EqualTo(string.Format("{0} {1}", encoding.WebName, EncodingConverter.ENCODING_SIGNATURE_MODIFIER)));
        }
        public void ConvertFromWithBomIsCaseInsensitive()
        {
            var encoding    = new UTF8Encoding(true);
            var displayName = $"{encoding.WebName} {EncodingConverter.ENCODING_SIGNATURE_MODIFIER.ToUpper()}";

            var sut             = new EncodingConverter();
            var convertedObject = sut.ConvertFrom(displayName);

            convertedObject.Should().BeEquivalentTo(encoding);
            convertedObject.Should().BeOfType <UTF8Encoding>();
            var convertedEncoding = convertedObject as UTF8Encoding;

            convertedEncoding.WebName.Should().Be(encoding.WebName);
            convertedEncoding.GetPreamble().Length.Should().BeGreaterThan(0);
        }
        public void ConvertFromWithoutBom()
        {
            var encoding    = new UTF8Encoding();
            var displayName = $"{encoding.WebName}";

            var sut             = new EncodingConverter();
            var convertedObject = sut.ConvertFrom(displayName);

            convertedObject.Should().BeEquivalentTo(encoding);
            convertedObject.Should().BeOfType <UTF8Encoding>();
            var convertedEncoding = convertedObject as UTF8Encoding;

            convertedEncoding.WebName.Should().Be(encoding.WebName);
            convertedEncoding.GetPreamble().Length.Should().Be(0);
        }
Exemple #13
0
        public void ConvertFromWithBom()
        {
            var encoding    = new UTF8Encoding(true);
            var displayName = string.Format("{0} {1}", encoding.WebName, EncodingConverter.ENCODING_SIGNATURE_MODIFIER);

            var sut             = new EncodingConverter();
            var convertedObject = sut.ConvertFrom(displayName);

            Assert.That(convertedObject, Is.InstanceOf <UTF8Encoding>());
            var convertedEncoding = convertedObject as UTF8Encoding;

            // ReSharper disable PossibleNullReferenceException
            Assert.That(convertedEncoding.WebName, Is.EqualTo(encoding.WebName));
            Assert.That(convertedEncoding.GetPreamble().Length, Is.GreaterThan(0));
            // ReSharper restore PossibleNullReferenceException
        }
        public void CanConvertTo()
        {
            var sut = new EncodingConverter();

            sut.CanConvertTo(typeof(string)).Should().BeTrue();
        }
Exemple #15
0
        public void CanConvertTo()
        {
            var sut = new EncodingConverter();

            Assert.That(sut.CanConvertTo(typeof(string)));
        }