public async Task Get_GivenIdWithMultipleViews_ReturnsCorrectView() { var firstView = new GameView() { Id = Guid.NewGuid(), Name = "Another Game", }; var expectedView = new GameView() { Id = Guid.NewGuid(), Name = "Test Game", }; var context = new GameViewContext(_contextOptions); await _connection.OpenAsync(); context.Database.EnsureCreated(); await context.AddAsync(firstView); await context.AddAsync(expectedView); await context.SaveChangesAsync(); Assert.That(await _service.Get(expectedView.Id), Is.EqualTo(expectedView) .Using <GameView, GameView>((a, e) => a.Id == e.Id && a.Name == e.Name)); }
private async Task HandleSaveGame(byte[] data) { var view = new GameView(); using (var memStream = new MemoryStream(data)) { var binReader = new BinaryReader(memStream); view.FromString(binReader.ReadString()); } if (view == new GameView()) { _logger.LogError($"Score was not formatted correctly."); return; } using (var context = new GameViewContext(_contextOptions)) using (var transaction = await context.Database.BeginTransactionAsync()) { await context.Games.AddAsync(view); await context.SaveChangesAsync(); transaction.Commit(); await context.DisposeAsync(); } _logger.LogDebug($"Game {view.Id} submitted successfully."); }
public async Task Get_GivenNonExistantGameId_ReturnsNull() { var testView = new GameView() { Id = Guid.NewGuid(), Name = "Test Game", }; var context = new GameViewContext(_contextOptions); await _connection.OpenAsync(); context.Database.EnsureCreated(); await context.AddAsync(testView); await context.SaveChangesAsync(); Assert.That(await _service.Get(Guid.NewGuid()), Is.Null); }