2018-03-27 20:26:55 -07:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Linq ;
using FluentAssertions ;
using Microsoft.DotNet.Cli ;
using Microsoft.DotNet.Cli.CommandLine ;
using Xunit ;
using Xunit.Abstractions ;
using Parser = Microsoft . DotNet . Cli . Parser ;
namespace Microsoft.DotNet.Tests.ParserTests
{
public class BuildServerShutdownParserTests
{
private readonly ITestOutputHelper output ;
public BuildServerShutdownParserTests ( ITestOutputHelper output )
{
this . output = output ;
}
[Fact]
public void GivenNoOptionsAllFlagsAreFalse ( )
{
2018-04-17 17:04:12 -07:00
var result = Parser . Instance . Parse ( "dotnet build-server shutdown" ) ;
2018-03-27 20:26:55 -07:00
2018-04-17 17:04:12 -07:00
var options = result [ "dotnet" ] [ "build-server" ] [ "shutdown" ] ;
2018-03-27 20:26:55 -07:00
options . ValueOrDefault < bool > ( "msbuild" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "vbcscompiler" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "razor" ) . Should ( ) . Be ( false ) ;
}
[Fact]
public void GivenMSBuildOptionIsItTrue ( )
{
2018-04-17 17:04:12 -07:00
var result = Parser . Instance . Parse ( "dotnet build-server shutdown --msbuild" ) ;
2018-03-27 20:26:55 -07:00
2018-04-17 17:04:12 -07:00
var options = result [ "dotnet" ] [ "build-server" ] [ "shutdown" ] ;
2018-03-27 20:26:55 -07:00
options . ValueOrDefault < bool > ( "msbuild" ) . Should ( ) . Be ( true ) ;
options . ValueOrDefault < bool > ( "vbcscompiler" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "razor" ) . Should ( ) . Be ( false ) ;
}
[Fact]
public void GivenVBCSCompilerOptionIsItTrue ( )
{
2018-04-17 17:04:12 -07:00
var result = Parser . Instance . Parse ( "dotnet build-server shutdown --vbcscompiler" ) ;
2018-03-27 20:26:55 -07:00
2018-04-17 17:04:12 -07:00
var options = result [ "dotnet" ] [ "build-server" ] [ "shutdown" ] ;
2018-03-27 20:26:55 -07:00
options . ValueOrDefault < bool > ( "msbuild" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "vbcscompiler" ) . Should ( ) . Be ( true ) ;
options . ValueOrDefault < bool > ( "razor" ) . Should ( ) . Be ( false ) ;
}
[Fact]
public void GivenRazorOptionIsItTrue ( )
{
2018-04-17 17:04:12 -07:00
var result = Parser . Instance . Parse ( "dotnet build-server shutdown --razor" ) ;
2018-03-27 20:26:55 -07:00
2018-04-17 17:04:12 -07:00
var options = result [ "dotnet" ] [ "build-server" ] [ "shutdown" ] ;
2018-03-27 20:26:55 -07:00
options . ValueOrDefault < bool > ( "msbuild" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "vbcscompiler" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "razor" ) . Should ( ) . Be ( true ) ;
}
[Fact]
public void GivenMultipleOptionsThoseAreTrue ( )
{
2018-04-17 17:04:12 -07:00
var result = Parser . Instance . Parse ( "dotnet build-server shutdown --razor --msbuild" ) ;
2018-03-27 20:26:55 -07:00
2018-04-17 17:04:12 -07:00
var options = result [ "dotnet" ] [ "build-server" ] [ "shutdown" ] ;
2018-03-27 20:26:55 -07:00
options . ValueOrDefault < bool > ( "msbuild" ) . Should ( ) . Be ( true ) ;
options . ValueOrDefault < bool > ( "vbcscompiler" ) . Should ( ) . Be ( false ) ;
options . ValueOrDefault < bool > ( "razor" ) . Should ( ) . Be ( true ) ;
}
}
}