Skip to content

Commit

Permalink
Reworked, added a test class, and fixed priority and context lookups.
Browse files Browse the repository at this point in the history
Changed to a Portable Class Library project to support desktop, win8,
and Windows Phone 8.
  • Loading branch information
austhomp committed Feb 13, 2014
1 parent 7926a5c commit ccbb04a
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 65 deletions.
36 changes: 36 additions & 0 deletions TRDataReader.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TRDataReader.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TRDataReader.Tests")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("78c6f8f1-d765-4097-af54-8e37b66cf5ef")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
27 changes: 27 additions & 0 deletions TRDataReader.Tests/ReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace TRDataReader.Tests
{
[TestClass]
public class ReaderTests
{
private const string TestInput = @"<data><version>5</version><maxID>149</maxID><topics><items><topic><name>None</name><description>No topic.</description><color><red>0</red><green>0</green><blue>0</blue><alpha>255</alpha></color><background><red>255</red><green>255</green><blue>255</blue><alpha>255</alpha></background><id>8</id></topic></items></topics><contexts><items><context><name>None</name><description>No context.</description><id>9</id></context><context><name>@ContextOne</name><description></description><id>144</id></context><context><name>@Context2</name><description></description><id>145</id></context></items></contexts><information><items><info><created>2014-02-08 20:05:02.631 UTC</created><description>Action 3 (Reference)</description><topic reference=""../../../../topics/items/topic""/><location></location><notes>Test</notes><id>140</id></info></items></information><futures><items><future><created>2014-02-08 20:05:11.727 UTC</created><thought><created>2014-02-08 20:04:06.63 UTC</created><description>Action 4 (Someday)</description><topic reference=""../../../../../topics/items/topic""/><processed>true</processed><id>132</id></thought><description>Action 4 (Someday)</description><topic reference=""../../../../topics/items/topic""/><notes></notes><id>142</id></future></items></futures><thoughts><items><thought><created>2014-02-08 20:03:44.3 UTC</created><description>Action 1</description><topic reference=""../../../../topics/items/topic""/><processed>true</processed><id>128</id></thought><thought><created>2014-02-08 20:03:50.606 UTC</created><description>Action 2</description><topic reference=""../../../../topics/items/topic""/><processed>true</processed><id>129</id></thought><thought><created>2014-02-08 20:03:53.15 UTC</created><description>Action 3 (Reference)</description><topic reference=""../../../../topics/items/topic""/><processed>true</processed><notes>Test</notes><id>130</id></thought><thought reference=""../../../futures/items/future/thought""/><thought><created>2014-02-08 20:04:08.662 UTC</created><description>Action 5</description><topic reference=""../../../../topics/items/topic""/><processed>false</processed><id>133</id></thought><thought><created>2014-02-08 20:04:10.22 UTC</created><description>Action 6</description><topic reference=""../../../../topics/items/topic""/><processed>false</processed><id>134</id></thought></items></thoughts><rootProject class=""projects""><id>1</id><created>2014-02-08 20:03:38.744 UTC</created><parent class=""tr.model.project.ProjectRoot""><id>0</id><created>2014-02-08 20:03:38.785 UTC</created><children><projects reference=""../../..""/><actions><id>2</id><created>2014-02-08 20:03:38.745 UTC</created><parent class=""tr.model.project.ProjectRoot"" reference=""../../..""/><children><action><id>137</id><created>2014-02-08 20:04:14.848 UTC</created><thought reference=""../../../../../../../thoughts/items/thought""/><parent class=""actions"" reference=""../../..""/><description>Action 1</description><topic reference=""../../../../../../../topics/items/topic""/><context reference=""../../../../../../../contexts/items/context[2]""/><state class=""actionStateASAP""><created>2014-02-08 20:04:34.54 UTC</created></state><notes></notes><done>false</done><priority><id>126</id><name>Would</name></priority><success></success><modified>2014-02-08 20:06:28.895 UTC</modified></action><action><id>138</id><created>2014-02-08 20:04:34.54 UTC</created><thought reference=""../../../../../../../thoughts/items/thought[2]""/><parent class=""actions"" reference=""../../..""/><description>Action 2</description><topic reference=""../../../../../../../topics/items/topic""/><context reference=""../../../../../../../contexts/items/context""/><state class=""actionStateInactive""><created>2014-02-08 20:04:40.271 UTC</created></state><notes></notes><done>false</done><priority><id>127</id><name>Could</name></priority><success></success><modified>2014-02-08 20:06:32.935 UTC</modified></action><action><id>147</id><created>2014-02-08 20:06:38.255 UTC</created><parent class=""actions"" reference=""../../..""/><description>Another action</description><topic reference=""../../../../../../../topics/items/topic""/><context reference=""../../../../../../../contexts/items/context[3]""/><state class=""actionStateInactive""><created>2014-02-08 20:06:38.257 UTC</created></state><notes>Manually entered into single actions via F3 and not from process screen</notes><done>false</done><priority><id>125</id><name>Should</name></priority><modified>2014-02-08 20:07:15.831 UTC</modified></action></children><topic reference=""../../../../../topics/items/topic""/><description></description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:06:38.257 UTC</modified></actions></children><topic reference=""../../../topics/items/topic""/><description></description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:03:38.785 UTC</modified></parent><children><project><id>148</id><created>2014-02-08 20:07:22.920 UTC</created><parent class=""projects"" reference=""../../..""/><children><action><id>149</id><created>2014-02-08 20:07:30.154 UTC</created><parent reference=""../../..""/><description>Project action 1</description><topic reference=""../../../../../../topics/items/topic""/><context reference=""../../../../../../contexts/items/context[3]""/><state class=""actionStateASAP""><created>2014-02-08 20:07:45.880 UTC</created></state><notes></notes><done>false</done><modified>2014-02-08 20:07:45.880 UTC</modified></action></children><topic reference=""../../../../topics/items/topic""/><description>Test project</description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:07:30.154 UTC</modified><seqIncludeProjects>true</seqIncludeProjects><seqIncludeScheduled>false</seqIncludeScheduled><seqIncludeDelegated>false</seqIncludeDelegated></project></children><topic reference=""../../topics/items/topic""/><description></description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:07:22.920 UTC</modified></rootProject><rootActions class=""actions"" reference=""../rootProject/parent/children/actions""/><rootTemplates class=""tr.model.project.ProjectTemplates""><id>3</id><created>2014-02-08 20:03:38.745 UTC</created><children/><topic reference=""../../topics/items/topic""/><description></description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:03:38.745 UTC</modified></rootTemplates><rootFutures class=""tr.model.project.ProjectFutures""><id>4</id><created>2014-02-08 20:03:38.745 UTC</created><children/><topic reference=""../../topics/items/topic""/><description></description><purpose></purpose><success></success><brainstorming></brainstorming><organising></organising><done>false</done><sequence>true</sequence><modified>2014-02-08 20:03:38.745 UTC</modified></rootFutures><timeCriterion><name>Time</name><use>false</use><values><items><value><id>101</id><name>5 min</name></value><value><id>102</id><name>10 min</name></value><value><id>103</id><name>15 min</name></value><value><id>104</id><name>20 min</name></value><value><id>105</id><name>30 min</name></value><value><id>106</id><name>45 min</name></value><value><id>107</id><name>1 hr</name></value><value><id>108</id><name>1.5 hrs</name></value><value><id>109</id><name>2 hrs</name></value><value><id>110</id><name>2.5 hrs</name></value><value><id>111</id><name>3 hrs</name></value><value><id>112</id><name>4 hrs</name></value><value><id>113</id><name>5 hrs</name></value><value><id>114</id><name>6 hrs</name></value><value><id>115</id><name>7 hrs</name></value><value><id>116</id><name>8 hrs</name></value></items></values></timeCriterion><energyCriterion><name>Energy</name><use>false</use><values><items><value><id>117</id><name>None</name></value><value><id>118</id><name>Low Mental</name></value><value><id>119</id><name>Med Mental</name></value><value><id>120</id><name>High Mental</name></value><value><id>121</id><name>Low Physical</name></value><value><id>122</id><name>Med Physical</name></value><value><id>123</id><name>High Physical</name></value></items></values></energyCriterion><priorityCriterion><name>Priority</name><use>true</use><values><items><value><id>124</id><name>Must</name></value><value reference=""../../../../rootProject/parent/children/actions/children/action[3]/priority""/><value reference=""../../../../rootProject/parent/children/actions/children/action/priority""/><value reference=""../../../../rootProject/parent/children/actions/children/action[2]/priority""/></items></values></priorityCriterion><maxLogID>0</maxLogID><actors><items/></actors><levels/></data>";

[TestMethod]
public void ParseData_Should_ReturnCorrectEntriesForTheInput()
{
var reader = new Reader();
var output = reader.ParseData(TestInput);

Assert.IsNotNull(output);

var doasap = output.Where(x => x.ActionState.Contains("ASAP")).ToList();
Assert.IsTrue(doasap.Count == 2);

var inactives = output.Where(x => x.ActionState.Contains("Inactive")).ToList();
Assert.IsTrue(inactives.Count == 2);
}
}
}
89 changes: 89 additions & 0 deletions TRDataReader.Tests/TRDataReader.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E3C87E5B-5113-4CAC-86BD-E9F3F9F0676B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TRDataReader.Tests</RootNamespace>
<AssemblyName>TRDataReader.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.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>
</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="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="ReaderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TRDataReader\TRDataReader.csproj">
<Project>{4106f0f7-a28a-4614-9f7d-7974129cc5a4}</Project>
<Name>TRDataReader</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
58 changes: 52 additions & 6 deletions TRDataReader/Extensions/XDocExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,33 @@ public static string GetAttributeOrValue(this XElement node, string attributeNam
return attribute != null ? attribute.Value : node.Value;
}

