|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using Cake.Common.Tests.Fixtures.Tools.DotNet.Package.Remove; |
| 6 | +using Cake.Common.Tools.DotNet; |
| 7 | +using Cake.Testing; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.Remove |
| 11 | +{ |
| 12 | + public sealed class DotNetPackageRemoverTests |
| 13 | + { |
| 14 | + public sealed class TheRemoveMethod |
| 15 | + { |
| 16 | + [Fact] |
| 17 | + public void Should_Throw_If_Process_Was_Not_Started() |
| 18 | + { |
| 19 | + // Given |
| 20 | + var fixture = new DotNetPackageRemoverFixture(); |
| 21 | + fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; |
| 22 | + fixture.GivenProcessCannotStart(); |
| 23 | + |
| 24 | + // When |
| 25 | + var result = Record.Exception(() => fixture.Run()); |
| 26 | + |
| 27 | + // Then |
| 28 | + AssertEx.IsCakeException(result, ".NET CLI: Process was not started."); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code() |
| 33 | + { |
| 34 | + // Given |
| 35 | + var fixture = new DotNetPackageRemoverFixture(); |
| 36 | + fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; |
| 37 | + fixture.GivenProcessExitsWithCode(1); |
| 38 | + |
| 39 | + // When |
| 40 | + var result = Record.Exception(() => fixture.Run()); |
| 41 | + |
| 42 | + // Then |
| 43 | + AssertEx.IsCakeException(result, ".NET CLI: Process returned an error (exit code 1)."); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void Should_Throw_If_PackageName_Is_Null() |
| 48 | + { |
| 49 | + // Given |
| 50 | + var fixture = new DotNetPackageRemoverFixture(); |
| 51 | + fixture.PackageName = null; |
| 52 | + fixture.GivenDefaultToolDoNotExist(); |
| 53 | + |
| 54 | + // When |
| 55 | + var result = Record.Exception(() => fixture.Run()); |
| 56 | + |
| 57 | + // Then |
| 58 | + AssertEx.IsArgumentNullException(result, "packageName"); |
| 59 | + } |
| 60 | + |
| 61 | + [Fact] |
| 62 | + public void Should_Add_Project_Argument() |
| 63 | + { |
| 64 | + // Given |
| 65 | + var fixture = new DotNetPackageRemoverFixture(); |
| 66 | + fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; |
| 67 | + fixture.Project = "ToDo.csproj"; |
| 68 | + |
| 69 | + // When |
| 70 | + var result = fixture.Run(); |
| 71 | + |
| 72 | + // Then |
| 73 | + Assert.Equal("remove \"ToDo.csproj\" package Microsoft.AspNetCore.StaticFiles", result.Args); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments