public IActionResult GetAllServers() { var servers = _repo.GetServers(); var serversDTO = new List <MinecraftServerDTO>(); foreach (var server in servers) { var serverDTO = _mapper.Map <MinecraftServerDTO>(server); serversDTO.Add(serverDTO); } return(Ok(serversDTO)); }
public R.ResultVm <List <ServerOnlyVm> > GetServers() { var result = new R.ResultVm <List <ServerOnlyVm> >().FromEmptyFailure(); if (result.Errors.Count == 0) { try { return(new ResultVm <List <ServerOnlyVm> >().FromSuccessObject(_repo.GetServers().Select(s => s.ToServerOnlyVm()).ToList())); } catch (Exception ex) { return(new ResultVm <List <ServerOnlyVm> >().FromException(ex)); } } return(result); }
public async Task GetServersTest() { // Arrange await _repo.AddServer(fooServer1); await _repo.AddServer(fooServer2); // Act var servers = _repo.GetServers(0, 2).ToList(); await _repo.RemoveServer(fooServer1.Id); await _repo.RemoveServer(fooServer2.Id); Console.WriteLine(servers); // Assert var expectedFooServer1 = servers.Where(s => s.Id == fooServer1.Id).FirstOrDefault(); var expectedFooServer2 = servers.Where(s => s.Id == fooServer2.Id).FirstOrDefault(); Assert.NotNull(servers); Assert.Equal(fooServer1.Name, expectedFooServer1.Name); Assert.Equal(fooServer2.Name, expectedFooServer2.Name); Assert.Equal(2, servers.Count()); }