public async void UpdateResultNotInDatabaseDoesNotUpdateDatabase() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("UpdateNonExistentDoesNothing").Options; using (API_DanceFellowsDbContext context = new API_DanceFellowsDbContext(options)) { //arrange Result result = new Result(); result.EventCompetitionID = 1; result.CompetitorID = 1; result.Placement = Placement.Finalled; Result resultTwo = new Result(); resultTwo.EventCompetitionID = 1; resultTwo.CompetitorID = 2; resultTwo.Placement = Placement.Position3; //act ResultManagementService resultServ = new ResultManagementService(context); await resultServ.CreateResult(result); Result queryResult = await resultServ.GetResult(1, 1); Placement oldPlacement = queryResult.Placement; resultTwo.Placement = Placement.Position3; await resultServ.UpdateResult(resultTwo); queryResult = await resultServ.GetResult(1, 1); //assert Assert.Equal(oldPlacement, queryResult.Placement); } }
public async void CanUpdateResultsInDatabase() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("UpdateExistingResult").Options; using (API_DanceFellowsDbContext context = new API_DanceFellowsDbContext(options)) { //arrange Result result = new Result(); result.EventCompetitionID = 1; result.CompetitorID = 1; result.Placement = Placement.Finalled; //act ResultManagementService resultServ = new ResultManagementService(context); await resultServ.CreateResult(result); result.Placement = Placement.Position3; await resultServ.UpdateResult(result); Result queryResult = await context.Results.FirstOrDefaultAsync(res => res.CompetitorID == result.CompetitorID && res.EventCompetitionID == result.EventCompetitionID && res.Placement == result.Placement); //assert Assert.Equal(result, queryResult); } }