Пример #1
0
    // This method tests Enjin's non-runtime API methods mostly used in the editor window.
    private void TestStaticEndpoints()
    {
        // Helper methods.
        TestMethod(() => { Enjin.StoreUserData(new User(), "test"); }, "user data storage");
        TestMethod <Boolean>(() => { return(Enjin.ValidateAddress("0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c")); }, true, "address validation");
        TestMethod(() => { Enjin.URLGetData("https://enjincoin.io/", new System.Collections.Generic.Dictionary <string, string>()); }, "fetching URL data");
        TestMethod <String>(() => { return(Enjin.URLGetData("bad URL", new System.Collections.Generic.Dictionary <string, string>())); }, string.Empty, "expected result from bad URL data");
        TestMethod(() => { Enjin.ResetErrorReport(); }, "error report reset");


        // CryptoItems methods.
        TestMethod(() => { Enjin.GetCryptoItemBalance(testingIdentityID, TESTING_ITEM_ID); }, "balance by identity");
        TestMethod(() => { Enjin.GetMintableItems(TESTING_ITEM_ID); }, "mintable item retrieval");
        TestMethod(() => {
            CryptoItem item = Enjin.GetCryptoItem(TESTING_ITEM_ID);
            Enjin.GetCryptoItemIDByName(item.name);
        }, "item identity by name");
        TestMethod(() => { Enjin.GetCryptoItemBalances(testingIdentityID); }, "all balances by identity");
        TestMethod(() => { Enjin.UpdateCryptoItem(new CryptoItem()); }, "item updating");
        TestMethod(() => { Enjin.GetAllCryptoItems(); }, "searching all items");
        TestMethod(() => {
            CryptoItem item = Enjin.GetCryptoItem(TESTING_ITEM_ID);
            Enjin.GetCryptoItemIDByName(item.name);
        }, "searching for item name");
        TestMethod(() => { Enjin.GetAllItems(0, 0, DEVELOPER_IDENTITY_ID); }, "getting all items by page");
        TestMethod(() => { Enjin.GetAllItems(DEVELOPER_IDENTITY_ID); }, "getting all items");

        // Enjin Platform API methods.
        TestMethod(() => { Enjin.GetTotalActiveTokens(DEVELOPER_IDENTITY_ID); }, "getting all active tokens");
        TestMethod(() => { Enjin.GetAppsByUserID(loginUser.id); }, "getting apps for user");
        TestMethod(() => { Enjin.GetAppByID(APP_ID); }, "getting app by id");

        // Identity methods.
        TestMethod(() => { Enjin.UpdateBalances(new Identity()); }, "identity balance updates");
        TestMethod(() => { Enjin.GetIdentity(testingIdentityID); }, "identity retrieval");
        TestMethod(() => { Enjin.GetAllIdentities(); }, "bulk identity retrieval");
        TestMethod(() => { Enjin.SearchIdentities("enjin"); }, "identity search");
        Identity sampleIdentity = new Identity
        {
            user = new Identity.User
            {
                name = loginUser.name,
                id   = loginUser.id
            },
            id     = testingIdentityID,
            fields = new Fields[] { new Fields("test", "enjin", 0, 0, 0) }
        };

        TestMethod(() => { Enjin.UpdateIdentity(sampleIdentity); }, "identity update");
        Enjin.AccessToken = TESTER_TOKEN;
        TestMethod(() => { Enjin.UpdateIdentityFields(testingIdentityID, new Fields[] { new Fields("test", "enjin!", 0, 0, 0) }); }, "identity field update");
        TestMethod(() => { Enjin.LinkIdentity(sampleIdentity); }, "identity link");
        TestMethod(() => { Enjin.UnLinkIdentity(testingIdentityID); }, "identity unlinking");
        TestMethod(() => { Enjin.DeleteIdentity(testingIdentityID + ""); }, "identity deletion");
        TestMethod(() => { Enjin.CreateIdentity(sampleIdentity); }, "identity creation");
        TestMethod(() => { Enjin.GetRoles(); }, "fetching identity roles");
        TestMethod(() => { Enjin.GetIdentities(0, 0); }, "fetching identity pages");
    }
    /// <summary>
    /// Placeholder for request handling and passing results to a watch action/event to prompt for pop-up notifications
    /// </summary>
    /// <param name="task"></param>
    /// <param name="identity"></param>
    /// <param name="properties"></param>
    /// <returns></returns>
    internal Identity ProcessRequest(ProcessTasks task, Identity identity, Dictionary <string, object> properties)
    {
        Identity retv = null;

        switch (task)
        {
        case ProcessTasks.VIEW:
            break;

        case ProcessTasks.CREATE:
            retv = Enjin.CreateIdentity(identity);
            if (retv != null)
            {
                EditorUtility.DisplayDialog("SUCCESS", "Identity " + retv.id + " has been created for app id " + retv.app_id + ".", "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog("FAILURE", "Identity " + retv.id + " could not be created. Please see the Unity Console for the error returned.", "Ok");
            }

            RefreshLists();
            State = IdentityState.VIEW;
            break;

        case ProcessTasks.DELETE:
            break;

        case ProcessTasks.EDIT:
            if (CurrentIdentity.linking_code != "")
            {
                retv = Enjin.UpdateIdentity(CurrentIdentity);
            }
            else
            {
                retv = Enjin.UpdateIdentityFields(CurrentIdentity.id, CurrentIdentity.fields);
            }

            if (retv != null)
            {
                EditorUtility.DisplayDialog("SUCCESS", "Identity " + retv.id + " was updated successfully.", "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog("FAILURE", "Identity " + retv.id + " could not be updated. Please see the Unity Console for the error returned.", "Ok");
            }

            RefreshLists();
            State = IdentityState.VIEW;
            break;
        }

        return(retv);
    }