public void SetUp()
 {
     testPerson = new Person {
         Name = "Phil", Age = 22, Height = 190
     };
     printer = ObjectPrinter.For <Person>();
 }
 public void SetUp()
 {
     printer = ObjectPrinter.For <Person>();
     person  = new Person {
         Name = "Alex", Age = 19, Height = 1.0001
     };
 }
Beispiel #3
0
 public void SetUp()
 {
     person = new Person
     {
         Name    = "Alex",
         Age     = 19,
         Height  = 1.85,
         Surname = "Brown"
     };
     person2 = new Person
     {
         Name    = "Jame",
         Age     = 20,
         Height  = 1.92,
         Surname = "Smith"
     };
     person3 = new Person
     {
         Name    = "John",
         Age     = 14,
         Height  = 1.77,
         Surname = "Muller"
     };
     printer = ObjectPrinter.For <Person>();
 }
        public void SameObjectsAreNotRecursiveLinks()
        {
            var config = new PrintingConfig <PathNode>();

            var printed = config.PrintToString(pathNode);

            AssertPrinting(printed, new string[0], new[] { "Recursive link" });
        }
        public void NullShouldBePrintCorrect()
        {
            var config = new PrintingConfig <Dictionary <int, int> >();

            var printed = config.PrintToString(null);

            AssertPrinting(printed, new[] { "null" }, new string[0]);
        }
        public void RecursiveLinksShouldNotBeBreakingApp()
        {
            var config = new PrintingConfig <PathNode>();

            var printed = config.PrintToString(pathNodeWithRecursiveLinks);

            AssertPrinting(printed, new[] { "Recursive link" }, new string[0]);
        }
Beispiel #7
0
        public void PrintToString_NotThrowsNullReferenceException_IfPropertyIsNull()
        {
            printer = printer
                      .SetAlternateSerialize(x => x.Name, x => null)
                      .SetTrimming(x => x.Name, 4);
            Action act = () => printer.PrintToString(person);

            act.Should().NotThrow <NullReferenceException>();
        }
        public void StringMustBeCropped()
        {
            var config = new PrintingConfig <Person>();

            config.Select <string>().CropTo(2);

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Je" }, new[] { "ff" });
        }
        public void AlternateSerializeWayByType()
        {
            var config = new PrintingConfig <Person>();

            config.Select <int>().SetSerializeWay(value => $"This is int: {value}");

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "This is int:" }, new string[0]);
        }
        public void ExcludePropertyByName()
        {
            var config = new PrintingConfig <Person>();

            config.Exclude(x => x.Age);

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Id" }, new[] { "Age" });
        }
        public void ExcludePropertyByType()
        {
            var config = new PrintingConfig <Person>();

            config.Exclude <int>();

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Name", "SleptToday" }, new[] { "Age", "Id" });
        }
        public void SpecificCulture()
        {
            var config = new PrintingConfig <Person>();

            config.Select <double>().SetCulture(specificCulture);

            person.Height = double.NaN;
            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "https://habr.com/ru/news/t/526412/" }, new string[0]);
        }
        public void AlternateSerializeWayByName()
        {
            var config = new PrintingConfig <Person>();

            config.Select(x => x.Width).SetSerializeWay(value => "Secret number");
            config.Select(x => x.Height).SetSerializeWay(value => $"Around {Math.Round(value, 0)}");

            var printed = config.PrintToString(person);

            AssertPrinting(printed, new[] { "Secret number", "Around 33" }, new[] { "99" });
        }
