ParserTest.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » RadioImport » Test » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » RadioImport » Test » ParserTest.cs
using System;
using NUnit.Framework;
using RJH.CommandLineHelper;



namespace RJH.CommandLineHelper.Test{
  /// <summary>
  /// Summary description for ParserTest.
  /// </summary>
  [TestFixture]
  public class ParserTest
  {
    [SetUp]
    public void SetUpForTests()
    {
      // This method will be run each and every time a test method is run.
      // Place common initialization steps here that should be run before
      // every test.
    }

    [TearDown]
    public void TearDownTests()
    {
      // This method will be run each and every time a test method is run.
      // Place common cleanup steps here that should be run after
      // every test.
    }

    [Test]
    public void ParseStringWithoutQuotesAndParams()
    {
      Parser parser = new Parser( "Jee.exe", this);
      parser.Parse();
      Assert.AreEqual("Jee.exe",parser.ApplicationName);
      Assert.AreEqual(0,parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithoutQuotesAndOneParam()
    {
      Parser parser = new Parser( "Jee.exe test", this);
      parser.Parse();
      Assert.AreEqual("Jee.exe",parser.ApplicationName);
      Assert.AreEqual(1, parser.Parameters.Length );
    }

    [Test]
    public void ParseStringWithoutQuotesAndTwoParams()
    {
      Parser parser = new Parser( "Jee.exe test1 test2", this);
      parser.Parse();
      Assert.AreEqual("Jee.exe",parser.ApplicationName);
      Assert.AreEqual(2,parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithoutQuotesAndParamWithQuotes()
    {
      Parser parser = new Parser( "Jee.exe test3 \'test1 test2\' test4", this);
      parser.Parse();
      Assert.AreEqual("Jee.exe",parser.ApplicationName);
      Assert.AreEqual(3,parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithQuotesAndOneParam()
    {
      Parser parser = new Parser( "'C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe' test", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe", parser.ApplicationName);
      Assert.AreEqual(1,parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithQuotesAndTwoParams()
    {
      Parser parser = new Parser( "'C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe' test1 test2", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual( 2, parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithQuotesAndParamWithQuote()
    {
      Parser parser = new Parser( "'C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe' 'test1 test2'", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual( 1, parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithDoubleQuotesAndParamWithQuote()
    {
      Parser parser = new Parser( "\"C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe\" 'test1 test2'", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual( 1, parser.Parameters.Length);
    }

    [Test]
    public void ParseStringWithDoubleQuotesAndParamWithDoubleQuotes()
    {
      Parser parser = new Parser( "\"C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe\" \"test1 test2\"", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual( 1, parser.Parameters.Length);
    }

    [Test]
    public void QuotesTest1()
    {
      Parser parser = new Parser( "\"C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe\" /p\"test1\" /a'test2'", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual(2, parser.Parameters.Length);
    }

    [Test]
    public void QuotesTest2()
    {
      Parser parser = new Parser( "'C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe' /p'test1' /a'test2'", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual(2, parser.Parameters.Length);
    }

    [Test]
    public void QuotesTest3()
    {
      Parser parser = new Parser( "\"C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe\" /p \"test1\" /a \"test2\"", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual(4, parser.Parameters.Length);
    }

    [Test]
    public void QuotesTest4()
    {
      Parser parser = new Parser( "\"C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe\" /p:\"test1\" /a:\"test2\"", this);
      parser.Parse();
      Assert.AreEqual("C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe",parser.ApplicationName);
      Assert.AreEqual(2, parser.Parameters.Length);
    }

    [Test]
    public void AutoLoadWithQuotes()
    {
      CommandLine commandLine = new CommandLine();
      Parser parser = new Parser("DummyProgram.exe /SourceDir:\"c:\\Program Files\"", commandLine);
      parser.Parse();
      Assert.AreEqual("c:\\Program Files", commandLine.SourceDirectory, "The source parameter is not correct.");
    }

    [Test]
    public void GetHelpText()
    {
      string expectedText =
        "DummyProgramName.exe [/SourceType:Radio] [/{ContentDir|to}] [/{SourceDir|from}] [/Help] \n\n" +
        "  /SourceType       -Specify the blog program from which to import content.\n" +
        "  /ContentDir       -The DasBlog content directory into which the entries are placed.\n" +
        "                              Aliases: to\n" +
        "  /SourceDir        -The source directory from which content will be imported.\n" +
        "                              Aliases: from\n" +
        "  /Help             -Displays the command line help.\n";

      CommandLine commandLine= new CommandLine();
      Parser parser = new Parser("DummyProgramName.exe /Help", commandLine);      
      parser.Parse();
      Console.WriteLine("Actual:\n" + parser.GetHelpText());
      Console.WriteLine("\nExpected:\n" + expectedText);

      Assert.IsTrue(commandLine.Help, "The CommandLine was unexpectedly not set to true when using the '/Help' parameters.");

      Assert.AreEqual(
        expectedText,
        parser.GetHelpText(),
        "The help text returned was not as expected.");
    }

    // [Test, ExpectedException(typeof(System.ApplicationException)), Ignore("Not yet supported")]
    public void InvalidEnumSpecified()
    {
      CommandLine commandLine= new CommandLine();
      Parser parser = new Parser("DummyProgramName.exe /Source:InvalidSource", commandLine);
      parser.Parse();
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.