public string RunWrongApproach() { var explanation = new StringBuilder(); explanation.AppendLine($"--- WRONG APPROACH ---"); var rectangle = new WrongApproach.Rectangle { Height = 10, Width = 3 }; explanation.AppendLine($"We have created a rectangle of 10x3: Height[{rectangle.Height}] Width[{rectangle.Width}] Area[{rectangle.GetArea()}]"); var square = new WrongApproach.Square { Height = 10, Width = 10 }; explanation.AppendLine($"And a square of 10x10: Height[{ square.Height}] Width[{ square.Width}] Area[{ square.GetArea()}]"); var approach = new WrongApproach(); var rectangleTest = approach.ValidateAreaCalculation(new WrongApproach.Rectangle()); var squareTest = approach.ValidateAreaCalculation(new WrongApproach.Square()); explanation.AppendLine($"Using both through their base class, we test that GIVEN sides of 6x8 WHEN we get the area THEN we get 48"); explanation.AppendLine($"\tRectangle object test: {( rectangleTest ? "passed" : "NOT passed")}"); explanation.AppendLine($"\tSquare object test: {(squareTest ? "passed" : "NOT passed")}"); explanation.AppendLine(); explanation.AppendLine($"In real life a square is also a rectangle, but that scenario not be always coded that way unless that \"square\" and \"rectangle\" are treated as properties of an object called, for instance, \"shape\""); return(explanation.ToString()); }
public string RunWrongApproach() { var explanation = new StringBuilder(); explanation.AppendLine("--- WRONG APPROACH ---"); explanation.AppendLine("Getting all items using a common interface will introduce several properties not used in objects"); var wrongApproach = new WrongApproach(); List <WrongApproach.SellableItem> items = wrongApproach.GetAllProducts(); var vegetableProducts = items.Where(x => x.MeasurementUnit == "Kg").ToList(); var ageragePriceOfVegetables = vegetableProducts.Average((v) => v.Price); explanation.AppendLine("In this approach there are:"); explanation.AppendLine($"\t{vegetableProducts.Count} vegetables products with an average price of {ageragePriceOfVegetables}€/Kg"); var tvProducts = items.Where(x => x.Name.ToLower().Contains("tv")).ToList(); var differentResolutions = tvProducts.Select(tv => tv.Resolution).Distinct().Count(); explanation.AppendLine($"\t{tvProducts.Count} TVs of {differentResolutions} different resolutions"); var schollItems = items.Where(x => "Clothing4Youth,WealthyLife,LearningSolutions".ToLower().Contains(x.ProviderName.ToLower())).ToList(); var shoesItems = schollItems.Where(i => i.MeasurementUnit == "pair").Count(); explanation.AppendLine($"\t{schollItems.Count} school items, and {shoesItems} of them are shoes"); string vegetableProperties = vegetableProducts.First().GetType().GetProperties().Select(p => p.Name).Aggregate((name, nextName) => $"{name}, {nextName}"); explanation.AppendLine("Vegetable visible properties: " + vegetableProperties); return(explanation.ToString()); }