Exemplo n.º 1
0
        public void Get_Video_By_Id()
        {
            var videos = new List <Video>
            {
                new Video
                {
                    Title = "Def",
                    Id    = 324
                },

                new Video
                {
                    Title = "Abc",
                    Id    = -1
                }
            }.AsQueryable();

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

            mockSet.As <IQueryable <Video> >().Setup(b => b.Provider).Returns(videos.Provider);
            mockSet.As <IQueryable <Video> >().Setup(b => b.Expression).Returns(videos.Expression);
            mockSet.As <IQueryable <Video> >().Setup(b => b.ElementType).Returns(videos.ElementType);
            mockSet.As <IQueryable <Video> >().Setup(b => b.GetEnumerator()).Returns(videos.GetEnumerator);

            var mockCtx = new Mock <LibraryDbContext>();

            mockCtx.Setup(c => c.Videos).Returns(mockSet.Object);

            var sut   = new VideoService(mockCtx.Object);
            var video = sut.Get(-1);

            video.Title.Should().Be("Abc");
        }
Exemplo n.º 2
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IVideoService, IVideoRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Video>(null));
            var service = new VideoService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VideoModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALVideoMapperMock);

            ApiVideoServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 3
0
 public JsonResult Get() =>
 new JsonResult(_videoService.Get());
Exemplo n.º 4
0
 public ActionResult <List <Video> > Get() =>
 _VideoService.Get();
Exemplo n.º 5
0
 public void OnGet()
 {
     Videos = _videoService.Get();
 }