Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement testing framework with basic tests #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

12 changes: 3 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ apply {
plugin("com.jetbrains.rdgen")
}

dependencies {
testImplementation("org.testng:testng:7.7.0")
}

val riderPluginId: String by project
val dotnetPluginId: String by project
val productVersion: String by project
Expand Down Expand Up @@ -142,7 +138,7 @@ intellij {

tasks {
wrapper {
gradleVersion = "8.2.1"
gradleVersion = "8.3"
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
Expand Down Expand Up @@ -228,8 +224,6 @@ tasks {
}

patchPluginXml {
sinceBuild.set("233.0")
untilBuild.set("233.*")
val latestChangelog = try {
changelog.getUnreleased()
} catch (_: MissingVersionException) {
Expand All @@ -256,8 +250,8 @@ tasks {

runIde {
// For statistics:
jvmArgs("-Xmx1500m", "-Didea.is.internal=true", "-Dfus.internal.test.mode=true")
// jvmArgs("-Xmx1500m")
// jvmArgs("-Xmx1500m", "-Didea.is.internal=true", "-Dfus.internal.test.mode=true")
jvmArgs("-Xmx1500m")
}

test {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-8.2.1-all.zip
distributionUrl=https\://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-8.3-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.rider.plugins.efcore.EfCoreUiBundle
import com.jetbrains.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import com.jetbrains.rider.plugins.efcore.cli.execution.CliCommand
import com.jetbrains.rider.plugins.efcore.cli.execution.CliCommandPresentationInfo

Expand All @@ -13,16 +14,32 @@ class ManagementCommandFactory(private val intellijProject: Project) {
fun getInstance(project: Project) = project.service<ManagementCommandFactory>()
}

fun installEfCoreTools(): CliCommand {
fun installGlobalTools(version: DotnetEfVersion? = null): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("install.dotnet.tool.presentable.name"),
EfCoreUiBundle.message("install.global.dotnet.tool.presentable.name"),
EfCoreUiBundle.message("ef.core.global.tools.have.been.successfully.installed"))

return DotnetCliCommandBuilder(presentation, intellijProject, "tool", "install").apply {
add("--ignore-failed-sources")
addNamed("--add-source", "https://api.nuget.org/v3/index.json")
return prepareToolInstallCommand(presentation).apply {
add("--global")
add("dotnet-ef")
}.build()
}

fun installLocalTools(version: DotnetEfVersion? = null): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("install.local.dotnet.tool.presentable.name"),
EfCoreUiBundle.message("ef.core.local.tools.have.been.successfully.installed"))

return prepareToolInstallCommand(presentation).apply {
add("dotnet-ef")
addNamedNullable("--version", version.toString())
}.build()
}

private fun prepareToolInstallCommand(presentation: CliCommandPresentationInfo) =
DotnetCliCommandBuilder(presentation, intellijProject, "tool", "install").apply {
add("--ignore-failed-sources")
add("--create-manifest-if-needed")
addNamed("--add-source", "https://api.nuget.org/v3/index.json")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.jetbrains.rider.plugins.efcore.cli.execution

import com.intellij.execution.configurations.GeneralCommandLine

open class CliCommand(
data class CliCommand(
val dotnetPath: String,
val commandLine: GeneralCommandLine,
val presentationInfo: CliCommandPresentationInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InstallDotnetEfAction : AnAction(EfCoreUiBundle.message("action.install.te
override fun actionPerformed(actionEvent: AnActionEvent) {
val project = actionEvent.project ?: return
val executor = PreferredCommandExecutorProvider.getInstance(project).getExecutor()
val command = ManagementCommandFactory.getInstance(project).installEfCoreTools()
val command = ManagementCommandFactory.getInstance(project).installGlobalTools()
project.lifetime.launchBackground {
executor.execute(command)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetbrains.rider.plugins.efcore.features.migrations.add

import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.ui.components.JBTextField
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.Panel
Expand All @@ -17,6 +18,7 @@ import com.jetbrains.rider.plugins.efcore.features.shared.dialog.DialogCommand
import com.jetbrains.rider.plugins.efcore.ui.AnyInputDocumentListener
import com.jetbrains.rider.plugins.efcore.ui.textFieldForRelativeFolder
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.TestOnly
import java.io.File
import java.util.*

Expand All @@ -31,8 +33,6 @@ class AddMigrationDialogWrapper(
intellijProject,
selectedProjectId
) {
private val migrationsCommandFactory by lazy { MigrationsCommandFactory.getInstance(intellijProject) }

//
// Internal data
private val migrationProjectFolder = observable("").withLogger("migrationProjectFolder")
Expand All @@ -43,6 +43,12 @@ class AddMigrationDialogWrapper(
// Validation
private val validator = AddMigrationValidator(dataCtx)

@TestOnly
internal var migrationNameComponent: JBTextField? = null

@TestOnly
internal var migrationsFolderComponent: TextFieldWithBrowseButton? = null

//
// Constructor
init {
Expand Down Expand Up @@ -80,6 +86,7 @@ class AddMigrationDialogWrapper(
.focused()
.applyToComponent {
setupInitialMigrationNameListener(this)
migrationNameComponent = this
}
}
}
Expand All @@ -93,6 +100,7 @@ class AddMigrationDialogWrapper(
.validationOnInput(validator.migrationsOutputFolderValidation())
.validationOnApply(validator.migrationsOutputFolderValidation())
.applyToComponent {
migrationsFolderComponent = this
dataCtx.migrationsProject.afterChange { isEnabled = it != null }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jetbrains.rider.plugins.efcore.features.shared.dialog

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.dsl.builder.AlignX
Expand Down Expand Up @@ -29,6 +30,7 @@ import com.jetbrains.rider.plugins.efcore.ui.items.*
import com.jetbrains.rider.plugins.efcore.ui.localize
import com.jetbrains.rider.plugins.efcore.ui.simpleExpandableTextField
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.TestOnly
import java.awt.event.ActionEvent
import java.util.*
import javax.swing.AbstractAction
Expand All @@ -37,8 +39,8 @@ import javax.swing.JComponent

@Suppress("MemberVisibilityCanBePrivate")
abstract class CommonDialogWrapper<TContext : CommonDataContext>(
protected val dataCtx: TContext,
protected val efCoreVersion: DotnetEfVersion,
val dataCtx: TContext,
val efCoreVersion: DotnetEfVersion,
dialogTitle: String,
protected val intellijProject: Project,
private val selectedProjectId: UUID?,
Expand Down Expand Up @@ -79,6 +81,22 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
// UI
protected lateinit var panel: DialogPanel

@TestOnly
internal var migrationsProjectComponent: ComboBox<MigrationsProjectItem>? = null

@TestOnly
internal var startupProjectComponent: ComboBox<StartupProjectItem>? = null

@TestOnly
internal var dbContextComponent: ComboBox<DbContextItem>? = null

@TestOnly
internal var targetFrameworkComponent: ComboBox<BaseTargetFrameworkItem>? = null

@TestOnly
internal var buildConfigurationComponent: ComboBox<BuildConfigurationItem>? = null


//
// Constructor
init {
Expand Down Expand Up @@ -231,6 +249,11 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
}
}

@TestOnly
internal fun requestPanel(): DialogPanel {
return panel
}

//
// UI
override fun createCenterPanel(): JComponent =
Expand Down Expand Up @@ -283,6 +306,7 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
iconComboBox(migrationsProjectView, availableMigrationsProjectsView)
.validationOnInput(validator.migrationsProjectValidation())
.validationOnApply(validator.migrationsProjectValidation())
.applyToComponent { migrationsProjectComponent = this }
}
}

Expand All @@ -292,6 +316,7 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
.validationOnInput(validator.startupProjectValidation())
.validationOnApply(validator.startupProjectValidation())
.comment(EfCoreUiBundle.message("startup.project.missing.comment"))
.applyToComponent { startupProjectComponent = this }
}
}

Expand All @@ -300,6 +325,7 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
iconComboBox(dbContextView, availableDbContextsView)
.validationOnInput(validator.dbContextValidation())
.validationOnApply(validator.dbContextValidation())
.applyToComponent { dbContextComponent = this }
}
}

Expand All @@ -320,12 +346,14 @@ abstract class CommonDialogWrapper<TContext : CommonDataContext>(
iconComboBox(buildConfigurationView, availableBuildConfigurationView)
.validationOnInput(validator.buildConfigurationValidation())
.validationOnApply(validator.buildConfigurationValidation())
.applyToComponent { buildConfigurationComponent = this }
}.enabledIf(noBuildCheck!!.selected.not())

row(EfCoreUiBundle.message("target.framework")) {
iconComboBox(targetFrameworksView, availableTargetFrameworksView)
.validationOnInput(validator.targetFrameworkValidation())
.validationOnInput(validator.targetFrameworkValidation())
.applyToComponent { targetFrameworkComponent = this }
}.enabledIf(noBuildCheck!!.selected.not())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jetbrains.rider.plugins.efcore.ui

import javax.swing.ComboBoxModel

val <T> ComboBoxModel<T>.elements: List<T> get() {
return buildList {
for (i in 0 until getSize()) {
add(getElementAt(i))
}
}
}
4 changes: 3 additions & 1 deletion src/rider/main/resources/messages/EfCoreUiBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ tab.ef.core.command=EF Core Command
#
# Install EF Core tools
action.install.text=Install
install.global.dotnet.tool.presentable.name=Install .NET Tool
install.local.dotnet.tool.presentable.name=Install .NET Tool (Local)
ef.core.global.tools.have.been.successfully.installed=EF Core global tools have been successfully installed
ef.core.local.tools.have.been.successfully.installed=EF Core local tools have been successfully installed
progress.title.getting.dotnet.ef.version=Getting dotnet-ef version\u2026
notification.content.ef.core.tools.are.required.to.execute.this.action=To use EF Core in the IDE, install dotnet-ef as a global tool
notification.content.invalid.ef.core.tools.version=Unable to find available EF Core tools
Expand Down Expand Up @@ -188,4 +191,3 @@ default.target.framework=<Default>
tool.kind.none=None
tool.kind.local=Local
tool.kind.global=Global
install.dotnet.tool.presentable.name=Install .NET Tool
Loading
Loading