public async void GetClassRooms_All_SuccessTest() { var testItems = new List<ClassRoom.ClassRoom>() { new ClassRoom.ClassRoom() { Id = Guid.NewGuid() }, new ClassRoom.ClassRoom() { Id = Guid.NewGuid() } }; Mock<IClassRoomRepository> mockRepo = new Mock<IClassRoomRepository>(); mockRepo.Setup(r => r.Get(null)).Returns(Task.FromResult(testItems.AsEnumerable())); var service = new ClassRoomService(mockRepo.Object); var items = await service.GetClassRooms(); Assert.Equal(2, items.Count()); }
public async void GetClassRooms_WithCriteria_SuccessTest() { var testId = Guid.NewGuid(); var testItems = new List<ClassRoom.ClassRoom>() { new ClassRoom.ClassRoom() { Id = testId, Name = "Class A" }, }; var criteria = new List<SearchCriteria>() { new SearchCriteria() { SearchField = "Name", SearchOperator = SearchOperator.Equals, SearchValue = "Class A" } }; Mock<IClassRoomRepository> mockRepo = new Mock<IClassRoomRepository>(); mockRepo.Setup(r => r.Get(It.Is<List<SearchCriteria>>(c => c.Equals(criteria)))).Returns(Task.FromResult(testItems.AsEnumerable())); var service = new ClassRoomService(mockRepo.Object); var items = await service.GetClassRooms(criteria); Assert.Equal(1, items.Count()); Assert.Equal(testId, items.First().Id); }
public async void GetClassRooms_EmptyResult_SuccessTest() { Mock<IClassRoomRepository> mockRepo = new Mock<IClassRoomRepository>(); mockRepo.Setup(r => r.Get(It.IsAny<List<SearchCriteria>>())).Returns(Task.FromResult((new List<ClassRoom.ClassRoom>()).AsEnumerable())); var service = new ClassRoomService(mockRepo.Object); var items = await service.GetClassRooms(new List<SearchCriteria>()); Assert.Empty(items); }