Exemplo 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();
        }
Exemplo 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();
        }
        public async void HandleWords()
        {
            var userId = 1;

            await using InWordsDataContext context = InWordsDataContextFactory.Create();
            var pair = new WordPair()
            {
                WordForeign = new Word(), WordNative = new Word()
            };

            context.UserWordPairs.Add(new UserWordPair()
            {
                UserId = userId, TimeGap = DateTime.UtcNow.AddDays(-5), WordPair = pair
            });
            context.UserWordPairs.Add(new UserWordPair()
            {
                UserId = userId, TimeGap = DateTime.UtcNow.AddDays(-1), WordPair = pair
            });
            context.UserWordPairs.Add(new UserWordPair()
            {
                UserId = userId, TimeGap = DateTime.UtcNow.AddDays(1), WordPair = pair
            });
            context.UserWordPairs.Add(new UserWordPair()
            {
                UserId = userId, TimeGap = DateTime.UtcNow.AddDays(2), WordPair = pair
            });
            context.UserWordPairs.Add(new UserWordPair()
            {
                UserId = userId, TimeGap = DateTime.UtcNow.AddDays(3), WordPair = pair
            });

            context.SaveChanges();

            var words = new GetLearningUserWords(context);
            var test  = await words.Handle(new GetLearningUserWordsQuery(userId)).ConfigureAwait(false);

            Assert.Equal(3, test.Count());
            context.Dispose();
        }
Exemplo n.º 4
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();
        }