public void CsvLogFieldListReaderTests_Ctor_Success()
        {
            // Arrange
            var mockTextWriter = new Mock <TextWriter>();
            var uut            = new PetReportGeneratorDynamic(mockTextWriter.Object);

            var pets = new List <IReportable>()
            {
                new Dog(new Owner {
                    Firstname = "Jim", Lastname = "Rogers", JoinedPractice = new DateTime(2020, 7, 20)
                })
                {
                    NumberOfVisits = 5
                },
                new Dog(new Owner
                {
                    Firstname = "Tony", Lastname = "Smith", JoinedPractice = new DateTime(1985, 7, 13)
                })
                {
                    NumberOfVisits = 10
                },
                new Cat(new Owner
                {
                    Firstname = "Steve", Lastname = "Roberts", JoinedPractice = new DateTime(2002, 5, 6)
                })
                {
                    NumberOfVisits = 20, NumberOfLives = 9
                }
            };


            // Act
            uut.GenerateReport(pets);

            // Assert
            mockTextWriter.Verify(x => x.WriteLine(It.Is <string>(item => item == "Owners name,Date Joined Practice,Number Of Visits,Number of Lives")), Times.Once());
            mockTextWriter.Verify(x => x.WriteLine(It.Is <string>(item => item == "Jim Rogers, 20/07/2020 00:00:00, 5, ")), Times.Once());
            mockTextWriter.Verify(x => x.WriteLine(It.Is <string>(item => item == "Tony Smith, 13/07/1985 00:00:00, 10, ")), Times.Once());
            mockTextWriter.Verify(x => x.WriteLine(It.Is <string>(item => item == "Steve Roberts, 06/05/2002 00:00:00, 20, 9")), Times.Once());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Report achieved using a polymorphic visitor pattern");
            Console.WriteLine("-----------------------------------------");
            var petsToVisit = new Pets();

            petsToVisit.Attach(new Dog(new Owner {
                Firstname = "Jim", Lastname = "Rogers", JoinedPractice = DateTime.Now
            })
            {
                NumberOfVisits = 5
            });
            petsToVisit.Attach(new Dog(new Owner {
                Firstname = "Tony", Lastname = "Smith", JoinedPractice = new DateTime(1985, 7, 13)
            })
            {
                NumberOfVisits = 10
            });
            petsToVisit.Attach(new Cat(new Owner {
                Firstname = "Steve", Lastname = "Roberts", JoinedPractice = new DateTime(2002, 5, 6)
            })
            {
                NumberOfVisits = 20, NumberOfLives = 9
            });

            var petReportVisitor = new PetReportVisitor(Console.Out);

            petsToVisit.Accept(petReportVisitor);

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Report achieved using the DynamicObject");
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine(" >> to file: PetsReport.csv");
            var pets = new List <IReportable>()
            {
                new Dog(new Owner {
                    Firstname = "Jim", Lastname = "Rogers", JoinedPractice = DateTime.Now
                })
                {
                    NumberOfVisits = 5
                },
                new Dog(new Owner {
                    Firstname = "Tony", Lastname = "Smith", JoinedPractice = new DateTime(1985, 7, 13)
                })
                {
                    NumberOfVisits = 10
                },
                new Cat(new Owner {
                    Firstname = "Steve", Lastname = "Roberts", JoinedPractice = new DateTime(2002, 5, 6)
                })
                {
                    NumberOfVisits = 20, NumberOfLives = 9
                }
            };

            using (StreamWriter writer = File.CreateText("PetsReport.csv"))
            {
                var report = new PetReportGeneratorDynamic(writer);
                report.GenerateReport(pets);
                writer.Flush();
            }

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Report achieved using the DynamicObject");
            Console.WriteLine("-----------------------------------------");

            {
                var report = new PetReportGeneratorDynamic(Console.Out);
                report.GenerateReport(pets);
            }

            var iReportablePets = new List <IReportable>()
            {
                new Dog(new Owner {
                    Firstname = "Jim", Lastname = "Rogers", JoinedPractice = DateTime.Now
                })
                {
                    NumberOfVisits = 5
                },
                new Dog(new Owner {
                    Firstname = "Tony", Lastname = "Smith", JoinedPractice = new DateTime(1985, 7, 13)
                })
                {
                    NumberOfVisits = 10
                },
                new Cat(new Owner {
                    Firstname = "Steve", Lastname = "Roberts", JoinedPractice = new DateTime(2002, 5, 6)
                })
                {
                    NumberOfVisits = 20, NumberOfLives = 9
                }
            };

            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("Report achieved using a direct a direct Reflection implementation");
            Console.WriteLine("-----------------------------------------");

            {
                var report = new PetReportGeneratorReflective(Console.Out);
                report.GenerateReport(iReportablePets);
            }

            Console.ReadKey();
        }