public void IsValidOnly()
        {
            // arrange
            var sshServer    = SshServerServiceTests.SshServerInsert(_sshServerSerivce);
            var pavlovServer = PavlovServer(sshServer);

            _pavlovServerService.Upsert(pavlovServer).GetAwaiter().GetResult();
            // act
            _pavlovServerService.IsValidOnly(pavlovServer).GetAwaiter().GetResult();
            // assert
            var pavlovServers = _pavlovServerService.FindAll().GetAwaiter().GetResult();

            pavlovServers.Should().HaveCount(1);
        }
        public async Task <IActionResult> SaveServer(PavlovServerViewModel server)
        {
            if (!ModelState.IsValid)
            {
                return(View("Server", server));
            }

            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), server.Id, _service, _pavlovServerService))
            {
                return(Forbid());
            }

            server.LiteDbUsers = (await _userservice.FindAll()).ToList();

            server.Owner = (await _userservice.FindAll())
                           .FirstOrDefault(x => x.Id == new ObjectId(server.LiteDbUserId));
            var resultServer = new PavlovServer();

            server.SshServer = await _service.FindOne(server.sshServerId);

            if (server.create)
            {
                // Duplicate Database entries check
                try
                {
                    await _pavlovServerService.IsValidOnly(server, false);

                    if (string.IsNullOrEmpty(server.SshServer.SshPassword))
                    {
                        throw new ValidateException("Id",
                                                    "Please add a sshPassword to the ssh user (Not root user). Sometimes the systems asks for the password even if the keyfile and passphrase is used.");
                    }
                    if (string.IsNullOrEmpty(server.ServerFolderPath))
                    {
                        throw new ValidateException("ServerFolderPath",
                                                    "The server ServerFolderPath is needed!");
                    }
                    if (!server.ServerFolderPath.EndsWith("/"))
                    {
                        throw new ValidateException("ServerFolderPath",
                                                    "The server ServerFolderPath needs a / at the end!");
                    }
                    if (!server.ServerFolderPath.StartsWith("/"))
                    {
                        throw new ValidateException("ServerFolderPath",
                                                    "The server ServerFolderPath needs a / at the start!");
                    }
                    if (server.ServerPort <= 0)
                    {
                        throw new ValidateException("ServerPort", "The server port is needed!");
                    }
                    if (server.TelnetPort <= 0)
                    {
                        throw new ValidateException("TelnetPort", "The rcon port is needed!");
                    }
                    if (string.IsNullOrEmpty(server.ServerSystemdServiceName))
                    {
                        throw new ValidateException("ServerSystemdServiceName",
                                                    "The server service name is needed!");
                    }
                    if (string.IsNullOrEmpty(server.Name))
                    {
                        throw new ValidateException("Name", "The Gui name is needed!");
                    }
                }
                catch (ValidateException e)
                {
                    ModelState.AddModelError(e.FieldName, e.Message);
                    return(await GoBackEditServer(server,
                                                  "Field is not set: " + e.Message));
                }

                if (server.SshKeyFileNameForm != null)
                {
                    await using var ms = new MemoryStream();
                    await server.SshKeyFileNameForm.CopyToAsync(ms);

                    var fileBytes = ms.ToArray();
                    server.SshKeyFileNameRoot = fileBytes;
                    // act on the Base64 data
                }

                try
                {
                    await _pavlovServerService.CreatePavlovServer(server);
                }
                catch (Exception e)
                {
                    return(await GoBackEditServer(server, e.Message, true));
                }
            }

            try
            {
                //save and validate server a last time
                resultServer = await _pavlovServerService.Upsert(server.toPavlovServer(server));
            }
            catch (ValidateException e)
            {
                ModelState.AddModelError(e.FieldName, e.Message);
                return(await GoBackEditServer(server,
                                              "Could not validate server -> " + e.Message, server.create));
            }

            if (ModelState.ErrorCount > 0)
            {
                return(await EditServer(server));
            }
            if (server.create)
            {
                return(Redirect("/PavlovServer/EditServerSelectedMaps/" + resultServer.Id));
            }

            return(RedirectToAction("Index", "SshServer"));
        }