public static async void TestRepository_Insert() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { (Motorcycle motorcycle, _) = Motorcycle.NewTestMotorcycle(); var repo = new MotorcycleRepository(context); var found = false; // ACT (Motorcycle entity, _, _) = await repo.InsertAsync(motorcycle, (moto) => { return(repo.ExistsByIdAsync(moto.Id)); }); found = context.Entities.Any(x => x.Id.Equals(entity.Id)); // ASSERT Assert.NotNull(entity); Assert.True(found); } }
public static async void TestRepository_Update_VinExists() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context, 2); var motorcycle1 = context.Entities.FirstOrDefault(); var motorcycle2 = context.Entities.LastOrDefault(); var repo = new MotorcycleRepository(context); if (motorcycle2 != null) { motorcycle2.Vin = motorcycle1?.Vin; } // ACT (_, OperationStatus status, _) = await repo.UpdateAsync(motorcycle2?.Id ?? Constants.InvalidEntityId, motorcycle2, async (moto) => { var count = (await repo.ListAsync()).list.Count(x => x.Vin.Equals(moto.Vin, StringComparison.CurrentCultureIgnoreCase)); return(count == 1); }); // ASSERT Assert.True(status == OperationStatus.InternalError); } }
public static async void TestRepository_Update_NotExist() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); if (motorcycle != null) { motorcycle.Make = kUpdatedMake; } // ACT (_, OperationStatus status, _) = await repo.UpdateAsync(kDoesNotExistId, motorcycle, async (moto) => { var count = (await repo.ListAsync()).list.Count(x => x.Vin.Equals(moto.Vin, StringComparison.CurrentCultureIgnoreCase)); return(count == 1); }); // ASSERT Assert.True(status == OperationStatus.NotFound); } }
public static void Main(string[] args) { //TODO Add IEngine //Motorcycle varche = new PowerMotorcycle("12214235", 75); //Console.WriteLine(varche.HorsePower); IMotorcycleFactory motorcycleFactory = new MotorcycleFactory(); IRaceFactory raceFactory = new RaceFactory(); IRiderFactory riderFactory = new RiderFactory(); MotorcycleRepository motorcycleRepository = new MotorcycleRepository(); RaceRepository raceRepository = new RaceRepository(); RiderRepository riderRepository = new RiderRepository(); IChampionshipController controller = new ChampionshipController( motorcycleFactory, raceFactory, riderFactory, motorcycleRepository, raceRepository, riderRepository); IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); IEngine engine = new Engine(reader, writer, controller); engine.Run(); }
public ChampionshipController() { this.motorcycleRepository = new MotorcycleRepository(); this.riderRepository = new RiderRepository(); this.raceRepository = new RaceRepository(); this.riders = new List <IRider>(); }
public static void Main(string[] args) { IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); IRepository <IMotorcycle> motorcycleRepository = new MotorcycleRepository(); IRepository <IRace> raceRepository = new RaceRepository(); IRepository <IRider> riderRepository = new RiderRepository(); MotorcycleFactory motorcycleFactory = new MotorcycleFactory(); // Judge system does not require dependency inversion principle to be observed! // Also Factories and CommandInterpreter are not required! IChampionshipController championshipController = new ChampionshipController( motorcycleRepository, raceRepository, riderRepository, motorcycleFactory); ICommandInterpreter commandInterpreter = new CommandInterpreter(championshipController); IEngine engine = new Engine(commandInterpreter, reader, writer); engine.Run(); }
public static async void TestRepository_Update() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); if (motorcycle != null) { motorcycle.Make = kUpdatedMake; } // ACT (Motorcycle updated, _, _) = await repo.UpdateAsync(motorcycle?.Id ?? Constants.InvalidEntityId, motorcycle, async (moto) => { var count = (await repo.ListAsync()).list.Count(x => x.Vin.Equals(moto.Vin, StringComparison.CurrentCultureIgnoreCase)); return(count == 1); }); // ASSERT Assert.Equal(updated.Make, kUpdatedMake); } }
public static void Main() { var raceRepo = new RaceRepository(); var riderRepo = new RiderRepository(); var motorcycleRepo = new MotorcycleRepository(); var raceFactory = new RaceFactory(); var riderFactory = new RiderFactory(); var motorcycleFactory = new MotorcycleFactory(); var championshipController = new ChampionshipController( raceRepo, riderRepo, motorcycleRepo, raceFactory, riderFactory, motorcycleFactory); var consoleReader = new ConsoleReader(); var consoleWriter = new ConsoleWriter(); var engine = new Engine( championshipController, consoleReader, consoleWriter); engine.Run(); }
public UnitOfWork(AutoniverseContext context) { this.context = context; Cars = new CarRepository(context); CarCategories = new CarCategoryRepository(context); Motorcycles = new MotorcycleRepository(context); MotorcycleCategories = new MotorcycleCategoryRepository(context); }
public ChampionshipController() { this.raceFactory = new RaceFactory(); this.riderFactory = new RiderFactory(); this.motorcycleFactory = new MotorcycleFactory(); this.motorcycleRepository = new MotorcycleRepository(); this.raceRepository = new RaceRepository(); this.riderRepository = new RiderRepository(); }
public ChampionshipController() { motorcycleRepo = new MotorcycleRepository(); raceRepo = new RaceRepository(); riderRepo = new RiderRepository(); motorcycleFactory = new MotorcycleFactory(); raceFactory = new RaceFactory(); riderFactory = new RiderFactory(); }
public ChampionshipController( IMotorcycleFactory motorcycleFactory, IRaceFactory raceFactory, IRiderFactory riderFactory, MotorcycleRepository motorcycleRepository, RaceRepository raceRepository, RiderRepository riderRepository) { this.motorcycleFactory = motorcycleFactory; this.raceFactory = raceFactory; this.riderFactory = riderFactory; this.motorcycleRepository = motorcycleRepository; this.raceRepository = raceRepository; this.riderRepository = riderRepository; }
public static async void TestRepository_Save() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { var repo = new MotorcycleRepository(context); // ACT (OperationStatus status, _) = await repo.SaveAsync(); // ASSERT Assert.True(status == OperationStatus.Ok); } }
public static async void TestRepository_FetchByVin_No() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { var repo = new MotorcycleRepository(context); // ACT (Motorcycle motorcycle, _, _) = await repo.FetchByVinAsync(kDoesNotExistVin); // ASSERT Assert.Null(motorcycle); } }
public static async void TestRepository_ExistsByVin_No() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { var repo = new MotorcycleRepository(context); // ACT (bool exists, _, _) = await repo.ExistsByVinAsync(kDoesNotExistVin); // ASSERT Assert.False(exists); } }
public static async void TestRepository_ListEmpty() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { var repo = new MotorcycleRepository(context); // ACT (IReadOnlyCollection <Motorcycle> list, _, _) = await repo.ListAsync(); // ASSERT Assert.Empty(list); } }
public static async void TestRepository_ListOfOne() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var repo = new MotorcycleRepository(context); // ACT (IReadOnlyCollection <Motorcycle> list, _, _) = await repo.ListAsync(); // ASSERT Assert.True(list.Count == 1); } }
public static async void TestRepository_ExistsByVin() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); // ACT (bool exists, _, _) = await repo.ExistsByVinAsync(motorcycle?.Vin); // ASSERT Assert.True(exists); } }
public static async void TestRepository_FetchByVin() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); // ACT (Motorcycle found, _, _) = await repo.FetchByVinAsync(motorcycle?.Vin); // ASSERT Assert.NotNull(found); } }
public static async void TestRepository_Delete_NotExist() { var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { // To ensure that the In-Memory database does not share state between tests. context.Database.EnsureDeleted(); var repo = new MotorcycleRepository(context); // ACT // Look for an Id that doesn't exist... (OperationStatus status, _) = await repo.DeleteAsync(kDoesNotExistId); // ASSERT Assert.True(status == OperationStatus.NotFound); } }
public static async void TestRepository_ExistsById_No() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { // To ensure that the In-Memory database does not share state between tests. // FIXME: Either add to each test method, or relocate to CreateTesting... or elsewhere. context.Database.EnsureDeleted(); var repo = new MotorcycleRepository(context); // ACT (bool exists, _, _) = await repo.ExistsByIdAsync(kDoesNotExistId); // ASSERT Assert.False(exists); } }
public static async void TestRepository_Delete() { var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { // To ensure that the In-Memory database does not share state between tests. context.Database.EnsureDeleted(); MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); // ACT (OperationStatus status, _) = await repo.DeleteAsync(motorcycle?.Id ?? Constants.InvalidEntityId); // ASSERT Assert.True(status == OperationStatus.Ok); } }
static void Main(string[] args) { Logger.InitLogger(); MotorcycleRepository motorcycleRepository = new MotorcycleRepository(); Motorcycle motorcycle = new Motorcycle("Honda", "CB", 2014, 23); Logger.Log.Info("CRUD operations started!"); motorcycleRepository.CreateMotorcycle(motorcycle); Motorcycle moto = motorcycleRepository.GetMotorcycleByID(1); Logger.Log.Info("Start of console output"); Console.WriteLine($"The name of the motorcycle: {moto.Name}\n" + $"The model of motorcycle: {moto.Model}\n" + $"The year of issure: {moto.Year}\n" + $"The odometer of the motorcycle: {moto.Odometer}"); Console.Read(); Logger.Log.Info("Program completed successfully"); }
public static async void TestRepository_Insert_VinExists() { // ARRANGE var options = MotorcycleContext.CreateTestingContextOptions(); using (var context = new MotorcycleContext(options)) { MotorcycleContext.LoadContextWithTestData(context); var motorcycle = context.Entities.FirstOrDefault(); var repo = new MotorcycleRepository(context); // ACT (_, OperationStatus status, IError error) = await repo.InsertAsync(motorcycle, (moto) => { // If exists is true, then the VIN is not unique. return(repo.ExistsByVinAsync(moto.Vin)); }); // ASSERT Assert.True(status == OperationStatus.Found); Assert.NotNull(error); } }
public ChampionshipController() { races = new RaceRepository(); motorcycles = new MotorcycleRepository(); riders = new RiderRepository(); }
public HomeController() { repoBike = new MotorcycleRepository(); repoCustomer = new CustomerRepository(); repoPurchase = new PurchaseRepository(); }