Exemplo n.º 1
0
        public void Convert_Source_Destination()
        {
            // Arrange
            var converter = new ChainedObjectConverter <object?, string?>(obj => obj?.ToString());

            // Act & Assert

            Assert.AreEqual(converter.Convert(null), null);
            Assert.AreEqual(converter.Convert(new object()), "System.Object");
            Assert.AreEqual(converter.Convert(new string('A', 5)), "AAAAA");
            Assert.AreEqual(converter.Convert("778899"), "778899");
        }
Exemplo n.º 2
0
        public void Convert_SourceAndObjectConverter_Destination()
        {
            // Arrange
            var converter1 = new ObjectConverter <object?, string?>(obj => $"{obj?.GetType().Name ?? "NULL"}");
            var converter2 = new ChainedObjectConverter <object?, string?>(obj => $"{obj} : {obj?.ToString()?.Length}", converter1);

            // Act & Assert

            Assert.AreEqual(converter2.Convert(null), "NULL : 4");
            Assert.AreEqual(converter2.Convert(new object()), "Object : 6");
            Assert.AreEqual(converter2.Convert(new DateTime()), "DateTime : 8");
            Assert.AreEqual(converter2.Convert("778899"), "String : 6");
        }