public void ItCreatesANewRecordIfOneDoesNotExist()
        {
            autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<BoardGameGeekGameDefinition>(boardGameGeekGameDefinitionId))
                .Throw(new EntityDoesNotExistException(typeof(BoardGameGeekGameDefinition), boardGameGeekGameDefinitionId));
            var expectedGameDetails = new GameDetails
            {
                Thumbnail = "some thumbnail",
                Name = "some name",
                Categories = new List<GameCategory>()
            };
            autoMocker.Get<IBoardGameGeekApiClient>().Expect(mock => mock.GetGameDetails(boardGameGeekGameDefinitionId))
                .Return(expectedGameDetails);

            autoMocker.ClassUnderTest.CreateBoardGameGeekGameDefinition(boardGameGeekGameDefinitionId, currentUser);

            var args = autoMocker.Get<IDataContext>().GetArgumentsForCallsMadeOn(mock => mock.Save(
                Arg<BoardGameGeekGameDefinition>.Is.Anything,
                Arg<ApplicationUser>.Is.Anything));

            Assert.That(args.Count, Is.GreaterThan(0));
            var actualBoardGameGeekGameDefinition = args[0][0] as BoardGameGeekGameDefinition;
            Assert.That(actualBoardGameGeekGameDefinition, Is.Not.Null);
            Assert.That(actualBoardGameGeekGameDefinition.Id, Is.EqualTo(boardGameGeekGameDefinitionId));
            Assert.That(actualBoardGameGeekGameDefinition.Thumbnail, Is.EqualTo(expectedGameDetails.Thumbnail));
            Assert.That(actualBoardGameGeekGameDefinition.Name, Is.EqualTo(expectedGameDetails.Name));
        }
        private void AssertBoardGameGeekGameDefinitionSaved(GameDetails expectedGameDetails)
        {
            var argumentsForCallsMadeOn = _autoMocker.Get<IDataContext>().GetArgumentsForCallsMadeOn(
                                                                                                     mock => mock.Save(Arg<BoardGameGeekGameDefinition>.Is.Anything,
                                                                                                                       Arg<ApplicationUser>.Is.Anything));
            Assert.That(argumentsForCallsMadeOn, Is.Not.Null);
            BoardGameGeekGameDefinition actualBoardGameGeekGameDefinition = null;
            foreach (var call in argumentsForCallsMadeOn)
            {
                actualBoardGameGeekGameDefinition = call[0] as BoardGameGeekGameDefinition;
                Assert.That(actualBoardGameGeekGameDefinition, Is.Not.Null);

                if (actualBoardGameGeekGameDefinition.Id == expectedGameDetails.GameId)
                {
                    break;
                }
            }

            Assert.That(actualBoardGameGeekGameDefinition, Is.Not.Null);
            Assert.That(actualBoardGameGeekGameDefinition.AverageWeight, Is.EqualTo(expectedGameDetails.AverageWeight));
            Assert.That(actualBoardGameGeekGameDefinition.Description, Is.EqualTo(expectedGameDetails.Description));
            Assert.That(actualBoardGameGeekGameDefinition.MaxPlayTime, Is.EqualTo(expectedGameDetails.MaxPlayTime));
            Assert.That(actualBoardGameGeekGameDefinition.MinPlayTime, Is.EqualTo(expectedGameDetails.MinPlayTime));
            Assert.That(actualBoardGameGeekGameDefinition.MaxPlayers, Is.EqualTo(expectedGameDetails.MaxPlayers));
            Assert.That(actualBoardGameGeekGameDefinition.MinPlayers, Is.EqualTo(expectedGameDetails.MinPlayers));
            Assert.That(actualBoardGameGeekGameDefinition.Name, Is.EqualTo(expectedGameDetails.Name));
            Assert.That(actualBoardGameGeekGameDefinition.Thumbnail, Is.EqualTo(expectedGameDetails.Thumbnail));
        }
        public void ItRefreshesEveryExistingBoardGameGeekGameDefinition()
        {
            //--arrange
            int expectedBoardGameGeekGameDefinitionId1 = 1;
            int expectedBoardGameGeekGameDefinitionId2 = 2;

            var allBoardGameGeekGameDefinitionsQueryable = new List<BoardGameGeekGameDefinition>
            {
                new BoardGameGeekGameDefinition
                {
                    Id = expectedBoardGameGeekGameDefinitionId1
                },
                new BoardGameGeekGameDefinition
                {
                    Id = expectedBoardGameGeekGameDefinitionId2
                }
            }.AsQueryable();
            _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<BoardGameGeekGameDefinition>())
                .Return(allBoardGameGeekGameDefinitionsQueryable);
            var expectedBggGameDetails1 = new GameDetails
            {
                GameId = expectedBoardGameGeekGameDefinitionId1,
                AverageWeight = 1,
                Description = "some description 1",
                Thumbnail = "some thumbnail",
                MinPlayers = 3,
                MaxPlayers = 4,
                MinPlayTime = 5,
                MaxPlayTime = 6
            };
            _autoMocker.Get<IBoardGameGeekApiClient>().Expect(mock => mock.GetGameDetails(expectedBoardGameGeekGameDefinitionId1))
                       .Return(expectedBggGameDetails1);
            var expectedBggGameDetails2 = new GameDetails
            {
                GameId = expectedBoardGameGeekGameDefinitionId2,
                AverageWeight = 10,
                Description = "some description 2",
                Thumbnail = "some thumbnail",
                MinPlayers = 30,
                MaxPlayers = 40,
                MinPlayTime = 50,
                MaxPlayTime = 60
            };
            _autoMocker.Get<IBoardGameGeekApiClient>().Expect(mock => mock.GetGameDetails(expectedBoardGameGeekGameDefinitionId2))
                       .Return(expectedBggGameDetails2);

            //--act
            _autoMocker.ClassUnderTest.RefreshAllBoardGameGeekData();

            //--assert
            AssertBoardGameGeekGameDefinitionSaved(expectedBggGameDetails1);
            AssertBoardGameGeekGameDefinitionSaved(expectedBggGameDetails2);
        }
 private BoardGameGeekGameDefinition GetExistingBGGGameById(GameDetails gameToAdd)
 {
     var existingGame = _dataContext.GetQueryable<BoardGameGeekGameDefinition>()
         .FirstOrDefault(bgg => bgg.Id == gameToAdd.GameId);
     return existingGame;
 }
        private BoardGameGeekGameDefinition CreateBGGGame(GameDetails gameToAdd)
        {
            var newRecord = new BoardGameGeekGameDefinition
            {
                Id = gameToAdd.GameId,
                Name = gameToAdd.Name,
                Thumbnail = gameToAdd.Thumbnail,
                Image = gameToAdd.Image,
                MaxPlayers = gameToAdd.MaxPlayers,
                MinPlayers = gameToAdd.MinPlayers,
                MaxPlayTime = gameToAdd.MaxPlayTime,
                MinPlayTime = gameToAdd.MinPlayTime,
                AverageWeight = gameToAdd.AverageWeight,
                Description = gameToAdd.Description
            };

            _dataContext.Save(newRecord, new ApplicationUser());
            return newRecord;
        }