--- /dev/null
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.agent;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetInstallPackageActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import org.jmock.Expectations;\r
+import org.jmock.Mockery;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.Collections;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 08.07.11 1:36\r
+ */\r
+public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {\r
+ private Mockery m;\r
+ private CommandlineBuildProcessFactory myProcessFactory;\r
+ private NuGetInstallPackageActionFactoryImpl i;\r
+ private BuildRunnerContext ctx;\r
+ private PackagesInstallParameters ps;\r
+ private File myTarget;\r
+ private File myConfig;\r
+\r
+ @BeforeMethod\r
+ @Override\r
+ protected void setUp() throws Exception {\r
+ super.setUp();\r
+ m = new Mockery();\r
+ myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
+ i = new NuGetInstallPackageActionFactoryImpl(myProcessFactory);\r
+ ctx = m.mock(BuildRunnerContext.class);\r
+ ps = m.mock(PackagesInstallParameters.class);\r
+\r
+ myTarget = createTempDir();\r
+ myConfig = createTempFile();\r
+ }\r
+\r
+ @Test\r
+ public void test_no_sources() throws RunBuildException, IOException {\r
+ final File nuget = createTempFile();\r
+ m.checking(new Expectations(){{\r
+ allowing(ps).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));\r
+ allowing(ps).getNuGetExeFile(); will(returnValue(nuget));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath()),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createBuildProcess(ctx, ps, myConfig, myTarget);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_sources() throws RunBuildException, IOException {\r
+ final File nuget = createTempFile();\r
+ m.checking(new Expectations(){{\r
+ allowing(ps).getNuGetPackageSources(); will(returnValue(Arrays.asList("aaa", "bbb")));\r
+ allowing(ps).getNuGetExeFile(); will(returnValue(nuget));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(\r
+ ctx,\r
+ nuget,\r
+ Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),\r
+ myConfig.getParentFile()\r
+ );\r
+ }});\r
+\r
+ i.createBuildProcess(ctx, ps, myConfig, myTarget);\r
+ m.assertIsSatisfied();\r
+ }\r
+}\r