public void PlateNumberGeneratorShouldGenerateRandomPlateNumbers() { var uniquePlateNumbers = new HashSet <string>(); var count = 9999; for (int i = 0; i < count; i++) { string plateNumber = CarSeeder.GeneratePlateNumber(); uniquePlateNumbers.Add(plateNumber); } Assert.IsTrue((float)(95 / 100) * count < uniquePlateNumbers.Count); }
public void EngineCodeGeneratorShouldGenerateRandomCodes() { var uniqueEngineCodes = new HashSet <string>(); int count = 9999; for (int i = 0; i < count; i++) { string code = CarSeeder.GenerateEngineCode(); uniqueEngineCodes.Add(code); } Assert.IsTrue((float)(90 / 100) * count < uniqueEngineCodes.Count); }
public void VinGneratorShouldGenerateCorrectWorldManufacturerIdentifiersForAllCarMakes() { var manufacturersList = AutoServiceManagementSystem.Helpers.ManufacturersList.Manufacturers; foreach (var manuf in manufacturersList) { string vin = CarSeeder.GenerateVinCode(manuf); Debug.WriteLine(vin); Assert.AreEqual(vin.Length, 17); } }
public void VinGeneratorShouldGenerateRandomVins() { var uniqueVins = new HashSet <string>(); int count = 99999; for (int i = 0; i < count; i++) { string vin = CarSeeder.GenerateVinCode("Mercedes"); Debug.WriteLine(vin); Assert.AreEqual(vin.Length, 17); uniqueVins.Add(vin); } Assert.AreEqual(count, uniqueVins.Count); }
public void NextCarShouldGenerateRandomCars() { var uniqueCars = new HashSet <Car>(); int count = 1000; for (int i = 0; i < count; i++) { var car = CarSeeder.NextCar(); //Debug.WriteLine(car.Manufacturer); //Debug.WriteLine(car.Model); //Debug.WriteLine(car.VIN); //Debug.WriteLine(car.Year); //Debug.WriteLine(car.PlateCode); //Debug.WriteLine(car.EngineCode); uniqueCars.Add(car); } Assert.AreEqual(count, uniqueCars.Count); }
public void GetYearShouldReturnACorrectYearAccordingToVIN() { Dictionary <char, int> charToYear = new Dictionary <char, int>() { { 'L', 1990 }, { 'M', 1991 }, { 'N', 1992 }, { 'P', 1993 }, { 'R', 1994 }, { 'S', 1995 }, { 'T', 1996 }, { 'V', 1997 }, { 'W', 1998 }, { 'X', 1999 }, { 'Y', 2000 }, { 'A', 2010 }, { '1', 2001 }, { '2', 2002 }, { '3', 2003 }, { '4', 2004 }, { '5', 2005 }, { '6', 2006 }, { '7', 2007 }, { '8', 2008 }, { '9', 2009 }, { 'B', 2011 }, { 'C', 2012 }, { 'D', 2013 }, { 'E', 2014 }, { 'F', 2015 }, { 'G', 2016 }, { 'H', 2017 }, { 'J', 2018 }, { 'K', 2018 } }; for (int i = 0; i < 9999; i++) { string vin = CarSeeder.GenerateVinCode( CarSeeder.GenerateManufacturer()); int year = CarSeeder.GetYear(vin); Assert.AreEqual(year, charToYear[vin[9]]); } }
protected override void Seed(MyDbContext context) { // This method will be called after migrating to the latest version. //ClearDatabase<MyDbContext>(); context = new MyDbContext(); #region Seeding ApplicationUsers bool exists = context.Users .Any(u => u.UserName == "*****@*****.**"); if (!exists) { var store = new UserStore <ApplicationUser>(context); var manager = new UserManager <ApplicationUser>(store); var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**", PhoneNumber = "088888888", UserDetails = new UserDetails { FirstName = "Ivan", LastName = "Petrov", CompanyName = "Auto Repair", City = "Ruse" } }; manager.Create(user, "password"); #endregion #region Seeding customers and their cars var currentUser = manager.FindByEmail("*****@*****.**"); var customersList = new List <Customer>(); var cars = new List <Car>(); for (int i = 0; i < 40; i++) { var customer = CustomerSeeder.NextCustomer(currentUser); for (int j = 0; j < 3; j++) { var car = CarSeeder.NextCar(currentUser, customer); cars.Add(car); customer.Cars.Add(car); } customersList.Add(customer); } customersList.ForEach(c => context.Customers.Add(c)); context.SaveChanges(); #endregion #region Suppliers seeding var suppliersToAdd = new List <Supplier> { new Supplier { Name = "No supplier", DiscountPercentage = 0.0m, User = currentUser, IsDeleted = true, IsDefault = true }, new Supplier { Name = "Euro 07", DiscountPercentage = 45.0m, City = "Rousse", WebsiteUrl = "http://euro07.bg", EmailAddress = "*****@*****.**", SkypeName = "euro07.ruse", User = currentUser }, new Supplier { Name = "Auto Plus", DiscountPercentage = 33.0m, City = "Rousse", WebsiteUrl = "http://autoplus.bg", EmailAddress = "*****@*****.**", SkypeName = "autoplus", User = currentUser }, new Supplier { Name = "Auto Commerce", DiscountPercentage = 25.0m, City = "Rousse", WebsiteUrl = "http://acommers.bg", User = currentUser }, new Supplier { Name = "Mega Parts", DiscountPercentage = 10.0m, City = "Sofia", WebsiteUrl = "http://megaparts.bg", EmailAddress = "*****@*****.**", User = currentUser }, new Supplier { Name = "Inter Cars", DiscountPercentage = 40.0m, City = "Rousse", WebsiteUrl = "http://intercars.bg", SkypeName = "intercars-bg", User = currentUser }, new Supplier { Name = "Auto Morgue", DiscountPercentage = 0.0m, City = "Rousse", WebsiteUrl = "", User = currentUser } }; suppliersToAdd.ForEach(s => context.Suppliers.Add(s)); context.SaveChanges(); #endregion #region Jobs seeding foreach (var car in cars) { var jobs = new List <Job>(); for (int i = 0; i < 3; i++) { jobs.Add(JobSeeder.NextJob(user, car, car.Customer)); } jobs.ForEach(j => context.Jobs.Add(j)); jobs.ForEach(j => j.SpareParts.ForEach( sp => context.SpareParts.Add(sp))); } SaveChanges(context); #endregion } ; }