public void CinemaService_GetAllCinemasAsync_ReturnsListOfCinemas() { //Arrange var expectedCount = 2; Data.Cinema cinema2 = new Data.Cinema { Id = 22, CityId = 1, Name = "Los bioskop" }; CinemaDomainModel cinemaDomainModel2 = new CinemaDomainModel { Id = cinema2.Id, CityId = cinema2.CityId, Name = cinema2.Name }; List <Data.Cinema> cinemas = new List <Data.Cinema>(); cinemas.Add(_cinema); cinemas.Add(cinema2); _mockCinemaRepository.Setup(x => x.GetAll()).ReturnsAsync(cinemas); //Act var resultAction = cinemaService.GetAllAsync().ConfigureAwait(false).GetAwaiter().GetResult(); var result = resultAction.ToList(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedCount, result.Count); Assert.AreEqual(_cinema.Name, result[0].Name); Assert.IsInstanceOfType(resultAction, typeof(IEnumerable <CinemaDomainModel>)); }
public async Task GetAllCinemas_ExpectedBehaviour() { // Arrange var fixture = new Fixture(); var expectedCinemas = fixture.Create <List <Cinema> >(); var cinemaRepoMock = new Mock <ICinemaRepository>(); cinemaRepoMock .Setup((r) => r.GetAllAsync()) .ReturnsAsync(() => expectedCinemas); var uowMock = new Mock <IUnitOfWork>(); uowMock .Setup(x => x.Cinemas) .Returns(cinemaRepoMock.Object); var cinemaService = new CinemaService(uowMock.Object); // Act var actualCinemas = await cinemaService.GetAllAsync(); // Assert Assert.Equal(actualCinemas, expectedCinemas); }
public void CinemaService_GetAllAsync_ReturnNull() { //Arrange IEnumerable <Data.Cinema> cinemas = null; Task <IEnumerable <Data.Cinema> > responseTask = Task.FromResult(cinemas); _mockCinemasRepository = new Mock <ICinemasRepository>(); _mockCinemasRepository.Setup(x => x.GetAll()).Returns(responseTask); CinemaService cinemaController = new CinemaService(_mockCinemasRepository.Object, _mockAuditoriumService.Object, _mockAuditoriumsRepository.Object, _mockProjectionsRepository.Object, _mockTicketService.Object, _mockSeatsRepository.Object); //Act var resultAction = cinemaController.GetAllAsync().ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNull(resultAction); }
public async Task GetAllCinemasAsync_EmptyResult() { // Arrange var cinemaRepoMock = new Mock <ICinemaRepository>(); cinemaRepoMock .Setup((r) => r.GetAllAsync()) .ReturnsAsync(() => new List <Cinema>()); var uowMock = new Mock <IUnitOfWork>(); uowMock .Setup(x => x.Cinemas) .Returns(cinemaRepoMock.Object); var cinemaService = new CinemaService(uowMock.Object); // Act var cinemas = await cinemaService.GetAllAsync(); // Assert Assert.Empty(cinemas); }
public void CinemaService_GetAllAsync_ReturnListOfCinemas() { //Arrange int expectedResultCount = 1; IEnumerable <Data.Cinema> cinemas = _listOfCinemas; Task <IEnumerable <Data.Cinema> > responseTask = Task.FromResult(cinemas); _mockCinemasRepository.Setup(x => x.GetAll()).Returns(responseTask); CinemaService cinemaController = new CinemaService(_mockCinemasRepository.Object, _mockAuditoriumService.Object, _mockAuditoriumsRepository.Object, _mockProjectionsRepository.Object, _mockTicketService.Object, _mockSeatsRepository.Object); //Act var resultAction = cinemaController.GetAllAsync().ConfigureAwait(false).GetAwaiter().GetResult(); var result = (List <CinemaDomainModel>)resultAction; //Assert Assert.IsNotNull(result); Assert.AreEqual(expectedResultCount, result.Count); Assert.AreEqual(_cinema.Id, result[0].Id); Assert.IsInstanceOfType(result[0], typeof(CinemaDomainModel)); }