public void TestRefreshTokens() { var blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl); UserCredentials user = null; // Authenticate user to gain tokens Task.Run(async() => { APIResult <UserCredentials, JsonError> response = await blueprintApi.AsyncAuthenticateUser(validUser); user = response.GetSuccess(); }).GetAwaiter().GetResult(); // Refresh tokens Task.Run(async() => { APIResult <ResponseAuthenticate, JsonError> response = await blueprintApi.AsyncRefreshTokens(user); if (response.isSuccess()) { // Success case Assert.IsNotNull(response.GetSuccess().refresh); Assert.IsNotNull(response.GetSuccess().access); } else { // Failure case Assert.Fail(); } }).GetAwaiter().GetResult(); }
public void TestValidAuthenticateUser() { var blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl); UserCredentials user = validUser; UserCredentials returnUser = null; Task.Run(async() => { Task <APIResult <UserCredentials, JsonError> > fetchingResponse = blueprintApi.AsyncAuthenticateUser(user); APIResult <UserCredentials, JsonError> response = await fetchingResponse; if (response.isSuccess()) { // Success case returnUser = response.GetSuccess(); } else { //error case } }).GetAwaiter().GetResult(); // Check returned user is correct and contains access tokens Assert.That(returnUser.GetUsername(), Is.EqualTo(validUser.GetUsername())); Assert.That(returnUser.GetPassword(), Is.EqualTo(validUser.GetPassword())); Assert.IsNotNull(returnUser.GetAccessToken()); Assert.IsNotNull(returnUser.GetRefreshToken()); }
public void TestDeleteInventory() { var blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl); UserCredentials user = null; ResponseGetInventory finalInventory = null; // Authenticate user to gain access token Task.Run(async() => { APIResult <UserCredentials, JsonError> response = await blueprintApi.AsyncAuthenticateUser(validUser); user = response.GetSuccess(); }).GetAwaiter().GetResult(); // Add item to test user inventory Task.Run(async() => { List <InventoryEntry> entries = new List <InventoryEntry>(); entries.Add(new InventoryEntry(1, 1)); ResponseGetInventory inventory = new ResponseGetInventory(entries); APIResult <Boolean, JsonError> response = await blueprintApi.AsyncAddToInventory(user, inventory); }).GetAwaiter().GetResult(); // Delete inventory and assert on response Task.Run(async() => { try { APIResult <Boolean, JsonError> response = await blueprintApi.AsyncDeleteInventory(user); // Success case } catch (WebException e) { // Failure case Assert.Fail(); } }).GetAwaiter().GetResult(); }
public void TestGetInventory() { var blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl); UserCredentials user = null; ResponseGetInventory finalInventory = null; // Authenticate user to gain access token Task.Run(async() => { APIResult <UserCredentials, JsonError> response = await blueprintApi.AsyncAuthenticateUser(validUser); user = response.GetSuccess(); }).GetAwaiter().GetResult(); // Add item to test user inventory Task.Run(async() => { List <InventoryEntry> entries = new List <InventoryEntry>(); entries.Add(new InventoryEntry(1, 1)); ResponseGetInventory inventory = new ResponseGetInventory(entries); APIResult <Boolean, JsonError> response = await blueprintApi.AsyncAddToInventory(user, inventory); }).GetAwaiter().GetResult(); // Retrieve inventory of new user Task.Run(async() => { APIResult <ResponseGetInventory, JsonError> finalInventoryResponse = await blueprintApi.AsyncGetInventory(user); finalInventory = finalInventoryResponse.GetSuccess(); }).GetAwaiter().GetResult(); Assert.That(finalInventory.items[0].item_id, Is.EqualTo(1)); Assert.That(finalInventory.items[0].item_id, Is.GreaterThanOrEqualTo(1)); }
public void TestRegisterUserValidPassword() { var blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl); Random random = new Random(); UserCredentials returnUser = null; string username = "******" + random.Next(10000); Task.Run(async() => { Task <APIResult <UserCredentials, JsonError> > fetchingResponse = blueprintApi.AsyncRegisterUser(username, "Failure123"); APIResult <UserCredentials, JsonError> response = await fetchingResponse; if (response.isSuccess()) { // Success case returnUser = response.GetSuccess(); } else { // Failure case Assert.Fail(); } }).GetAwaiter().GetResult(); // Check returned user is correct and contains access tokens Assert.That(returnUser.GetUsername(), Is.EqualTo(username)); Assert.That(returnUser.GetPassword(), Is.EqualTo("Failure123")); Assert.IsNotNull(returnUser.GetAccessToken()); Assert.IsNotNull(returnUser.GetRefreshToken()); }
public void TestBlueprintApiDefaultCredentialsConstructor() { var blueprintApi = BlueprintAPI.DefaultCredentials(); UserCredentials user = null; // Authenticate user Task.Run(async() => { APIResult <UserCredentials, JsonError> response = await blueprintApi.AsyncAuthenticateUser(validUser); user = response.GetSuccess(); }).GetAwaiter().GetResult(); Assert.That(user.GetUsername(), Is.EqualTo(validUser.GetUsername())); }
public void Start() { heldItem = GameObject.Find("HeldItem"); currentHeld = 0; inventoryContents = new InventoryItem[size]; itemSlots = GameObject.Find("GridPanel").GetComponentsInChildren <InventorySlotController>().ToList(); UserCredentials user = GameManager.Instance().GetUserCredentials(); GameManager.Instance().store.Subscribe(this); var blueprintApi = BlueprintAPI.DefaultCredentials(); Task.Run(async() => { APIResult <ResponseGetInventory, JsonError> finalInventoryResponse = await blueprintApi.AsyncGetInventory(user); if (finalInventoryResponse.isSuccess()) { remoteInv = finalInventoryResponse.GetSuccess(); } else { JsonError error = finalInventoryResponse.GetError(); } }).GetAwaiter().GetResult(); foreach (InventoryEntry entry in remoteInv.items) { GameManager.Instance().store.Dispatch( new AddItemToInventory(entry.item_id, entry.quantity, GetItemName(entry.item_id))); } /* * Task.Run(async () => { * try { * APIResult<Boolean, JsonError> response = await blueprintApi.AsyncDeleteInventory(user); * * // Success case * } catch (WebException e) { * // Failure case * throw new System.Exception("Did not delete inventory."); * } * }).GetAwaiter().GetResult();*/ foreach (Transform child in heldItem.transform) { if (child.gameObject.CompareTag("Held")) { child.gameObject.GetComponent <Text>().text = GetItemName(inventoryContents[currentHeld].GetId()); } } }
public void onLoginClick() { setInfoMessage(""); string usernameLoginText = usernameLoginInput.text; string passwordLoginText = passwordLoginInput.text; // Validate user input if (string.IsNullOrWhiteSpace(usernameLoginText) || usernameLoginText.Length > maxUsernameLength) { setErrorMessage("Invalid username, it must have between 1 and 16 characters."); return; } else if (string.IsNullOrWhiteSpace(passwordLoginText)) { setErrorMessage("Please enter a non-empty password."); return; } UserCredentials userCredentials = new UserCredentials(usernameLoginText, passwordLoginText); UserCredentials returnUser; Task.Run(async() => { Task <APIResult <UserCredentials, JsonError> > fetchingResponse = api.AsyncAuthenticateUser(userCredentials); // TODO Add a visual cue ( using setInfoMessage(“Connecting . . . “) ) // to indicate to the user that the app is waiting on a response form the server. try { APIResult <UserCredentials, JsonError> response = await fetchingResponse; returnUser = response.GetSuccess(); GameManager.Instance().SetUserCredentials(returnUser); if (response.isSuccess()) { // Launch Blueprint SceneManager.LoadScene(SceneMapping.World); } else { setErrorMessage(response.GetError().error); } } catch (Exception e) { setErrorMessage(e.Message); } }).GetAwaiter().GetResult(); }
public static GameObjectsHandler WithRemoteSchema() { GameObjectsHandler goh = new GameObjectsHandler(); // Get schema BlueprintAPI api = BlueprintAPI.DefaultCredentials(); Task.Run(async() => { APIResult <string, JsonError> response = await api.AsyncGetItemSchema(); if (response.isSuccess()) { // Populate GameObjs goh.GameObjs = JsonUtility.FromJson <GameObjects>(response.GetSuccess()); } else { throw new InvalidDataException(response.GetError().error); } }).GetAwaiter().GetResult(); return(goh); }