public async Task GetAsyncReturnsSearchedElementMapped() { // Arrange var projections = new List <FilmProjection> { new FilmProjection { Id = "1", Cinema = new Cinema { Name = "Best", City = "Sliven", Country = "Bulgaria" }, ProjectionType = ProjectionType._4D, Date = DateTime.Now, Film = new Film { FilmData = new FilmData { Title = "FilmTitle", TargetAudience = TargetAudience.Adults, Runtime = 50 } }, TotalTickets = 100, TicketPrices = new TicketPrices() }, new FilmProjection { Id = "2" }, }.AsQueryable(); var mockSet = new Mock <DbSet <FilmProjection> >(); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Provider).Returns(projections.Provider); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Expression).Returns(projections.Expression); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.ElementType).Returns(projections.ElementType); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.GetEnumerator()).Returns(projections.GetEnumerator()); var mockContext = new Mock <CinemaDbContext>(); mockContext.Setup(c => c.FilmProjections).Returns(mockSet.Object); mockContext.Setup(c => c.FilmProjections.FindAsync(It.IsAny <string>())). Returns(new ValueTask <FilmProjection>(projections.First())); var projectionBusiness = new FilmProjectionBusiness(mockContext.Object, new EmailSender("TestAPIKey", "TestSender", "TestSenderName")); var searchedProj = projections.First(); var mapper = new Mapper(); // Act var resultProj = await projectionBusiness.GetAsync(searchedProj.Id, mapper.MapToProjectionDataViewModel); // Assert Assert.AreEqual(searchedProj.Id, resultProj.Id, "Doesn't return the searched projection data mapped."); }
public async Task GetReturnsSearchedElementFromDb() { // Arrange var projections = new List <FilmProjection> { new FilmProjection { Id = "1" }, new FilmProjection { Id = "2" } }.AsQueryable(); var mockSet = new Mock <DbSet <FilmProjection> >(); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Provider).Returns(projections.Provider); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Expression).Returns(projections.Expression); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.ElementType).Returns(projections.ElementType); mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.GetEnumerator()).Returns(projections.GetEnumerator()); var mockContext = new Mock <CinemaDbContext>(); mockContext.Setup(c => c.FilmProjections).Returns(mockSet.Object); mockContext.Setup(c => c.FilmProjections.FindAsync(It.IsAny <string>())).Returns(new ValueTask <FilmProjection>((projections.First()))); var projectionBusiness = new FilmProjectionBusiness(mockContext.Object, new EmailSender("TestAPIKey", "TestSender", "TestSenderName")); var searchedProj = projections.First(); // Act var resultProj = await projectionBusiness.GetAsync(searchedProj.Id); // Assert Assert.AreEqual(searchedProj.Id, resultProj.Id, "Doesn't return the searched element from the database."); }