static async Task Main(string[] args)
    {
        AutoFaker.Configure(builder =>
        {
            builder.WithConventions();
        });

        string runId      = DateTime.UtcNow.ToString("yyyy-MM-dd-HHmmss");
        string outputDir  = Path.Combine(AppContext.BaseDirectory, "../../../examples", runId);
        string outputFile = Path.Combine(outputDir, runId + ".txt");

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

        using (var output = File.OpenWrite(outputFile))
            using (var writer = new StreamWriter(output))
            {
                for (int i = 0; i < 1000; i++)
                {
                    var stream = new MemoryStream();

                    try
                    {
                        var customers = new CustomerCollectionResponse
                        {
                            Customers = Enumerable.Range(0, 50).Select(i => CustomerDataGenerator.CreateCustomer()).ToList()
                        };

                        await JsonSerializer.SerializeAsync(stream, customers);

                        stream.Position = 0;

                        var deserialized = await JsonSerializer.DeserializeAsync <CustomerCollectionResponse>(stream, s_serializerOptions);

                        writer.WriteLine($"{i:0000}: Reading Json from stream - deserialized {deserialized.Customers.Count} customer records.");
                        Console.WriteLine($"{i:0000}: Reading Json from stream - deserialized {deserialized.Customers.Count} customer records.");
                    }
                    catch (Exception e)
                    {
                        writer.WriteLine($"{i:0000}: Error:{Environment.NewLine}{e}");
                        Console.WriteLine($"{i:0000}: Error:{Environment.NewLine}{e}");

                        using (var file = File.OpenWrite(Path.Combine(outputDir, $"{runId}-{i:0000}.json")))
                        {
                            await file.WriteAsync(stream.ToArray());
                        }
                    }
                }
            }
    }
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <CustomerDbContext>();

                CustomerDataGenerator.Initialize(services);
            }

            host.Run();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // var customers = CutomerDataHelper.GetCustomer();
            //var employees = EmployeeDataGenerator.GetEmployee();
            CustomerService             customerService1 = new CustomerService(); // This has all the methods.
            ICustomerService <Customer> customerService2 = new CustomerService(); // This has methods only from ICutomerService
            IBaseRepository <Customer>  customerService3 = new CustomerService(); //This has mehtodds only from IBaseRpeository
            var employeeService = new EmployeeService();
            //customerService.


            var custResult = from c in CustomerDataGenerator.GetCustomer()

                             select c;

            foreach (var cust in custResult)
            {
                Console.WriteLine("{0}, {1}", cust.Id, cust.FirstName);
            }
            Console.ReadKey();


            Console.WriteLine("Hello World!");
        }