Example #1
0
        public async Task NewEntriesNotAddedIfScoreLowerThanLastPlace()
        {
            HighscoreEntriesController controller = createController("NewEntriesNotAddedIfScoreLowerThanLastPlace");

            for (int points = 10; points <= 110; points += 10)
            {
                await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asdf", Points = points });
            }

            // Act
            ActionResult <IEnumerable <HighscoreEntry> > result = await controller.GetHighscoreEntries();

            // Assert
            ActionResult <IEnumerable <HighscoreEntry> > viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);

            Assert.Equal(10, viewResult.Value.Count());

            await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asdf", Points = 9 });

            result = await controller.GetHighscoreEntries();

            viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);
            Assert.Equal(10, viewResult.Value.Count());
            Assert.NotEqual(9, viewResult.Value.Last().Points);
        }
Example #2
0
        public async Task NoEntries()
        {
            HighscoreEntriesController controller = createController("NoEntries");

            // Act
            ActionResult <IEnumerable <HighscoreEntry> > result = await controller.GetHighscoreEntries();

            // Assert
            ActionResult <IEnumerable <HighscoreEntry> > viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);

            Assert.Empty(viewResult.Value);
        }
Example #3
0
        public async Task EntriesCanBeAdded()
        {
            HighscoreEntriesController controller = createController("EntriesCanBeAdded");

            await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asd", Points = 100 });

            // Act
            ActionResult <IEnumerable <HighscoreEntry> > result = await controller.GetHighscoreEntries();

            // Assert
            ActionResult <IEnumerable <HighscoreEntry> > viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);

            Assert.NotEmpty(viewResult.Value);
        }
Example #4
0
        public async Task EntriesAreCappedAt10()
        {
            HighscoreEntriesController controller = createController("EntriesAreCappedAt10");

            for (int i = 0; i < 11; i++)
            {
                await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asdf", Points = 80 });
            }

            // Act
            ActionResult <IEnumerable <HighscoreEntry> > result = await controller.GetHighscoreEntries();

            // Assert
            ActionResult <IEnumerable <HighscoreEntry> > viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);

            Assert.Equal(10, viewResult.Value.Count());
        }
Example #5
0
        public async Task EntriesAreSorted()
        {
            HighscoreEntriesController controller = createController("EntriesAreSorted");

            await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asd", Points = 80 });

            await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asd", Points = 100 });

            await controller.PostHighscoreEntry(new HighscoreEntry { Name = "asd", Points = 90 });

            // Act
            ActionResult <IEnumerable <HighscoreEntry> > result = await controller.GetHighscoreEntries();

            // Assert
            ActionResult <IEnumerable <HighscoreEntry> > viewResult = Assert.IsType <ActionResult <IEnumerable <HighscoreEntry> > >(result);
            List <HighscoreEntry> list = viewResult.Value.ToList();

            Assert.Equal(100, list[0].Points);
            Assert.Equal(90, list[1].Points);
            Assert.Equal(80, list[2].Points);
        }