示例#1
0
        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));
        }
示例#2
0
        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.");
        }
示例#3
0
        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);
        }
        public async Task <GameView> Get(Guid id, int take = 1, int skip = 1)
        {
            _logger.LogDebug($"Attempting to get game {id}.");
            if (id == Guid.Empty)
            {
                throw new ArgumentException("Game ID must be provided.");
            }

            if (take != 1 || skip != 1)
            {
                throw new ArgumentException("Take and Skip must be equal to 1.");
            }

            _logger.LogDebug("Connection to GameView database");
            using (var context = new GameViewContext(_contextOptions))
            {
                _logger.LogDebug("Attempting to find game.");
                return(await context.FindAsync <GameView>(id));
            }
        }