Ejemplo n.º 1
0
        public async Task GetAll_JournalsFound_Limit_ReturnsLimitedJournals()
        {
            // Arrange
            await PrepareDatabase();

            var journals = Helpers.GetJournals(5);

            Context !.Journals?.AddRange(journals);
            await Context.SaveChangesAsync();

            var repo = GetJournalRepo();

            // Act
            var result = await repo.GetAll(new QueryFilter { Limit = 2 });

            // Assert
            result !.Count().Should().Be(2);
        }
Ejemplo n.º 2
0
        public async Task RemoveAllByUser_UserFound_JournalsRemoved()
        {
            // Arrange
            await PrepareDatabase();

            var journals = Helpers.GetJournals(3);

            Helpers.AddEntriesToJournal(journals[2], Helpers.GetEntries(20));
            Context !.Journals?.AddRange(journals);
            await Context.SaveChangesAsync();

            _service = GetJournalService();

            // Act
            var result = await _service.RemoveAllByUser("UserId");

            // Assert
            result.Should().BeGreaterOrEqualTo(20);
        }
Ejemplo n.º 3
0
        public async Task GetAll_JournalsFound_NoLimit_ReturnsAllJournals()
        {
            // Arrange
            await PrepareDatabase();

            var journals = Helpers.GetJournals(5);

            journals[3].UserId = "Blah McBlahston";
            journals[4].UserId = "Blah McBlahston";
            Context !.Journals?.AddRange(journals);
            await Context.SaveChangesAsync();

            var repo = GetJournalRepo();

            // Act
            var result = await repo.GetAll();

            // Assert
            result !.Count().Should().Be(3);
        }
Ejemplo n.º 4
0
        public async Task Find_WhereTitleContainsDog_ReturnsJournal()
        {
            // Arrange
            await PrepareDatabase();

            var journals = Helpers.GetJournals(3);

            journals[1].Title = "A Dog Wrote This";
            Context !.Journals?.AddRange(journals);
            await Context.SaveChangesAsync();

            var repo = GetJournalRepo();

            // Act
            var result = await repo.Find(j => j.Title !.Contains("Dog"));

            // Assert
            result.Should().NotBeNull();
            result?.Title.Should().Be(journals[1].Title);
        }
Ejemplo n.º 5
0
        public async Task GetAll_JournalsFound_OrderByTitleAscending_ReturnsOrderedJournals()
        {
            // Arrange
            await PrepareDatabase();

            var journals   = Helpers.GetJournals(3);
            var fancyTitle = "My Fancy Title";
            var xyz        = "XYZ";
            var alphabets  = "Alphabets and Stuff";

            journals[0].Title = fancyTitle;
            journals[1].Title = xyz;
            journals[2].Title = alphabets;
            Context !.Journals?.AddRange(journals);
            await Context.SaveChangesAsync();

            var repo = GetJournalRepo();

            // Act
            var result = await repo.GetAll(new QueryFilter { OrderBy = "asc" }) as List <Journal>;

            // Assert
            result.Should().BeInAscendingOrder(j => j.Title);
        }