Beispiel #14
0
 public void SetUp()
 {
     printer = ObjectPrinter.For <Person>();
     person  = new Person
     {
         Age    = 19,
         Height = 188.9,
         Name   = "Alexander",
         Id     = Guid.Empty
     };
     newLine = Environment.NewLine;
 }
        public void CanBePrintEnumerable()
        {
            var config = new PrintingConfig <List <int> >();
            var list   = new List <int>()
            {
                1, 99, 2
            };
            var expectedString = "[ 1, 99, 2 ]";

            var printed = config.PrintToString(list);

            AssertPrinting(printed, new[] { expectedString }, new string[0]);
        }
        public void ObjectPrinter_TzarPrintingCycleReference()
        {
            var tzar1 = new Tzar("Serega", 18);
            var tzar2 = new Tzar("Kolya", 74);
            var tzar3 = new Tzar("Ekaterina", 45);

            tzar1.PreviousTzar = tzar2;
            tzar1.NextTzar     = tzar3;
            tzar2.PreviousTzar = tzar1;
            var printer = new PrintingConfig <Tzar>();
            var str     = printer.PrintToString(tzar1);

            str.Should()
            .Be(
                "Tzar\r\n	Age = 18\r\n	Name = Serega\r\n	PreviousTzar = Tzar\r\n		Age = 74\r\n		Name = Kolya\r\n		NextTzar = null\r\n		Id = 1\r\n	NextTzar = Tzar\r\n		Age = 45\r\n		Name = Ekaterina\r\n		PreviousTzar = null\r\n		NextTzar = null\r\n		Id = 2\r\n	Id = 0\r\n");
        }
        public void CanBePrintDictionary()
        {
            var config     = new PrintingConfig <Dictionary <string, string> >();
            var dictionary = new Dictionary <string, string>()
            {
                { "hello", "world" },
                { "1", "2" }
            };
            var expectedStrings = new List <string>()
            {
                "{ hello: world }", "{ 1: 2 }"
            };

            var printed = config.PrintToString(dictionary);

            AssertPrinting(printed, expectedStrings, new string[0]);
        }
        public void SetUp()
        {
            personPrinter = ObjectPrinter.For <Person>();
            person        = new Person
            {
                Id     = Guid.Empty,
                Name   = "John Smith",
                Age    = 69,
                Height = 13.37
            };

            myCustomObjectPrinter = ObjectPrinter.For <MyCustomObject>();
            myCustomObject        = new MyCustomObject
            {
                JustAField            = 1337,
                StringProperty        = "string",
                AnotherStringProperty = "another string",
                Person = person
            };

            myObjectWithEnumerablesPrinter = ObjectPrinter.For <MyObjectWithEnumerables>();
            myObjectWithEnumerables        = new MyObjectWithEnumerables
            {
                Array = new[] { 1, 2, 3 },
                ListOfComplexObjects = new List <Person>
                {
                    person,
                    person
                },
                Dictionary = new Dictionary <string, string>
                {
                    { "Somebody once told me", "the world is gonna roll me" },
                    { "I ain't the sharpest", "tool in the shed" }
                }
            };
        }
