Skip to content

Commit

Permalink
WI #1150 Finalize Skeleton file Sax Parser implementation.
Browse files Browse the repository at this point in the history
This finalization includes unit tests that validate an Xml Skeleton file against its Schema.
  • Loading branch information
mayanje committed Oct 10, 2018
1 parent a81e5fe commit 4310142
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 45 deletions.
20 changes: 20 additions & 0 deletions TypeCobol.TemplateCore.Test/Properties/AssemblyInfo.cs
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("TypeCobol.TemplateCore.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TypeCobol.TemplateCore.Test")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("e9386ee6-7b3b-4823-beef-1b6521ce5319")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
68 changes: 68 additions & 0 deletions TypeCobol.TemplateCore.Test/TemplateCoreTests.cs
@@ -0,0 +1,68 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeCobol.TemplateCore.SaxParser;

namespace TypeCobol.TemplateCore.Test
{
[TestClass]
public class TemplateCoreTests
{
/// <summary>
/// Test to only validates the XML Skeleton file against the Schema.
/// </summary>
[TestMethod]
public void SkeletonFileXmlSchemaValidationTest()
{
string currentDir = System.IO.Directory.GetCurrentDirectory();
string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeletons.xml");
string xsdFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeleton.xsd");

SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile, xsdFile);
bool bValidate = parser.Validate();
Assert.IsTrue(bValidate, bValidate ? "" : parser.ValidationMessage.ToString());
}

/// <summary>
/// Test to both parse and validate on the fly the XML Skeleton file against the Schema.
/// </summary>
[TestMethod]
public void SkeletonFileXmlSaxParsingWithValidationTest()
{
string currentDir = System.IO.Directory.GetCurrentDirectory();
string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeletons.xml");
string xsdFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeleton.xsd");

SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile, xsdFile);
try
{
parser.Parse();
bool bValidate = parser.ValidationErrorCount == 0 && parser.ValidationWarningCount == 0;
Assert.IsTrue(bValidate, bValidate ? "" : parser.ValidationMessage.ToString());
}
catch(SaxParser.SaxParser.ParsingException e)
{
throw e;
}
}

/// <summary>
/// Test to only parse the XML Skeleton file without validation.
/// </summary>
[TestMethod]
public void SkeletonFileXmlSaxParsingWithoutValidationTest()
{
string currentDir = System.IO.Directory.GetCurrentDirectory();
string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeletons.xml");

SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile);
try
{
parser.Parse();
}
catch (SaxParser.SaxParser.ParsingException e)
{
throw e;
}
}
}
}
73 changes: 73 additions & 0 deletions TypeCobol.TemplateCore.Test/TypeCobol.TemplateCore.Test.csproj
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E9386EE6-7B3B-4823-BEEF-1B6521CE5319}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TypeCobol.TemplateCore.Test</RootNamespace>
<AssemblyName>TypeCobol.TemplateCore.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\TypeCobol.TemplateTranspiler\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\TypeCobol.TemplateTranspiler\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="TemplateCoreTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TypeCobol.TemplateCore\TypeCobol.TemplateCore.csproj">
<Project>{fb927d1e-c8d1-48c6-bf13-25942be5041b}</Project>
<Name>TypeCobol.TemplateCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\TypeCobol.TemplateTranspiler\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" />
</Project>
5 changes: 5 additions & 0 deletions TypeCobol.TemplateCore.Test/packages.config
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net461" />
</packages>
3 changes: 3 additions & 0 deletions TypeCobol.TemplateCore/Model/AttributeNames.cs
Expand Up @@ -11,6 +11,9 @@ namespace TypeCobol.TemplateCore.Model
/// </summary>
public static class AttributeNames
{
public static string Version = "version";
public static string Encoding = "encoding";

public static string Node = "node";
public static string Name = "name";
public static string Var = "var";
Expand Down
12 changes: 10 additions & 2 deletions TypeCobol.TemplateCore/Model/AttributedEntity.cs
Expand Up @@ -9,14 +9,22 @@ namespace TypeCobol.TemplateCore.Model
/// <summary>
/// The base class of an attributed entity: an entity which have attributes
/// </summary>
public class AttributedEntity : Dictionary<string,Attribute>
public class AttributedEntity
{
/// <summary>
/// Attributes
/// </summary>
public Dictionary<string, Attribute> Attributes
{
get;
set;
}
/// <summary>
/// Empty constructor
/// </summary>
public AttributedEntity()
{

Attributes = new Dictionary<string, Attribute>();
}
}
}
27 changes: 26 additions & 1 deletion TypeCobol.TemplateCore/Model/Conditions.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -36,7 +37,21 @@ public Conditions()
set => throw new NotImplementedException();
}

public bool IsReadOnly => throw new NotImplementedException();
public bool IsReadOnly
{
get
{
return ConditionList.IsReadOnly;
}
}

public int Count
{
get
{
return ConditionList.Count;
}
}

public void Add(Condition item)
{
Expand Down Expand Up @@ -77,5 +92,15 @@ IEnumerator<Condition> IEnumerable<Condition>.GetEnumerator()
{
return ConditionList.GetEnumerator();
}

public void Clear()
{
ConditionList.Clear();
}

public IEnumerator GetEnumerator()
{
return ConditionList.GetEnumerator();
}
}
}
27 changes: 26 additions & 1 deletion TypeCobol.TemplateCore/Model/Patterns.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -37,7 +38,21 @@ public Patterns()
set => throw new NotImplementedException();
}

public bool IsReadOnly => throw new NotImplementedException();
public bool IsReadOnly
{
get
{
return PatternList.IsReadOnly;
}
}

public int Count
{
get
{
return PatternList.Count;
}
}

public void Add(Pattern item)
{
Expand Down Expand Up @@ -78,5 +93,15 @@ IEnumerator<Pattern> IEnumerable<Pattern>.GetEnumerator()
{
return PatternList.GetEnumerator();
}

public void Clear()
{
PatternList.Clear();
}

public IEnumerator GetEnumerator()
{
return PatternList.GetEnumerator();
}
}
}
23 changes: 21 additions & 2 deletions TypeCobol.TemplateCore/Model/Skeletons.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -14,7 +15,7 @@ public class Skeletons : AttributedEntity, IList<Skeleton>
/// <summary>
/// The List of all single skeletons.
/// </summary>
public List<Skeleton> SkeletonList
public IList<Skeleton> SkeletonList
{
get;
private set;
Expand Down Expand Up @@ -71,11 +72,29 @@ IEnumerator<Skeleton> IEnumerable<Skeleton>.GetEnumerator()
return SkeletonList.GetEnumerator();
}

public void Clear()
{
SkeletonList.Clear();
}

public IEnumerator GetEnumerator()
{
return SkeletonList.GetEnumerator();
}

public bool IsReadOnly
{
get
{
return false;
return SkeletonList.IsReadOnly;
}
}

public int Count
{
get
{
return SkeletonList.Count;
}
}

Expand Down
9 changes: 9 additions & 0 deletions TypeCobol.TemplateCore/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions TypeCobol.TemplateCore/Resource.resx
Expand Up @@ -126,6 +126,9 @@
<data name="ParserErrorExpectedToken" xml:space="preserve">
<value>Sax parser error, expecting token : '{0}'</value>
</data>
<data name="ParserErrorMissingVersionEncoding" xml:space="preserve">
<value>Xml parsing error, missing version and encoding.</value>
</data>
<data name="WarningMsg" xml:space="preserve">
<value>Warning: {0}</value>
</data>
Expand Down

0 comments on commit 4310142

Please sign in to comment.