package com.jetbrains.env.python.dotNet;

import com.jetbrains.env.python.debug.PyEnvTestCase;
import com.jetbrains.python.psi.PyFile;
import org.junit.Assert;

/**
 * IronPython.NET specific tests
 *
 * @author Ilya.Kazakevich
 */
public class PyIronPythonTest extends PyEnvTestCase {

  /**
   * IronPython tag
   */
  static final String IRON_TAG = "iron";

  public PyIronPythonTest() {
    super(IRON_TAG);
  }

  /**
   * Tests skeleton generation
   */
  public void testSkeletons() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "testSkeleton.py",
      null
    ));
  }

  /**
   * Tests skeleton generation with "from" statements
   */
  public void testClassFromModule() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_class_from_module.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when imported as alias
   */
  public void testClassFromModuleAlias() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_class_from_module_alias.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when module is imported
   */
  public void testModuleFromPackage() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_module_from_package.py",
      null
    ));
  }

  /**
   * Tests skeleton generation when several classes are imported
   */
  public void testSeveralClasses() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.java.py",
      "com.just.like.java",
      "import_several_classes_from_module.py",
      "com.just.like.java.LikeJavaClass"
    ));
  }

  /**
   * Tests skeletons for built-in classes. We can't compare files (CLR class may be changed from version to version),
   * but we are sure there should be class System.Web.AspNetHostingPermissionLevel which is part of public API
   */
  public void testImportBuiltInSystem() throws Exception {
    final SkeletonTestTask task = new SkeletonTestTask(
      null,
      "System.Web",
      "import_system.py",
      null
    );
    runPythonTest(task);
    final PyFile skeleton = task.getGeneratedSkeleton();
    Assert.assertNotNull("System.Web does not contain class AspNetHostingPermissionLevel. Error generating stub? It has classes  " +
                         skeleton.getTopLevelClasses(),
                         skeleton.findTopLevelClass("AspNetHostingPermissionLevel"));
  }

  /**
   * Test importing of inner classes
   */
  public void testImportInnerClass() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.Deep.py",
      "SingleNameSpace.Some.Deep",
      "inner_class.py",
      null
    ));
  }

  /**
   * Test importing of the whole namespace
   */
  public void testWholeNameSpace() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.SingleNameSpace.py",
      "SingleNameSpace",
      "whole_namespace.py",
      null
    ));
  }

  /**
   * Test importing of single class
   */
  public void testSingleClass() throws Exception {
    runPythonTest(new SkeletonTestTask(
      "dotNet/expected.skeleton.SingleNameSpace.py",
      "SingleNameSpace",
      "single_class.py",
      null
    ));
  }
}

@@ -35,16 +35,116 @@
 otNet;%0A%0A
+import com.intellij.openapi.application.ReadAction;%0Aimport com.intellij.openapi.application.Result;%0A
 import c
@@ -228,16 +228,58 @@
 PyFile;%0A
+import org.jetbrains.annotations.NotNull;%0A
 import o
@@ -2551,16 +2551,127 @@
 eton();%0A
+    new ReadAction() %7B%0A      @Override%0A      protected void run(@NotNull Result result) throws Throwable %7B%0A    
     Asse
@@ -2812,32 +2812,36 @@
                 
+    
 skeleton.getTopL
@@ -2855,16 +2855,20 @@
 sses(),%0A
+    
         
@@ -2941,24 +2941,50 @@
 onLevel%22));%0A
+      %7D%0A    %7D.execute();%0A%0A
   %7D%0A%0A  /**%0A 

Read action.