Exemplo n.º 1
0
        public async Task GetAllStages_WhenThreeAreAdded_ReturnsThree()
        {
            // Arrange
            var connectionStringBuild =
                new SqliteConnectionStringBuilder {
                DataSource = ":memory:"
            };
            var connection = new SqliteConnection(connectionStringBuild.ToString());

            var options = new DbContextOptionsBuilder <StageBuilderDbContext>()
                          .UseSqlite(connection)
                          .Options;

            using (var context = new StageBuilderDbContext(options))
            {
                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                context.AddRange(new List <StageEntity>
                {
                    new StageEntity()
                    {
                        UserId          = 1,
                        GameId          = 1,
                        CreatedDate     = DateTime.Now,
                        LastUpdatedDate = DateTime.Now
                    },
                    new StageEntity()
                    {
                        UserId          = 1,
                        GameId          = 1,
                        CreatedDate     = DateTime.Now,
                        LastUpdatedDate = DateTime.Now
                    },
                    new StageEntity()
                    {
                        UserId          = 1,
                        GameId          = 1,
                        Published       = true,
                        CreatedDate     = DateTime.Now,
                        LastUpdatedDate = DateTime.Now
                    }
                }.ToArray());
                context.SaveChanges();
            }

            using (var context = new StageBuilderDbContext(options))
            {
                var service = new StageService(context);

                // Act
                var stages = await service.GetAllPublishedStagesAsync();

                // Assertion
                var expectedCount = 3;
                var msg           = $"There are {expectedCount} {Entities} in the database";
                stages.Should().HaveCount(expectedCount, because: msg);
            }
        }