Exemplo n.º 1
0
        public async Task ReturnCollectionOfProjections_WhenCountIsValid()
        {
            //Arrange
            // Create a new options instance telling the context to use an InMemory database and the new service provider.
            var contextOptions = new DbContextOptionsBuilder <AlphaCinemaContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfProjections_WhenCountIsValid")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var listOfProjections = new List <Projection>()
            {
                testProjectionOne, testProjectionTwo, testProjectionThree
            };
            var listOfMovies = new List <Movie>()
            {
                testMovieOne, testMovieTwo, testMovieThree
            };

            //Act and Assert
            using (var actContext = new AlphaCinemaContext(contextOptions))
            {
                await actContext.AddRangeAsync(listOfProjections);

                await actContext.AddRangeAsync(listOfMovies);

                await actContext.AddAsync(testOpenHour);

                await actContext.AddAsync(testCity);

                await actContext.SaveChangesAsync();
            }

            //Assert
            using (var assertContext = new AlphaCinemaContext(contextOptions))
            {
                var command = new ProjectionService(assertContext);
                var result  = await command.GetTopProjections(projectionCount);

                Assert.AreEqual(testProjectionOne.Id, result.First().Id);
                //We are returning the FirstProjection and we want the top 1
            }
        }