Skip to content

Commit 2948310

Browse files
author
Joseph Phillips
committed
Added Unit test project. Feature collection test for point features passing.
1 parent e0ef8cd commit 2948310

5 files changed

Lines changed: 256 additions & 0 deletions

File tree

Lib/xunit.dll

61 KB
Binary file not shown.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Xunit;
6+
using Newtonsoft.Json;
7+
8+
namespace SharpGeoJSON.UnitTests
9+
{
10+
public class FeatureCollectionTests
11+
{
12+
private const string CompanyJson = @"
13+
{
14+
""type"": ""FeatureCollection"",
15+
""company_id"": 1,
16+
""name"":""acme"",
17+
""features"":
18+
[
19+
{
20+
""fid"":1,
21+
""properties"":
22+
{
23+
""site_id"":10,
24+
""address"":""somewhere"",
25+
""type"":""office"",
26+
""employees"":
27+
[
28+
{
29+
""employee_id"":33,
30+
""name"":""Mr. Johnson"",
31+
""position"":""Company Man""
32+
}
33+
]
34+
},
35+
""geometry"":
36+
{
37+
""type"": ""Point"",
38+
""coordinates"": [1, 2]
39+
}
40+
},
41+
{
42+
""fid"":2,
43+
""properties"":
44+
{
45+
""site_id"":11,
46+
""address"":""somewhere else"",
47+
""type"":""warehouse"",
48+
""employees"":
49+
[
50+
{
51+
""employee_id"":44,
52+
""name"":""Ronnie James Dio"",
53+
""position"":""Legend""
54+
},
55+
{
56+
""employee_id"":55,
57+
""name"":""Chuck Schuldiner"",
58+
""position"":""Godfather""
59+
}
60+
]
61+
},
62+
""geometry"":
63+
{
64+
""type"": ""Point"",
65+
""coordinates"": [3, 4]
66+
}
67+
}
68+
]
69+
}";
70+
71+
[Fact]
72+
public void TestPointFeatureCollection()
73+
{
74+
var collection = JsonConvert.DeserializeObject<CompanySiteCollection>(CompanyJson);
75+
76+
Assert.Equal(2, collection.Features.Count());
77+
Assert.Equal(1, collection.CompanyId);
78+
Assert.Equal("acme", collection.Name);
79+
80+
Assert.Equal(1, collection.Features[0].FeatureId);
81+
Assert.Equal(10, collection.Features[0].Properties.SiteId);
82+
Assert.Equal("somewhere", collection.Features[0].Properties.Address);
83+
Assert.Equal(1, collection.Features[0].Geometry.X);
84+
Assert.Equal(2, collection.Features[0].Geometry.Y);
85+
86+
Assert.Equal(1, collection.Features[0].Properties.Employees.Count());
87+
Assert.Equal(33, collection.Features[0].Properties.Employees[0].EmployeeId);
88+
Assert.Equal("Mr. Johnson", collection.Features[0].Properties.Employees[0].Name);
89+
Assert.Equal("Company Man", collection.Features[0].Properties.Employees[0].Position);
90+
91+
Assert.Equal(2, collection.Features[1].FeatureId);
92+
Assert.Equal(11, collection.Features[1].Properties.SiteId);
93+
Assert.Equal("somewhere else", collection.Features[1].Properties.Address);
94+
Assert.Equal(3, collection.Features[1].Geometry.X);
95+
Assert.Equal(4, collection.Features[1].Geometry.Y);
96+
97+
Assert.Equal(2, collection.Features[1].Properties.Employees.Count());
98+
Assert.Equal(44, collection.Features[1].Properties.Employees[0].EmployeeId);
99+
Assert.Equal("Ronnie James Dio", collection.Features[1].Properties.Employees[0].Name);
100+
Assert.Equal("Legend", collection.Features[1].Properties.Employees[0].Position);
101+
Assert.Equal(55, collection.Features[1].Properties.Employees[1].EmployeeId);
102+
Assert.Equal("Chuck Schuldiner", collection.Features[1].Properties.Employees[1].Name);
103+
Assert.Equal("Godfather", collection.Features[1].Properties.Employees[1].Position);
104+
}
105+
}
106+
107+
public class CompanySiteCollection : FeatureCollection<CompanySite>
108+
{
109+
[JsonProperty("company_id")]
110+
public int CompanyId { get; set; }
111+
112+
[JsonProperty("name")]
113+
public string Name { get; set; }
114+
}
115+
116+
public class CompanySite : PointFeature<SiteProperties>
117+
{
118+
[JsonProperty("fid")]
119+
public int FeatureId { get; set; }
120+
}
121+
122+
public class SiteProperties
123+
{
124+
[JsonProperty("site_id")]
125+
public int SiteId { get; set; }
126+
127+
[JsonProperty("address")]
128+
public string Address { get; set; }
129+
130+
[JsonProperty("type")]
131+
public string Type { get; set; }
132+
133+
[JsonProperty("employees")]
134+
public List<EmployeeProperties> Employees { get; set; }
135+
}
136+
137+
public class EmployeeProperties
138+
{
139+
[JsonProperty("employee_id")]
140+
public int EmployeeId { get; set; }
141+
142+
[JsonProperty("name")]
143+
public string Name { get; set; }
144+
145+
[JsonProperty("position")]
146+
public string Position { get; set; }
147+
}
148+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SarpGeoJSON.UnitTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Ennoble Consultancy Australia")]
12+
[assembly: AssemblyProduct("SarpGeoJSON.UnitTests")]
13+
[assembly: AssemblyCopyright("Copyright © Ennoble Consultancy Australia 2011")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a74fc1e7-1655-4d77-bd2e-801eafe96f09")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{916246A5-C758-45AD-93CA-6ACF952C50D8}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>SharpGeoJSON.UnitTests</RootNamespace>
12+
<AssemblyName>SharpGeoJSON.UnitTests</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Newtonsoft.Json.Net35">
36+
<HintPath>..\Lib\Newtonsoft.Json.Net35.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
<Reference Include="xunit">
45+
<HintPath>..\Lib\xunit.dll</HintPath>
46+
</Reference>
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="FeatureCollectionTests.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\SharpGeoJSON\SharpGeoJSON.csproj">
54+
<Project>{568C3EDD-89C6-495A-AFA3-73B8CDC61D36}</Project>
55+
<Name>SharpGeoJSON</Name>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60+
Other similar extension points exist, see Microsoft.Common.targets.
61+
<Target Name="BeforeBuild">
62+
</Target>
63+
<Target Name="AfterBuild">
64+
</Target>
65+
-->
66+
</Project>

SharpGeoJSON.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
33
# Visual Studio 2010
44
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGeoJSON", "SharpGeoJSON\SharpGeoJSON.csproj", "{568C3EDD-89C6-495A-AFA3-73B8CDC61D36}"
55
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGeoJSON.UnitTests", "SharpGeoJSON.UnitTests\SharpGeoJSON.UnitTests.csproj", "{916246A5-C758-45AD-93CA-6ACF952C50D8}"
7+
EndProject
68
Global
79
GlobalSection(SolutionConfigurationPlatforms) = preSolution
810
Debug|Any CPU = Debug|Any CPU
@@ -13,6 +15,10 @@ Global
1315
{568C3EDD-89C6-495A-AFA3-73B8CDC61D36}.Debug|Any CPU.Build.0 = Debug|Any CPU
1416
{568C3EDD-89C6-495A-AFA3-73B8CDC61D36}.Release|Any CPU.ActiveCfg = Release|Any CPU
1517
{568C3EDD-89C6-495A-AFA3-73B8CDC61D36}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{916246A5-C758-45AD-93CA-6ACF952C50D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{916246A5-C758-45AD-93CA-6ACF952C50D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{916246A5-C758-45AD-93CA-6ACF952C50D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{916246A5-C758-45AD-93CA-6ACF952C50D8}.Release|Any CPU.Build.0 = Release|Any CPU
1622
EndGlobalSection
1723
GlobalSection(SolutionProperties) = preSolution
1824
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)