public static void Generate() { var productFaker = new ProductFaker(); var serviceFaker = new ServiceFaker(); var products = productFaker.Generate(100); var services = serviceFaker.Generate(40); var customerFaker = new CustomerFaker(); var customers = customerFaker.Generate(50); //var items = products.OfType<Item>().Union(services).ToList(); //var orderFaker = new OrderFaker(customers, items); //var orders = orderFaker.Generate(10); using (var context = new MyContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Products.AddRange(products); context.Services.AddRange(services); context.SaveChanges(); context.Customers.AddRange(customers); context.SaveChanges(); //context.Orders.AddRange(orders); //context.SaveChanges(); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { // dotnet add package Microsoft.AspNetCore.SignalR.Client HubConnection connection = new HubConnectionBuilder() .WithUrl(url, options => { options.Headers.Add("Grupa", "GrupaA"); }) .Build(); _logger.LogInformation("Connecting..."); await connection.StartAsync(); _logger.LogInformation("Connected."); connection.On <Customer>("Created", customer => _logger.LogInformation($"Received {customer.FirstName}")); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); var customer = customerFaker.Generate(); _logger.LogInformation("Sending {customer} at: {time}", customer.FullName, DateTimeOffset.Now); await connection.SendAsync("CreatedCustomer", customer); _logger.LogInformation("Sent {customer} at: {time}", customer.FullName, DateTimeOffset.Now); await Task.Delay(1000, stoppingToken); } }
private static void GeneratingDataTest() { System.Console.WriteLine("---------------"); System.Console.WriteLine("Generatind Data Test"); string connectionString = "Server=127.0.0.1,1433;Database=ZFDb;User Id=sa;Password=P@ssw0rd"; var optionsBuilder = new DbContextOptionsBuilder<MyContext>(); var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(new ConsoleLoggerProvider((category, level) => level == LogLevel.Information, true)); optionsBuilder .UseLoggerFactory(loggerFactory) .UseSqlServer(connectionString); var customerFaker = new CustomerFaker(); var customers = customerFaker.Generate(1000); using(var context = new MyContext(optionsBuilder.Options)) { context.Customers.AddRange(customers); context.SaveChanges(); } }
protected override void Seed(Vavatech.WebApi.DbServices.WarehouseContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. ProductFaker productFaker = new ProductFaker(); ServiceFaker serviceFaker = new ServiceFaker(); CustomerFaker customerFaker = new CustomerFaker(new AddressFaker()); Product[] products = productFaker.Generate(10).ToArray(); context.Products.AddOrUpdate(p => p.Id, products); Service[] services = serviceFaker.Generate(20).ToArray(); context.Services.AddOrUpdate(p => p.Id, services); context.Customers.AddOrUpdate(p => p.Id, customerFaker.Generate(50).ToArray()); EmployeeFaker employeeFaker = new EmployeeFaker(); context.Users.AddOrUpdate(p => p.Id, employeeFaker.Generate(10).ToArray()); GuestFaker guestFaker = new GuestFaker(); context.Users.AddOrUpdate(p => p.Id, guestFaker.Generate(10).ToArray()); }
public static IEnumerable <Customer> GetCustomers(int count) { var customerFaker = new CustomerFaker(); var customers = customerFaker.Generate(count); return(customers); }
static async Task Main(string[] args) { const string url = "http://localhost:5000/signalr/customers"; Console.WriteLine("Hello Signal-R Sender!"); HubConnection connection = new HubConnectionBuilder() .WithUrl(url) .WithAutomaticReconnect() .Build(); Console.WriteLine("Connectig..."); await connection.StartAsync(); Console.WriteLine("Connected!"); CustomerFaker customerFaker = new CustomerFaker(); Customer customer = customerFaker.Generate(); Console.WriteLine($"Sending {customer.FirstName} {customer.LastName}"); await connection.SendAsync("SendCustomerAdded", customer); Console.WriteLine("Customer send"); Console.ReadKey(); }
private static async Task UpdateCustomerTest(ICustomerServiceAsync customerService) { CustomerFaker customerFaker = new CustomerFaker(); Customer customer = customerFaker.Generate(); await customerService.UpdateAsync(customer); }
private static async Task AddCustomerTest(ICustomerRepositoryAsync customerRepository) { // ICustomerRepositoryAsync customerRepository = new ApiCustomerRepository(new HttpClient()); CustomerFaker customerFaker = new CustomerFaker(new AddressFaker()); Customer customer = customerFaker.Generate(); await customerRepository.AddAsync(customer); }
// dotnet add package Microsoft.Extensions.Option public FakeCustomerRepository( CustomerFaker customerFaker, IOptionsSnapshot <FakeCustomerRepositoryOptions> options) { this.options = options.Value; customers = customerFaker.Generate(this.options.Quantity); }
public async Task <IActionResult> Generate([FromForm] int count) { CustomerFaker customerFaker = new CustomerFaker(); IEnumerable <CustomerWriteModel> generatedCustomers = customerFaker.Generate(count); await Task.WhenAll(generatedCustomers.Select(this.customerRepository.Create)); return(this.RedirectToAction("Index")); }
private static async Task AddCustomers() { var customerFaker = new CustomerFaker(); List <Customer> customers = customerFaker.Generate(10); foreach (var customer in customers) { await AddCustomer(customer); } }
public FakeCustomerRepository(CustomerFaker customerFaker) { this.customerFaker = customerFaker; customers = customerFaker.Generate(100); //customers = Enumerable.Empty<Customer>().ToList(); //customers.Add(new Customer { Id = 1, FirstName = "Marcin", LastName = "Sulecki", Gender = Gender.Man }); //customers.Add(new Customer { Id = 2, FirstName = "Bartek", LastName = "Sulecki", Gender = Gender.Man }); //customers.Add(new Customer { Id = 3, FirstName = "Kasia", LastName = "Sulecka", Gender = Gender.Woman }); }
// snippet: ctor public FakeCustomerRepository() { CustomerFaker customerFaker = new CustomerFaker(new AddressFaker()); customers = customerFaker.Generate(1000); //customers = new List<Customer>() //{ // new Customer (1, "John", "Smith"), // new Customer (2, "Ann", "Smith"), // new Customer (3, "Peter", "Novak"), //}; }
private static void AddRangeCustomersTest() { CustomerFaker customerFaker = new CustomerFaker(new AddressFaker()); var customers = customerFaker.Generate(100); ShopContextFactory shopContextFactory = new ShopContextFactory(); ShopContext context = shopContextFactory.Create(); ICustomerRepository customerRepository = new DbCustomerRepository(context); customerRepository.AddRange(customers); }
private static async Task AddCustomerTest() { CustomerFaker customerFaker = new CustomerFaker(); Customer customer = customerFaker.Generate(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:5001"); HttpResponseMessage response = await client.PostAsJsonAsync("api/customers", customer); string content = await response.RequestMessage.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { } } }
public FakeCustomersService(CustomerFaker customerFaker) { this.customerFaker = customerFaker; customers = customerFaker.Generate(100); }
// dotnet add package Microsoft.Extensions.Options public FakeCustomerRepository(IOptions <CustomerOptions> options, CustomerFaker customerFaker) { customers = customerFaker.Generate(options.Value.Count); }
public void Add(ICustomer entity) { entity.Id = customerFaker.Generate().Id; customers.Add(entity); }
public FakeCustomerRepository(CustomerFaker customerFaker) { this.customerFaker = customerFaker; this.customers = customerFaker.Generate(100).OfType <ICustomer>().ToList(); }
public CustomersService() { customers = customerFaker.Generate(100); }