﻿#if !NETFX_CORE
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using UnityEngine.SceneManagement;
using I2.Loc;
using UnityEngine.UI;
using System;
#pragma warning disable 618


public partial class I2Loc_PlayTest_Targets
{
    [TearDown]
    public void CleanUp()
    {
        TestLogger.Disable();
    }

    [UnityTest, Category("Targets")]
    public IEnumerator I2LocTest_StandardComponents()
    {
        SceneManager.LoadScene("I2Localization    Standard Components");
        yield return null;
        Assert.IsTrue(LocalizationManager.Sources.Count == (LocalizationManager.GlobalSources.Length + 1));

        var audioSource = I2Utils.FindObject("Examples/Audio Source").GetComponent<AudioSource>();
        var prefab = I2Utils.FindObject("Examples/Prefab");
        var spriteRenderer = I2Utils.FindObject("Examples/Sprite Renderer").GetComponent<SpriteRenderer>();
        var textMesh = I2Utils.FindObject("Examples/Text Mesh").GetComponent<TextMesh>();


        I2Utils.FindObject("Canvas/Buttons/Spanish").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(audioSource.isPlaying && audioSource.clip.name == "espannol");
        Assert.IsTrue(prefab.transform.Find("Mesh_ES") != null && prefab.transform.Find("Mesh_ES").gameObject.activeInHierarchy);
        Assert.IsTrue(spriteRenderer.sprite.name == "L_ES");
        Assert.IsTrue(textMesh.text == "El jugador Rojo ha ganado!");
        Assert.IsTrue(textMesh.font.name == "COMIC");

        I2Utils.FindObject("Canvas/Buttons/English").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(audioSource.isPlaying && audioSource.clip.name == "ingles");
        Assert.IsTrue(prefab.transform.Find("Mesh_US") != null && prefab.transform.Find("Mesh_US").gameObject.activeInHierarchy);
        Assert.IsTrue(spriteRenderer.sprite.name == "L_EN");
        Assert.IsTrue(textMesh.text == "Red Player Wins!");
        Assert.IsTrue(textMesh.font.name == "ARIAL");


        I2Utils.FindObject("Canvas/Buttons/French").GetComponent<Button>().onClick.Invoke();
        yield return null;

        Assert.IsTrue(audioSource.isPlaying && audioSource.clip.name == "frances");
        Assert.IsTrue(prefab.transform.Find("Mesh_FR") != null && prefab.transform.Find("Mesh_FR").gameObject.activeInHierarchy);
        Assert.IsTrue(spriteRenderer.sprite.name == "L_FR");
        Assert.IsTrue(textMesh.text == "Joueur Rouge gagne!");
        Assert.IsTrue(textMesh.font.name == "ARIAL");
    }
}

#endif