public async Task FilterSpellsAsync_ShouldReturnSpells_WhenPassedValidParameters()
        {
            // Arrange
            var contextOptions = new DbContextOptionsBuilder <DataContext>()
                                 .UseInMemoryDatabase(databaseName: "FilterSpellsAsync_ShouldReturnSpells_WhenPassedValidParameters")
                                 .Options;

            string validSortOrder  = "name_asc";
            string validFilter     = "testSpell";
            int    validPageSize   = 10;
            int    validPageNumber = 1;

            string validName = "testSpell";

            Spell validSpell = new Spell
            {
                Id   = Guid.NewGuid(),
                Name = validName
            };

            IEnumerable <Spell> result = new List <Spell>();

            // Act
            using (DataContext actContext = new DataContext(contextOptions))
            {
                Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();

                await actContext.Spells.AddAsync(validSpell);

                await actContext.SaveChangesAsync();

                SpellService SUT = new SpellService(
                    pandaScoreClientMock.Object,
                    actContext);

                result = await SUT.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, validPageSize);
            }

            // Assert
            using (DataContext assertContext = new DataContext(contextOptions))
            {
                var spell = result.ToArray()[0];

                Assert.IsTrue(assertContext.Spells.Count().Equals(result.Count()));
                Assert.IsTrue(assertContext.Spells.Any(s => s.Name.Equals(spell.Name)));
            }
        }
Пример #2
0
        public async Task ThrowArgumentOutOfRangeException_WhenPassedInvalidPageSize(int invalidPageSize)
        {
            // Arrange
            Mock <IPandaScoreClient> pandaScoreClientMock = new Mock <IPandaScoreClient>();
            Mock <DataContext>       dataContextMock      = new Mock <DataContext>();

            string validSortOrder  = string.Empty;
            string validFilter     = string.Empty;
            int    validPageNumber = 1;

            SpellService SUT = new SpellService(
                pandaScoreClientMock.Object,
                dataContextMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(
                () => SUT.FilterSpellsAsync(validSortOrder, validFilter, validPageNumber, invalidPageSize));
        }