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 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_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() { // 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); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request /// pipeline. /// </summary> /// /// <param name="app"> The application. </param> /// <param name="env"> The environment. </param> /// <param name="serviceProvider"> The service provider. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public static void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { #if DEBUG // Using in-memory database for this simple application, which is good for TDD. When running the API in debug mode, we will // load the following default data. var context = serviceProvider.GetService <MotorcycleContext>(); MotorcycleContext.LoadContextWithTestData(context); #endif }
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_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_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_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_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_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_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_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); } }
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_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); } }