Exemple #1
0
        public void FindNotes_SearchTermAndOneCategory_ShouldReturnOneNote()
        {
            var mockContext = new Mock <NexusContext>();

            mockContext.Setup(nex => nex.Set <Category>()).Returns(TestHelpers.MockDbSet(new List <Category>()
            {
                new Category()
                {
                    Id = 1, Title = "Cat 1"
                },
                new Category()
                {
                    Id = 2, Title = "Cat 1.1", ParentId = 1
                },
                new Category()
                {
                    Id = 3, Title = "Cat 2"
                },
                new Category()
                {
                    Id = 4, Title = "Cat 2.1", ParentId = 3
                }
            }));

            mockContext.Setup(nex => nex.Set <Note>()).Returns(TestHelpers.MockDbSet(new List <Note>()
            {
                new Note()
                {
                    Id = 1, Title = "Note A"
                },
                new Note()
                {
                    Id = 2, Title = "Note B"
                },
                new Note()
                {
                    Id = 3, Title = "Note C"
                },
                new Note()
                {
                    Id = 4, Title = "Note D"
                },
            }));

            mockContext.Setup(nex => nex.Set <NoteCategory>()).Returns(TestHelpers.MockDbSet(new List <NoteCategory>
            {
                new NoteCategory {
                    NoteId = 1, CategoryId = 1
                },
                new NoteCategory {
                    NoteId = 2, CategoryId = 2
                },
                new NoteCategory {
                    NoteId = 3, CategoryId = 3
                },
                new NoteCategory {
                    NoteId = 4, CategoryId = 4
                }
            }));

            var repo = new NoteRepository(mockContext.Object);

            string userSearchTerm = "Note";

            int[] categories = { 1 };
            int[] tags       = Array.Empty <int>();
            int   pageNumber = 1;
            int   pageSize   = 25;
            var   notes      = repo.FindNotes(userSearchTerm, categories, tags, pageNumber, pageSize).ToList();

            Assert.Contains(notes, note => note.Title == "Note A");
            Assert.Single(notes);
        }