Skip to content
This repository has been archived by the owner on Jul 5, 2018. It is now read-only.

Commit

Permalink
Unit Test added, Maxmind db service tested
Browse files Browse the repository at this point in the history
  • Loading branch information
khurram khan committed Oct 18, 2016
1 parent 4370dc2 commit ed03b6d
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 23 deletions.
36 changes: 18 additions & 18 deletions GeoIp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,48 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EPiServer.ApplicationModules, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.ApplicationModules.dll</HintPath>
<Reference Include="EPiServer.ApplicationModules, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.ApplicationModules.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Data, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Data.dll</HintPath>
<Reference Include="EPiServer.Data, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Data.Cache, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Data.Cache.dll</HintPath>
<Reference Include="EPiServer.Data.Cache, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Data.Cache.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Events, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Events.dll</HintPath>
<Reference Include="EPiServer.Events, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Events.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Framework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Framework.dll</HintPath>
<Reference Include="EPiServer.Framework, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Licensing, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Licensing.dll</HintPath>
<Reference Include="EPiServer.Licensing, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Licensing.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPiServer.Shell, Version=9.0.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.0.0\lib\net45\EPiServer.Shell.dll</HintPath>
<Reference Include="EPiServer.Shell, Version=9.6.1.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7, processorArchitecture=MSIL">
<HintPath>packages\EPiServer.Framework.9.6.1\lib\net45\EPiServer.Shell.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MaxMind.Db, Version=2.0.0.0, Culture=neutral, PublicKeyToken=66afa4cc5ae853ac, processorArchitecture=MSIL">
<HintPath>packages\MaxMind.Db.2.0.0\lib\net45\MaxMind.Db.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MaxMind.GeoIP2, Version=2.5.0.0, Culture=neutral, PublicKeyToken=66afa4cc5ae853ac, processorArchitecture=MSIL">
<HintPath>packages\MaxMind.GeoIP2.2.5.0\lib\net452\MaxMind.GeoIP2.dll</HintPath>
<Reference Include="MaxMind.GeoIP2, Version=2.6.0.0, Culture=neutral, PublicKeyToken=66afa4cc5ae853ac, processorArchitecture=MSIL">
<HintPath>packages\MaxMind.GeoIP2.2.6.0\lib\net45\MaxMind.GeoIP2.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StructureMap, Version=3.1.6.186, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion GeoIp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoIp", "GeoIp.csproj", "{057FC15B-5276-4DEA-B9EB-ED8212CCFC10}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoIpTests", "..\GeoIpTests\GeoIpTests.csproj", "{790C223E-A730-404B-8407-785FDD8959B9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeoIpTests", "GeoIpTests\GeoIpTests.csproj", "{790C223E-A730-404B-8407-785FDD8959B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
103 changes: 103 additions & 0 deletions GeoIpTests/GeoIpTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{790C223E-A730-404B-8407-785FDD8959B9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GeoIpTests</RootNamespace>
<AssemblyName>GeoIpTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</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>
<TargetFrameworkProfile />
</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="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\Maxmind.GeoIP\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Moq, Version=4.5.23.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\Maxmind.GeoIP\packages\Moq.4.5.23\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\Maxmind.GeoIP\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<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 />
</Choose>
<ItemGroup>
<Compile Include="MaxmindGeoIp2Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="db\GeoLite2-City.mmdb" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GeoIp.csproj">
<Project>{057fc15b-5276-4dea-b9eb-ed8212ccfc10}</Project>
<Name>GeoIp</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>
23 changes: 23 additions & 0 deletions GeoIpTests/MaxmindGeoIp2Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using Pixie.Extensions.Maxmind.GeoIp.Services;
using System.Collections.Specialized;
using System.Net;

namespace GeoIpTests
{
[TestFixture]
public class MaxmindGeoIp2Tests
{
private GeolocationMaxmindService service = new GeolocationMaxmindService();

//[TestCase]
//public void MaxmindServiceDBTest()
//{
// NameValueCollection config = new NameValueCollection();
// config.Add("databaseFileName", @"C:\EPiServer\Extension\Maxmind\GIT\Maxmind.GeoIP\GeoIpTests\db\GeoLite2-City.mmdb");
// var result = service.GetGeoLocation(IPAddress.Parse("213.205.251.152"), config);
// Assert.AreEqual("GB", result.CountryCode);
//}

}
}
36 changes: 36 additions & 0 deletions GeoIpTests/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("GeoIpTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GeoIpTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("790c223e-a730-404b-8407-785fdd8959b9")]

// 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")]
11 changes: 11 additions & 0 deletions GeoIpTests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Binary file added GeoIpTests/db/GeoLite2-City.mmdb
Binary file not shown.
6 changes: 6 additions & 0 deletions GeoIpTests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.3" targetFramework="net45" />
<package id="Moq" version="4.5.23" targetFramework="net45" />
<package id="NUnit" version="3.5.0" targetFramework="net45" />
</packages>
1 change: 1 addition & 0 deletions Services/GeolocationMaxmindService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GeolocationMaxmindService : IGeolocationService
public GeoLocationResult GetGeoLocation(IPAddress address, NameValueCollection config)
{
string text = config["databaseFileName"];

if (!string.IsNullOrEmpty(text))
{
maxMindDatabaseFileName = VirtualPathUtilityEx.RebasePhysicalPath(text);
Expand Down
30 changes: 29 additions & 1 deletion app.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,35 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.ApplicationModules" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Data.Cache" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Data" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Events" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Framework" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Licensing" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EPiServer.Shell" publicKeyToken="8fe83dea738b45b7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.6.1.0" newVersion="9.6.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
6 changes: 3 additions & 3 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EPiServer.Framework" version="9.0.0" targetFramework="net452" />
<package id="EPiServer.Framework" version="9.6.1" targetFramework="net452" />
<package id="MaxMind.Db" version="2.0.0" targetFramework="net452" />
<package id="MaxMind.GeoIP2" version="2.5.0" targetFramework="net452" />
<package id="MaxMind.GeoIP2" version="2.6.0" targetFramework="net452" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net452" />
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net452" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net452" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" />
<package id="structuremap.web-signed" version="3.1.6.186" targetFramework="net452" />
<package id="structuremap-signed" version="3.1.6.186" targetFramework="net452" />
</packages>

0 comments on commit ed03b6d

Please sign in to comment.