public static void Login(SUGARClient client, string gameName, string userKey, out GameResponse game, out AccountResponse user) { var accountRequest = new AccountRequest { Name = userKey, Password = "******", SourceToken = "SUGAR" }; //gameId is 1 so that user is able to log in to get actual gameId (can in theory be anything) try { client.Session.Login(1, accountRequest); } catch { client.Session.CreateAndLogin(1, accountRequest); } var games = client.Game.Get(gameName); if (games.Any()) { game = games.Single(g => g.Name == gameName); user = client.Session.Login(game.Id, accountRequest); } else { throw new Exception("This game has not been set up in seeding."); } }
public SUGARClient CreateSugarClient(Dictionary <string, string> persistentHeaders = null, Dictionary <string, string> sessionHeaders = null) { var client = Server.CreateClient(); var testHttpHandler = new HttpClientHandler(client); var sugarClient = new SUGARClient(Server.BaseAddress.AbsoluteUri, testHttpHandler, true, persistentHeaders, sessionHeaders); return(sugarClient); }
public ClientTestsFixture() { var builder = WebHost.CreateDefaultBuilder() .UseStartup <Startup>() .UseEnvironment("Tests"); Server = new TestServer(builder); Program.Setup(Server.Host); SUGARClient = CreateSugarClient(); }
public static AccountResponse CreateAndLoginGlobal(SUGARClient client, string userName, bool issueLoginToken = false) { try { return(client.Session.CreateAndLogin(GlobalGameId, new AccountRequest { Name = userName, Password = "******", SourceToken = SugarSourceToken, IssueLoginToken = issueLoginToken })); } catch { return(client.Session.Login(GlobalGameId, new AccountRequest { Name = userName, Password = "******", SourceToken = SugarSourceToken, IssueLoginToken = issueLoginToken })); } }
public static AccountResponse LoginWithToken(SUGARClient client, string token) { return(client.Session.Login(token)); }