コード例 #1
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();
    }
コード例 #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());
    }
コード例 #3
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));
    }
コード例 #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();
    }
コード例 #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());
    }
コード例 #6
0
    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();
    }
コード例 #7
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();
    }
コード例 #8
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();
    }