Skip to content

Commit

Permalink
-add: retrieving information from QUERY_STRING environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
yas4891 committed May 2, 2012
1 parent 62a4aaa commit f35f977
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
10 changes: 10 additions & 0 deletions GSTConsole/GSTConsole.csproj
Expand Up @@ -37,6 +37,14 @@
<Reference Include="Antlr3.Runtime">
<HintPath>..\ThirdPartyLibs\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.mocks, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\nunit.mocks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -46,8 +54,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GeneralHelper.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="test\GeneralHelperTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CTokenizer\CTokenizer.csproj">
Expand Down
30 changes: 30 additions & 0 deletions GSTConsole/GeneralHelper.cs
Expand Up @@ -7,7 +7,37 @@ namespace GSTConsole
{
static class GeneralHelper
{
/// <summary>
/// extracts the student identifier from the query string
/// </summary>
/// <param name="queryString"></param>
/// <returns></returns>
internal static string GetStudentIdentifier(string queryString)
{
var firstPart = queryString.Substring(0, queryString.IndexOf('&'));
var afterSecondSlash = firstPart.Substring(firstPart.IndexOf('/', firstPart.IndexOf('/') + 1) + 1);
return afterSecondSlash.Substring(0, afterSecondSlash.IndexOf('/'));
}

/// <summary>
/// extracts the assignment identifier from the query string
/// </summary>
/// <param name="queryString"></param>
/// <returns></returns>
internal static string GetAssignmentIdentifier(string queryString)
{
var middlePart = queryString.Substring(queryString.IndexOf('&') + 1);
middlePart = middlePart.Substring(0, middlePart.IndexOf('&'));

return middlePart.Substring(middlePart.LastIndexOf('/') + 1);
}

/// <summary>
/// extracts the path from the query string
/// </summary>
/// <param name="queryString"></param>
/// <returns></returns>
internal static string GetPath(string queryString)
{
return queryString.Substring(0, queryString.IndexOf('&'));
}
Expand Down
7 changes: 3 additions & 4 deletions GSTConsole/Program.cs
@@ -1,10 +1,6 @@
using System;
using System.IO;
using CTokenizer;
using DataRepository;
using GSTAppLogic.app;
using GSTAppLogic.app.model;
using GSTAppLogic.test.model;

namespace GSTConsole
{
Expand All @@ -19,7 +15,10 @@ static void Main(string[] args)
if(!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("QUERY_STRING")))
{
var queryString = Environment.GetEnvironmentVariable("QUERY_STRING");

assignment = GeneralHelper.GetAssignmentIdentifier(queryString);
student = GeneralHelper.GetStudentIdentifier(queryString);
path = GeneralHelper.GetPath(queryString);
}
else if(3 == args.Length)
{
Expand Down
8 changes: 7 additions & 1 deletion GSTConsole/test/GeneralHelperTest.cs
Expand Up @@ -7,7 +7,7 @@
namespace GSTConsole.test
{
[TestFixture]
class GeneralHelperTest
public class GeneralHelperTest
{
private const string EXAMPLE_1 = "UPLOAD/mop/Pawelczak+Dieter/59067/V1/aufgabe2_10.c&HTML/mop/_plag/V1/aufgabe2_10&main";

Expand All @@ -16,5 +16,11 @@ public void GetStudentIdentifier()
{
Assert.AreEqual("Pawelczak+Dieter", GeneralHelper.GetStudentIdentifier(EXAMPLE_1));
}

[Test]
public void GetAssignmentIdentifier()
{
Assert.AreEqual("aufgabe2_10", GeneralHelper.GetAssignmentIdentifier(EXAMPLE_1));
}
}
}
8 changes: 6 additions & 2 deletions GSTTests.VisualState.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<VisualState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ShowCheckBoxes="true">
<TopNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</TopNode>
<SelectedNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</SelectedNode>
<TopNode>[0-1014]GSTLibrary.test.tile.GSTAlgorithmTest.MatchesTwoDifferentTiles</TopNode>
<SelectedNode>[0-1036]GSTConsole.test.GeneralHelperTest.GetStudentIdentifier</SelectedNode>
<ExcludeCategories>false</ExcludeCategories>
<Nodes>
<Node UniqueName="[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit" Expanded="true" />
Expand All @@ -20,5 +20,9 @@
<Node UniqueName="[0-1032]GSTAppLogic" Expanded="true" />
<Node UniqueName="[0-1033]GSTAppLogic.test" Expanded="true" />
<Node UniqueName="[0-1034]GSTAppLogic.test.model" Expanded="true" />
<Node UniqueName="[0-1038]D:\wissen\csharp\GreedyStringTiling\GSTConsole\bin\Debug\GSTConsole.exe" Expanded="true" />
<Node UniqueName="[0-1039]GSTConsole" Expanded="true" />
<Node UniqueName="[0-1040]GSTConsole.test" Expanded="true" />
<Node UniqueName="[0-1035]GSTConsole.test.GeneralHelperTest" Expanded="true" />
</Nodes>
</VisualState>
1 change: 1 addition & 0 deletions GSTTests.nunit
Expand Up @@ -4,6 +4,7 @@
<assembly path="GSTLibrary\bin\Debug\GSTLibrary.dll" />
<assembly path="CTokenizer\bin\Debug\CTokenizer.dll" />
<assembly path="GSTAppLogic\bin\Debug\GSTAppLogic.dll" />
<assembly path="GSTConsole\bin\Debug\GSTConsole.exe" />
</Config>
<Config name="Release" binpathtype="Auto" />
</NUnitProject>

0 comments on commit f35f977

Please sign in to comment.