Beispiel #19
0
        public async Task PrintDespatchLabels(List <vGetChassisNumbers> data, PrintingConfig _printing)
        {
            DirectoryInfo di = new DirectoryInfo(@"PDFservices\Data\");

            int c = 0;
            List <vGetChassisNumbers> sortedData     = data.OrderBy(x => x.ChassisNumber).ToList();
            List <string>             pdfPagesLabel1 = new List <string>();
            List <string>             pdfPagesLabel2 = new List <string>();

            string LabelprinterName = _printing.LabelPrinterName; //"SATO WS408";
            string mergedLabels1    = "";
            string mergedLabels2    = "";
            bool   usePdf           = true;

            foreach (var i in sortedData)
            {
                int      tLabel1copies     = 2;
                int      tLabel2copies     = 2;
                string   customerProductNo = i.MCusSupStkCode;
                string   stockDescription  = i.MStockDes;
                string   chassisNo         = i.ChassisNumber;
                string   stockCode         = i.MStockCode;
                DateTime despatchDate      = i.MLineShipDate;

                ThermalLabel tLabel1 = new V1Label(customerProductNo, stockDescription, chassisNo, despatchDate);
                ThermalLabel tLabel2 = new V2Label(stockCode, customerProductNo);

                var dir = Path.Combine("PDFservices", "Data");

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                if (usePdf)
                {
                    var filepath1 = Path.Combine(dir, Guid.NewGuid() + ".pdf");
                    var filepath2 = Path.Combine(dir, Guid.NewGuid() + ".pdf");

                    while (tLabel1copies > 0)
                    {
                        pdfPagesLabel1.Add(Export.Export.ExportToPDF(tLabel1, filepath1));
                        tLabel1copies--;
                    }

                    while (tLabel2copies > 0)
                    {
                        pdfPagesLabel2.Add(Export.Export.ExportToPDF(tLabel2, filepath2));
                        tLabel2copies--;
                    }
                }
                else
                {
                    var filepath1 = Path.Combine(dir, Guid.NewGuid() + ".pdf");
                    var filepath2 = Path.Combine(dir, Guid.NewGuid() + ".pdf");

                    Export.Export.PrintZpl(tLabel1, filepath1, LabelprinterName, tLabel1copies);
                    Export.Export.PrintZpl(tLabel2, filepath2, LabelprinterName, tLabel2copies);
                }
                c++;
            }
            String[] pdfLabelArr1 = pdfPagesLabel1.ToArray();
            String[] pdfLabelArr2 = pdfPagesLabel2.ToArray();

            if (usePdf)
            {
                mergedLabels1 = PDFSharp.MergeMultiplePDFIntoSinglePDF(pdfLabelArr1, Guid.NewGuid().ToString());
                mergedLabels2 = PDFSharp.MergeMultiplePDFIntoSinglePDF(pdfLabelArr2, Guid.NewGuid().ToString());

                await PrintingService.PDFPrinting.PDFToPrinter(mergedLabels1, LabelprinterName);

                await PrintingService.PDFPrinting.PDFToPrinter(mergedLabels2, LabelprinterName);
            }

            File.Delete(mergedLabels1);
            File.Delete(mergedLabels2);
            foreach (var f in pdfPagesLabel1)
            {
                File.Delete(f);
            }
            foreach (var f in pdfPagesLabel2)
            {
                File.Delete(f);
            }
            foreach (var f in pdfLabelArr1)
            {
                File.Delete(f);
            }
            foreach (var f in pdfLabelArr2)
            {
                File.Delete(f);
            }
        }
Beispiel #20
0
 public void SetUp()
 {
     printer = ObjectPrinter.For <Person>();
 }
Beispiel #21
0
 public TypeEntity(PrintingConfig <TOwner> config, Dictionary <Type, Delegate> serializeWays)
 {
     this.config        = config;
     this.serializeWays = serializeWays;
 }
 public PropertyPrintingConfig(PrintingConfig <TOwner> printingConfig, PropertyInfo property = null)
 {
     this.printingConfig = printingConfig;
     this.property       = property;
 }
 public PropertyPrintingConfig(PrintingConfig <TOwner> printingConfig, string propertyName = null)
 {
     this.printingConfig = printingConfig;
     this.propertyName   = propertyName;
 }
Beispiel #24
0
 public PropertyPrintingConfig(PrintingConfig <TOwner> printingConfig, string propertyName = null)
 {
     ParentConfig = printingConfig;
     PropertyName = propertyName;
 }
 public static string PrintToString <T>(this PrintingConfig <T> printingConfig, T objectToSerialize)
 {
     return(new Serializer <T>(printingConfig).Serialize(objectToSerialize));
 }
Beispiel #26
0
 public static string PrintToString <T>(T obj, PrintingConfig <T> configuration)
 {
     return(configuration.GetStringRepresentation(obj));
 }
Beispiel #27
0
 public void PrintToString_PrintingWithCulture_IfCultureWasSet()
 {
     printer = printer.SetCulture <double>(CultureInfo.InvariantCulture);
     printer.PrintToString(person).Should().Contain($"{nameof(person.Height)} = 1.85");
 }
Beispiel #28
0
 public PropertyEntity(PrintingConfig <TOwner> config, MemberInfo property, Dictionary <MemberInfo, Delegate> serializeWays)
 {
     this.config        = config;
     this.serializeWays = serializeWays;
     this.property      = property;
 }
Beispiel #29
0
 public void PrintToString_PrintingPropertyByAlternateSerializing()
 {
     printer = printer.SetAlternateSerialize(x => x.Name, x => x + "!!");
     printer.PrintToString(person).Should().Contain($"{nameof(person.Name)} = Alex!!");
 }
Beispiel #30
0
 public void PrintToString_PrintingFieldByAlternateSerializing()
 {
     printer = printer.SetAlternateSerialize(x => x.Surname, x => x + "!!");
     printer.PrintToString(person).Should().Contain($"{nameof(person.Surname)} = Brown!!");
 }