public void GetSongs()
        {
            var data = new List <Song>
            {
                testSong
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Song> >();

            mockSet.As <IQueryable <Song> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Song> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Song> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Song> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <DatabaseContext>();

            mockContext.Setup(c => c.Songs).Returns(mockSet.Object);

            var service = new SongsRepository(mockContext.Object);
            var blogs   = service.GetSongs();

            Assert.AreEqual(1, blogs.Count());
        }
Esempio n. 2
0
 // GET: api/Songs
 public IQueryable <Song> GetSongs()
 {
     return(dbRepository.GetSongs());
 }