public async Task FindById_ReturnLectureDetailModel() { //Arrange var lecturesList = await lectureService.GetAll(); var lastLecture = lecturesList[lecturesList.Count - 1]; //Act var result = await lectureService.FindById(lastLecture.Id); //Assert Assert.IsInstanceOfType(result, typeof(LectureDetailsModel)); }
public void ReturnNull_IfLectureNotFound() { // Arrange var lectures = this.GetLectures(); var mockDbContext = new Mock <IDatabaseContext>(); var mockSet = new Mock <IDbSet <Lecture> >(); mockSet.As <IQueryable <Lecture> >().Setup(m => m.Provider).Returns(lectures.Provider); mockSet.As <IQueryable <Lecture> >().Setup(m => m.Expression).Returns(lectures.Expression); mockSet.As <IQueryable <Lecture> >().Setup(m => m.ElementType).Returns(lectures.ElementType); mockDbContext.Setup(c => c.Lectures).Returns(mockSet.Object); var lectureId = Guid.NewGuid().ToString(); var lectureService = new LectureService(mockDbContext.Object); // Act var lecture = lectureService.FindById(lectureId); // Assert Assert.IsNull(lecture); }
public void ReturnRightLecture() { // Arrange var lectures = this.GetLectures(); var mockDbContext = new Mock <IDatabaseContext>(); var mockSet = new Mock <IDbSet <Lecture> >(); mockSet.As <IQueryable <Lecture> >().Setup(m => m.Provider).Returns(lectures.Provider); mockSet.As <IQueryable <Lecture> >().Setup(m => m.Expression).Returns(lectures.Expression); mockSet.As <IQueryable <Lecture> >().Setup(m => m.ElementType).Returns(lectures.ElementType); mockDbContext.Setup(c => c.Lectures).Returns(mockSet.Object); var lectureService = new LectureService(mockDbContext.Object); // Act var lecture = lectureService.FindById(this.searchedLectureId); // Assert Assert.AreEqual(this.lecturesTitle, lecture.Title); Assert.AreEqual(this.searchedLectureId, lecture.Id); }