public static string GetRelativeElementValue(this XElement node, string element)
{
var e = node.Element(element);

if (e == null)
{
return "N/A";
}

var r = e.Attribute("reference");
if (r != null)
{
return r.GetRelativeValue();
}
else
{
return (string)e;
}
}

public static string GetRelativeValue(this XAttribute attribute)
{
return attribute.Parent.GetRelativeValue(attribute.Value);
var relativeValue = attribute.Parent.GetRelativeValue(attribute.Value);
return relativeValue;
}

public static string GetRelativeValue(this XElement node, string pathReference)
public static string GetRelativeValue(this XElement node, string pathReference, string targetElementName = null)
{
var parts = pathReference.Split(new string[] { "/"}, StringSplitOptions.RemoveEmptyEntries);
XElement current = node;
Expand All @@ -57,19 +78,44 @@ public static string GetRelativeValue(this XElement node, string pathReference)
var opening = part.IndexOf("[");
var target = part.Substring(0, opening);
var ending = part.IndexOf("]");
var index = int.Parse(part.Substring(opening + 1, ending - opening-1));
var index = int.Parse(part.Substring(opening + 1, ending - opening - 1));

current = current.Descendants(target).Skip(index-1).First();
// apparently we have to not count any items that are just references themselves. Not obvious nor was it easy to determine.
current = current.Descendants(target)
.Where(x => x.Elements().Where(y => !y.Value.Contains("reference")).Any())
.Skip(index - 1)
.First();
}
else
{
current = current.Element(part);
var prev = current;
current = current.Element(part);
if (current == null)
{
var maybeRef = prev.Attribute("reference");
if (maybeRef != null)
{
return prev.GetRelativeValue(maybeRef.Value, part);
}
}
}

}
}

if (current == null) return "<Unknown>";
return (string)current.Element("name") ?? current.Value as string;

if (targetElementName != null)
{
var d = current.Element(targetElementName);
if (d != null)
{
current = d;
}
}

string val = (string) current.Element("name") ?? current.Value;
return val;
}

public static XElement GetRelativeNode(this XAttribute attribute)
Expand Down
12 changes: 3 additions & 9 deletions TRDataReader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -13,14 +14,7 @@
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6037041c-5568-494d-aba1-015260b62de3")]
[assembly: NeutralResourcesLanguage("en")]

// Version information for an assembly consists of the following four values:
//
Expand Down
Loading

0 comments on commit ccbb04a

Please sign in to comment.