public override void GetOneByExistingId() { // Rental needs to contact VideoRepo to get rented video var mockVideoRepository = new Mock <IRepository <Video> >(); MockUOW.Setup(uow => uow.VideoRepository).Returns(mockVideoRepository.Object); // Rental needs to contact UserRepo to get user who rented var mockUserRepository = new Mock <IRepository <User> >(); MockUOW.Setup(uow => uow.UserRepository).Returns(mockUserRepository.Object); // Setup mock repos to respond with valid data MockRentalRepository.Setup(r => r.GetById(MockRentalBO.Id)).Returns(MockRental); mockVideoRepository.Setup(vr => vr.GetById(It.IsAny <int>())).Returns( new Video() { Id = 1, Title = "Die Hard" }); mockUserRepository.Setup(gr => gr.GetById(It.IsAny <int>())).Returns( new User() { Id = 1, Username = "******", Password = "******", RoleId = 1, Role = new Role() }); var entity = _service.GetById(MockRentalBO.Id); Assert.NotNull(entity); }
public void OnlyGetRentalWithUserByExistingId_WhenVideoDoNotExist() { // Rental needs to contact VideoRepo to get rented video var mockVideoRepository = new Mock <IRepository <Video> >(); MockUOW.Setup(uow => uow.VideoRepository).Returns(mockVideoRepository.Object); // Rental needs to contact UserRepo to get user who rented var mockUserRepository = new Mock <IRepository <User> >(); MockUOW.Setup(uow => uow.UserRepository).Returns(mockUserRepository.Object); // Setup mock repos to respond with valid data MockRentalRepository.Setup(r => r.GetById(MockRentalBO.Id)).Returns( new Rental() { Id = 1, UserId = 1, VideoId = 1 }); mockVideoRepository.Setup(vr => vr.GetById(It.IsAny <int>())).Returns(() => null); mockUserRepository.Setup(gr => gr.GetById(It.IsAny <int>())).Returns( new User() { Id = 1, Username = "******", Password = "******", RoleId = 1, Role = new Role() }); var entity = _service.GetById(MockRentalBO.Id); Assert.NotNull(entity); Assert.NotNull(entity.User); Assert.Null(entity.Video); }
public override void GetOneByExistingId() { MockUserRepository.Setup(r => r.GetById(MockUser.Id)).Returns(MockUser); var roleRepository = new Mock <IRepository <Role> >(); MockUOW.Setup(uow => uow.RoleRepository).Returns(roleRepository.Object); roleRepository.Setup(rr => rr.GetById(It.IsAny <int>())).Returns(new Role()); var entity = _service.GetById(MockUserBO.Id); Assert.NotNull(entity); }
public void GetOneWithoutGenreByExistingId_WhenGenreDoNotExist() { MockVideoRepository.Setup(r => r.GetById(MockVideoBO.Id)).Returns(MockVideo); var mockGenreRepository = new Mock <IRepository <Genre> >(); MockUOW.Setup(uow => uow.GenreRepository).Returns(mockGenreRepository.Object); mockGenreRepository.Setup(r => r.GetAllByIds(It.IsAny <List <int> >())).Returns(() => null); var entity = _service.GetById(MockVideoBO.Id); Assert.NotNull(entity); Assert.Null(entity.Genres); }
public override void GetOneByExistingId() { var mockGenreRepository = new Mock <IRepository <Genre> >(); MockUOW.Setup(uow => uow.GenreRepository).Returns(mockGenreRepository.Object); MockVideoBO.GenreIds = new List <int> { 1 }; var genre = new Genre { Id = 1, Name = "Action" }; MockVideo.Genres = new List <VideoGenre> { new VideoGenre { GenreId = 1, VideoId = 1 } }; MockVideoRepository.Setup(r => r.GetById(MockVideo.Id)).Returns(MockVideo); mockGenreRepository.Setup(g => g.GetAllByIds(MockVideoBO.GenreIds)).Returns( new List <Genre> { genre }); var existingId = MockVideoBO.Id; var entity = _service.GetById(existingId); Assert.NotNull(entity); Assert.NotEmpty(entity.Genres); }
public ProfileServiceShould() { MockUOW.Setup(uow => uow.ProfileRepository).Returns(MockProfileRepository.Object); _service = new ProfileService(MockDALFacade.Object); }
public GenreServiceShould() { MockUOW.Setup(uow => uow.GenreRepository).Returns(MockGenreRepository.Object); _service = new GenreService(MockDALFacade.Object); }
public RentalServiceShould() { MockUOW.Setup(uow => uow.RentalRepository).Returns(MockRentalRepository.Object); _service = new RentalService(MockDALFacade.Object); }