Skip to content

Commit

Permalink
Fixed regn bug
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkors committed Feb 23, 2012
1 parent aae4536 commit 7d85f68
Show file tree
Hide file tree
Showing 24 changed files with 431 additions and 83 deletions.
10 changes: 10 additions & 0 deletions Local.testsettings
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="c6bb6cc5-b7ea-4b9e-a9a0-0fec093a78fa" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>
65 changes: 65 additions & 0 deletions ParApply.Business.Tests/ParApply.Business.Tests.csproj
@@ -0,0 +1,65 @@
<?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>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1D17094E-0F39-4382-B908-597A3AAF5911}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ParApply.Business.Tests</RootNamespace>
<AssemblyName>ParApply.Business.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</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.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ParaplyServiceTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ParApply.Business\ParApply.Business.csproj">
<Project>{0B093F7B-6671-4610-9B1B-5CF312D7990C}</Project>
<Name>ParApply.Business</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>
50 changes: 50 additions & 0 deletions ParApply.Business.Tests/ParaplyServiceTests.cs
@@ -0,0 +1,50 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ParApply.Business;

namespace ParApply.Business.Tests
{
[TestClass]
public class ParaplyServiceTests
{
[TestMethod]
public void ShouldUse_WhenRegn_ReturnsYes()
{
AssertUseParaplyWhenYrSymbolIs(UseParaply.Yes, "Regn");
AssertUseParaplyWhenYrSymbolIs(UseParaply.Yes, "regn");
}

[TestMethod]
public void ShouldUse_WhenNotRegn_ReturnsNo()
{
AssertUseParaplyWhenYrSymbolIs(UseParaply.No, "Something other");
}

private static void AssertUseParaplyWhenYrSymbolIs(UseParaply useParaply, string symbolName)
{
// arrange
var paraplyService = new ParaplyService();
var yrResult = GetYrResult(symbolName);

// act
var useParaplyResult = paraplyService.ShouldUseParaply(yrResult);

// assert
Assert.AreEqual(useParaply, useParaplyResult.Result, "One should use a paraply when yr symbol is {0}", symbolName);
}

private static Result<IEnumerable<YrData>> GetYrResult(string symbolName)
{
List<YrData> yrData = new List<YrData>();
yrData.Add(new YrData()
{
SymbolName = symbolName
});
var yrResult = new Result<IEnumerable<YrData>>(yrData);
return yrResult;
}
}
}
35 changes: 35 additions & 0 deletions ParApply.Business.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
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("ParApply.Business.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ParApply.Business.Tests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[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("4533a8ac-6163-499b-bb0b-2d94348f9a39")]

// 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.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
75 changes: 75 additions & 0 deletions ParApply.Business/ParApply.Business.csproj
@@ -0,0 +1,75 @@
<?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>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0B093F7B-6671-4610-9B1B-5CF312D7990C}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ParApply.Business</RootNamespace>
<AssemblyName>ParApply.Business</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<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;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Windows" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Net" />
<Reference Include="mscorlib.extensions" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="StedParser.cs" />
<Compile Include="Services\ParaplyService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\RestService.cs" />
<Compile Include="Result.cs" />
<Compile Include="Sted.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="UseParaply.cs" />
<Compile Include="UseParaplyResult.cs" />
<Compile Include="YrData.cs" />
<Compile Include="Services\YrService.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions />
<!-- 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>
37 changes: 37 additions & 0 deletions ParApply.Business/Properties/AssemblyInfo.cs
@@ -0,0 +1,37 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

// 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("ParApply.Business")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ParApply.Business")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[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("72aebc57-8bb6-4f99-abfd-b19ef0811a52")]

// 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 Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
@@ -1,6 +1,6 @@
using System;

namespace ParApply
namespace ParApply.Business
{
public class Result<T>
{
Expand Down
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace ParApply
namespace ParApply.Business
{
internal class ParaplyService
public class ParaplyService
{
public UseParaplyResult ShouldUseParaply(Result<IEnumerable<YrData>> yrResult)
{
Expand All @@ -12,20 +13,10 @@ public UseParaplyResult ShouldUseParaply(Result<IEnumerable<YrData>> yrResult)
{
var yrData = yrResult.Value.First();
useParaplyResult.YrData = yrData;
useParaplyResult.Result = yrData.SymbolName.Contains("regn", StringComparison.OrdinalIgnoreCase) ? UseParaply.Yes : UseParaply.No;
useParaplyResult.Result = yrData.SymbolName.Contains("regn", StringComparison.InvariantCultureIgnoreCase) ? UseParaply.Yes : UseParaply.No;
return useParaplyResult;
}
return useParaplyResult;
}
}

internal class UseParaplyResult
{
public bool HasError()
{
return YrData == null;
}
public YrData YrData { get; set; }
public UseParaply Result { get; set; }
}
}
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Xml;

namespace ParApply
namespace ParApply.Business
{
public abstract class RestService<T> where T : class
{
Expand Down Expand Up @@ -34,17 +34,11 @@ protected void Get(Uri uri, Action<Result<IEnumerable<T>>> callback)
}, webRequest);
}

private void OnResponse(IAsyncResult responseResult)
{

}

public abstract IEnumerable<T> ParseXml(XmlReader reader);

private IEnumerable<T> ParseResult(WebResponse response)
{
var encoding = Encoding.GetEncoding("iso-8859-1");
using (var sr = new StreamReader(response.GetResponseStream(), encoding))
{
using (var sr = new StreamReader(response.GetResponseStream()))
using (var xmlReader = XmlReader.Create(sr))
{
return ParseXml(xmlReader);
Expand Down
Expand Up @@ -4,7 +4,7 @@
using System.Xml;
using System.Xml.Linq;

namespace ParApply
namespace ParApply.Business
{
public class YrService : RestService<YrData>
{
Expand All @@ -28,7 +28,7 @@ public override IEnumerable<YrData> ParseXml(XmlReader reader)
Period = time.Attribute("period").Value,
SymbolName = time.Elements("symbol").First().Attribute("name").Value
};
return twoWeeksWorthOfYrData.ToList();
return Enumerable.ToList(twoWeeksWorthOfYrData);
}

}
Expand Down
16 changes: 16 additions & 0 deletions ParApply.Business/Sted.cs
@@ -0,0 +1,16 @@
using System;
using System.Globalization;

namespace ParApply.Business
{
public class Sted
{
public string Navn { get; set; }

public string Latitude { get; set; }

public string Longitude { get; set; }

public Uri YrUrl { get; set; }
}
}

0 comments on commit 7d85f68

Please sign in to comment.