public async void GetCompetitor_CanGetOnlyCompetitor() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("CanGetOnlyCompetitor").Options; using (API_DanceFellowsDbContext _context = new API_DanceFellowsDbContext(options)) { //arrange Competitor competitor = new Competitor(); competitor.WSDC_ID = 1000; competitor.FirstName = "Joe"; competitor.LastName = "Schmoe"; //act CompetitorManagementService resultServ = new CompetitorManagementService(_context); await _context.Competitors.AddAsync(competitor); await _context.SaveChangesAsync(); Competitor query = await resultServ.GetCompetitor(competitor.WSDC_ID); //assert Assert.Equal(competitor, query); } }
public async void DuplicateResultsAreNotAddedToTable() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("CreateDuplicateResult").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 = 1; resultTwo.Placement = Placement.Position3; //act ResultManagementService resultServ = new ResultManagementService(context); await resultServ.CreateResult(result); await resultServ.CreateResult(resultTwo); List <Result> queryResults = await context.Results.ToListAsync(); //assert Assert.True(1 == queryResults.Count); } }
public async void CanCreateResultIntoNonEmptyDatabase() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("CreateResultintoNonEmpty").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 = 3; resultTwo.Placement = Placement.Position3; //act ResultManagementService resultServ = new ResultManagementService(context); await resultServ.CreateResult(result); await resultServ.CreateResult(resultTwo); Result queryResult = await context.Results.FirstOrDefaultAsync(res => res.CompetitorID == resultTwo.CompetitorID && res.EventCompetitionID == resultTwo.EventCompetitionID && res.Placement == resultTwo.Placement); //assert Assert.Equal(resultTwo, queryResult); } }
public async void DeleteResultDeletesOnlyThatResult() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("DeletingADoesNotDeleteB").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); await resultServ.CreateResult(resultTwo); await resultServ.DeleteResult(result.EventCompetitionID, result.CompetitorID); Result queryResult = await resultServ.GetResult(1, 2); //assert Assert.Equal(resultTwo, queryResult); } }
public async void DeleteDeletesARecordFromTheDatabase() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("DeleteDeletes").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); await resultServ.DeleteResult(result.EventCompetitionID, result.CompetitorID); Result queryResult = await resultServ.GetResult(1, 1); //assert Assert.Null(queryResult); } }
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 GetCompetitor_NoMatchReturnsNull() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("NoMatchReturnsNull").Options; using (API_DanceFellowsDbContext _context = new API_DanceFellowsDbContext(options)) { //arrange Competitor joe = new Competitor(); joe.WSDC_ID = 1000; joe.FirstName = "Joe"; joe.LastName = "Schmoe"; Competitor jane = new Competitor(); jane.WSDC_ID = 2000; jane.FirstName = "Jane"; jane.LastName = "Schmane"; Competitor josh = new Competitor(); josh.WSDC_ID = 3000; josh.FirstName = "Josh"; josh.LastName = "Schmosh"; //act CompetitorManagementService resultServ = new CompetitorManagementService(_context); await _context.Competitors.AddAsync(joe); await _context.Competitors.AddAsync(jane); await _context.Competitors.AddAsync(josh); await _context.SaveChangesAsync(); Competitor query = await resultServ.GetCompetitor(9999); //assert Assert.Null(query); } }
public async void UpdatingEmptyDatabaseDoesNotCreateNewEntry() { //Create the options to feed into the context for dependency injection... DbContextOptions <API_DanceFellowsDbContext> options = new DbContextOptionsBuilder <API_DanceFellowsDbContext>().UseInMemoryDatabase("UpdateDoesNotCreate").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); 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.Null(queryResult); } }
/// <summary> /// Constructor for this service using dependency injection - sets our readonly context to the provided context when instantiating the service /// </summary> /// <param name="context">Database context to be used for this service</param> public CompetitorManagementService(API_DanceFellowsDbContext context) { ReadOnlyContext = context; _context = context; }
public ResultManagementService(API_DanceFellowsDbContext context) { ReadOnlyContext = context; }