Beispiel #1
0
        public async Task ReturnsDataFromStorage()
        {
            var expectedServers = new[]
            {
                new Server(Guid.NewGuid(), "Lithuania #1", 20),
                new Server(Guid.NewGuid(), "Latvia #1", 500),
                new Server(Guid.NewGuid(), "Estonia #1", 750)
            };

            await _dbContext.MigrateDatabase();

            await _dbContext.Servers.AddRangeAsync(expectedServers);

            await _dbContext.SaveChangesAsync();

            var result = (await _repository.GetAll()).ToList();

            Assert.Equal(3, result.Count);

            foreach (var(id, name, distance) in expectedServers)
            {
                var server = result.Find(s => s.Id == id) !;

                Assert.NotNull(server);
                Assert.Equal(id, server.Id);
                Assert.Equal(name, server.Name);
                Assert.Equal(distance, server.Distance);
            }
        }
Beispiel #2
0
        public async Task <int> RunAsync(Func <ServersDbContext, Task>?databaseContextFunc = null)
        {
            await _databaseContext.MigrateDatabase();

            _databaseContext.Servers.RemoveRange(_databaseContext.Servers);
            await _databaseContext.SaveChangesAsync();

            if (databaseContextFunc != null)
            {
                await databaseContextFunc(_databaseContext);
            }

            await _host.RunAsync();

            return(_state.ExitCode);
        }