public void WillCreatePackageUsingSpecFileAndWorkingDirectory() { var packageStreamStub = new Mock <Stream>(); var packageBuilderStub = new Mock <IPackageBuilder>(); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(packageBuilderStub: packageBuilderStub, packageStreamStub: packageStreamStub); bool actualResut = task.Execute(); packageBuilderStub.Verify(x => x.Save(packageStreamStub.Object)); Assert.IsTrue(actualResut); }
public void WillSetOutputPathWhenRun() { var packageStreamStub = new Mock <Stream>(); var packageBuilderStub = new Mock <IPackageBuilder>(); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(packageBuilderStub: packageBuilderStub, packageStreamStub: packageStreamStub); bool actualResut = task.Execute(); string packagePath = task.OutputPackage; packageBuilderStub.Verify(x => x.Save(packageStreamStub.Object)); Assert.AreEqual(createdPackage, packagePath); }
public void WillLogMessagesBeforeAndAfterPackageCreation() { Queue <string> actualMessages = new Queue <string>(); var buildEngineStub = new Mock <IBuildEngine>(); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(buildEngineStub: buildEngineStub); buildEngineStub .Setup(x => x.LogMessageEvent(It.IsAny <BuildMessageEventArgs>())) .Callback <BuildMessageEventArgs>(e => actualMessages.Enqueue(e.Message)); task.Execute(); Assert.AreEqual("Creating a package for at .", actualMessages.Dequeue()); Assert.AreEqual("Created a package for at .", actualMessages.Dequeue()); }
public void WillRemoveNuspecFilesFromPackage() { var packageBuilderStub = new Mock <IPackageBuilder>(); var packageFileStub = new Mock <IPackageFile>(); packageFileStub.Setup(x => x.Path).Returns("/aFile.nuspec"); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(packageBuilderStub: packageBuilderStub); packageBuilderStub.Setup(x => x.Files).Returns(new Collection <IPackageFile>() { packageFileStub.Object }); bool actualResut = task.Execute(); Assert.AreEqual(0, packageBuilderStub.Object.Files.Count); }
public void WillLogAnErrorWhenAnUnexpectedErrorHappens() { string actualMessage = null; var packageBuilderStub = new Mock <IPackageBuilder>(); var buildEngineStub = new Mock <IBuildEngine>(); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(packageBuilderStub: packageBuilderStub, buildEngineStub: buildEngineStub); packageBuilderStub.Setup(x => x.Save(It.IsAny <Stream>())).Throws(new Exception()); buildEngineStub .Setup(x => x.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(e => actualMessage = e.Message); bool actualResut = task.Execute(); Assert.IsTrue(actualMessage.Contains("An unexpected error occurred while creating the package:")); Assert.IsFalse(actualResut); }
public void WillErrorWhenTheSpecFileDoesNotExist() { string actualMessage = null; var fileSystemStub = new Mock <IExtendedFileSystem>(); var buildEngineStub = new Mock <IBuildEngine>(); NuGet.MSBuild.NuGet task = CreateTaskWithDefaultStubs(fileSystemStub: fileSystemStub, buildEngineStub: buildEngineStub); buildEngineStub .Setup(x => x.LogErrorEvent(It.IsAny <BuildErrorEventArgs>())) .Callback <BuildErrorEventArgs>(e => actualMessage = e.Message); fileSystemStub .Setup(x => x.FileExists(It.IsAny <string>())) .Returns(false); task.SpecFile = "aPathThatDoesNotExist"; bool actualResut = task.Execute(); Assert.AreEqual("The spec file does not exist.", actualMessage); Assert.IsFalse(actualResut); }