Esempio n. 1
0
    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));
    }
Esempio n. 2
0
    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());
    }
Esempio n. 3
0
    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();
    }
Esempio n. 4
0
    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();
    }
Esempio n. 5
0
    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());
    }
    void Start()
    {
        maxUsernameLength = 16;
        api = BlueprintAPI.WithBaseUrl("http://smithwjv.ddns.net");

        GameObject errorObject = GameObject.Find("InfoMessage");

        infoMessage       = errorObject.GetComponent <Text>();
        infoMessage.color = Color.blue;
        infoMessage.text  = "";
        usernameLoginInput.Select();
    }
Esempio n. 7
0
    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()));
    }
Esempio n. 8
0
        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());
                }
            }
        }
Esempio n. 9
0
    public void TestRegisterUserNoLowercasePassword()
    {
        var    blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl);
        Random random       = new Random();
        string username     = "******" + random.Next(10000);

        Task.Run(async() => {
            try {
                Task <APIResult <UserCredentials, JsonError> > fetchingResponse =
                    blueprintApi.AsyncRegisterUser(username, "FAILURE123");
                APIResult <UserCredentials, JsonError> response = await fetchingResponse;

                // Failure case
                // If here, exception has not been thrown
                Assert.Fail();
            } catch (InvalidCredentialException e) {
                // Pass case
                // Exception correctly thrown
            }
        }).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);
    }
Esempio n. 11
0
    public void TestInvalidAuthenticateUser()
    {
        var             blueprintApi = BlueprintAPI.WithBaseUrl(baseUrl);
        UserCredentials user         = new UserCredentials("test_invalid", "Invalid123");

        Task.Run(async() => {
            Task <APIResult <UserCredentials, JsonError> > fetchingResponse = blueprintApi.AsyncAuthenticateUser(user);

            APIResult <UserCredentials, JsonError> response = await fetchingResponse;

            if (!response.isSuccess())
            {
                // Error case
                JsonError error = response.GetError();

                Assert.That(error.error, Is.EqualTo("The credentials provided do not match any user"));
            }
            else
            {
                Assert.Fail();
            }
        }).GetAwaiter().GetResult();
    }