static void Main(string[] args) { // Reading CLI args example. if (args.Length > 0) { // Run via: `dotnet run -- <arg>`. Console.WriteLine($"Hello {args[0]}!"); } else { Console.WriteLine("Hello!"); } // Multiple files in same directory example. Console.WriteLine("Fibonacci Numbers 1-15:"); var generator = new FibonacciGenerator(); foreach (var digit in generator.Generate(15)) { Console.WriteLine(digit); } // Multiple files in sub-folders example. List <IPet> pets = new List <IPet> { new Dog(), new Cat(), new Bird() }; foreach (var pet in pets) { Console.WriteLine(pet.TalkToOwner()); } SumPageExample sumPageExample = new SumPageExample(); // Synchronous call to get HTTP pages. StopWatchDelegate(sumPageExample.SumPageSizes); // Asynchronous call to get HTTP pages. StopWatchDelegateAsync(sumPageExample.SumPageSizesAsync).GetAwaiter().GetResult(); // Asynchronous & Parallel calls to get HTTP pages. StopWatchDelegateAsync(sumPageExample.SumPageSizesInParallelAndAsync).GetAwaiter().GetResult(); // Multiple asynchronous calls created and then awaited at a later // date, to provide a parallel call. StopWatchDelegateAsync(sumPageExample.CreateMultipleTasksAsync).GetAwaiter().GetResult(); }
public void GetURLContentsTest() { // FIXME: Site is not under my control, so fragile to test against it. string expString = "Learn to Develop with Microsoft Developer Network | MSDN"; string url = "https://msdn.microsoft.com"; byte[] content = new SumPageExample().GetURLContents(url); // INVESTIGATE: Why does `byte[].ToString()` return `"System.Byte[]` // instead of the string within the byte array?? Feels like a Gotcha // that describes it's own object, rather than the contents. string contentString = Encoding.UTF8.GetString(content); // Commented out due to size of printing page source. // output.WriteLine($"XXX - content: {contentString}"); Assert.Contains(expString, contentString); // FIXME: Again, fragile to test like this on an external site. output.WriteLine($"XXX - content Length: {content.Length}"); Assert.InRange(content.Length, 30000, 50000); }