Ejemplo n.º 1
0
        public async void HistoryLevelHistoryGameExistWordsExists()
        {
            const int userId = 1;

            // initialise
            await using InWordsDataContext context = InWordsDataContextFactory.Create();
            CreateContextWithExistedGame(context, userId);
            await context.SaveChangesAsync().ConfigureAwait(false);

            var testQuery = new CustomLevelMetricQuery()
            {
                UserId  = userId,
                Metrics = new List <ClassicCardLevelMetric>()
                {
                    new ClassicCardLevelMetric()
                    {
                        GameLevelId          = 0,
                        WordPairIdOpenCounts = new Dictionary <int, int>()
                        {
                            { 1, 4 },
                            { 2, 5 },
                            { 3, 1 }
                        }
                    }
                }.ToImmutableArray()
            };


            // act
            var handler = new CreateHistoryLevelsRequest(context);
            CustomLevelMetricQuery actualResult = await handler.Handle(testQuery).ConfigureAwait(false);

            // assert
            var expectedLevels            = 1;
            List <GameLevel> actualLevels = context.GameLevels.Where(g => g.GameId.Equals(1)).ToList();

            Assert.Equal(expectedLevels, actualLevels.Count);
            var expectedLevelWords = 3;
            var actualLevelWords   = context.GameLevelWords
                                     .Where(d => actualLevels.Contains(d.GameLevel));

            Assert.Equal(expectedLevelWords, actualLevelWords.Count());

            Assert.Equal(4, actualResult.Metrics[0].WordPairIdOpenCounts[2]);

            context.Dispose();
        }
Ejemplo n.º 2
0
        public async void HistoryNonExistWordsExist()
        {
            // initialise
            await using InWordsDataContext context = InWordsDataContextFactory.Create();
            context.Games.Add(new Game {
                GameId = 1
            });
            context.GameTags.Add(new GameTag()
            {
                UserId = 1, Tags = GameTags.CustomLevelsHistory, GameId = 1
            });
            var testQuery = new CustomLevelMetricQuery()
            {
                UserId  = 1,
                Metrics = new List <ClassicCardLevelMetric>()
                {
                    new ClassicCardLevelMetric()
                    {
                        GameLevelId          = 0,
                        WordPairIdOpenCounts = new Dictionary <int, int>()
                        {
                            { 1, 2 },
                            { 2, 3 },
                            { 3, 4 }
                        }
                    }
                }.ToImmutableArray()
            };
            await context.SaveChangesAsync().ConfigureAwait(false);


            // act
            var handler = new CreateHistoryLevelsRequest(context);

            // assert
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => handler.Handle(testQuery)).ConfigureAwait(false);

            context.Dispose();
        }
Ejemplo n.º 3
0
        public async void GameThereAreNoWordsInTheDatabase()
        {
            int userId = 2;

            // initialise
            await using InWordsDataContext context = InWordsDataContextFactory.Create();
            CreateContextWithExistedGame(context, userId - 1);

            var testQuery = new CustomLevelMetricQuery()
            {
                UserId  = userId,
                Metrics = new List <ClassicCardLevelMetric>()
                {
                    new ClassicCardLevelMetric()
                    {
                        GameLevelId          = 0,
                        WordPairIdOpenCounts = new Dictionary <int, int>()
                        {
                            { 1, 2 },
                            { 2, 3 },
                            { 3, 4 }
                        }
                    }
                }.ToImmutableArray()
            };
            await context.SaveChangesAsync().ConfigureAwait(false);


            // act
            var handler = new CreateHistoryLevelsRequest(context);
            var result  = await handler.Handle(testQuery).ConfigureAwait(false);

            // assert
            Assert.Equal(2, context.Games.Count());
            Assert.Equal(2, context.GameTags.Count());
            context.Dispose();
        }
Ejemplo n.º 4
0
        private Task <CustomLevelMetricQuery> HandleNewHistoryGamesAsync(CardLevelMetricQuery request, CancellationToken cancellationToken)
        {
            var customLevel = new CustomLevelMetricQuery(request);

            return(new CreateHistoryLevelsRequest(Context).Handle(customLevel, cancellationToken));
        }