Skip to content

Commit

Permalink
Use NUnit dotnet core test runner
Browse files Browse the repository at this point in the history
Also:

* Update `.travis.yml` to use .NET Core released version.
* Update `appveyor.yml` with `dotnet pack` and saving package as build
  artifact (we can configure `deploy:` to NuGet as well).
* Minor branding updates including addition of MaxMind-logo and used in
  project.json -> `iconUrl`. :)
* Add ability to set `mmdb` path via command-line argument and
  environment variable `MAXMIND_BENCHMARK_DB` in `GeoIP2.Benchmark`
  runner with fallback to CWD/GeoLite2-City.mmdb.
* Add ability to set test directory via environment variable
  `MAXMIND_TEST_BASE_DIR` in `GeoIP2.UnitTests` and falls back to CWD.
* Remove `Program.cs` in `UnitTests` project in favour of
  dotnet-test-nunit runner.
  • Loading branch information
am11 committed Jul 14, 2016
1 parent 66b5e8a commit 91248e3
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 120 deletions.
90 changes: 54 additions & 36 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
---
sudo: false
language: csharp
# dotnet cli require Ubuntu 14.04
sudo: required
dist: trusty

# dotnet cli require OSX 10.10
osx_image: xcode7.1
language: generic

addons:
apt:
packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8

os:
- osx
- linux
- zlib1g

env:
matrix:
- CLI_VERSION: Latest
Configuration: Debug
Framework: netcoreapp1.0
- CLI_VERSION: Latest
Configuration: Release
Framework: netcoreapp1.0
global:
- MAXMIND_BENCHMARK_DB=GeoIP2.Benchmark/GeoLite2-City.mmdb
- MAXMIND_TEST_BASE_DIR=GeoIP2.UnitTests

matrix:
include:
- os: linux
dist: trusty # Ubuntu 14.04
sudo: required
env: CONFIGURATION=Debug
- os: linux
dist: trusty
sudo: required
env: CONFIGURATION=Release
- os: osx
osx_image: xcode7.2 # macOS 10.11
env: CONFIGURATION=Debug
- os: osx
osx_image: xcode7.2
env: CONFIGURATION=Release

before_install:
# Install OpenSSL
# Also set download URLs obtained from https://www.microsoft.com/net/download#core
- if test "$TRAVIS_OS_NAME" == "osx"; then
brew update;
brew install openssl;
brew link --force openssl;
export DOTNET_SDK_URL="https://go.microsoft.com/fwlink/?LinkID=809128";
else
export DOTNET_SDK_URL="https://go.microsoft.com/fwlink/?LinkID=809129";
fi

# Download script to install dotnet cli
- curl -L --create-dirs https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh -o ./scripts/install.sh

- export DOTNET_INSTALL_DIR="$PWD/.dotnetcli"

# Install the latest versio of dotnet CLI
- bash ./scripts/install.sh --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR" --no-path
# Install .NET CLI
- mkdir $DOTNET_INSTALL_DIR
- curl -L $DOTNET_SDK_URL -o dotnet_package
- tar -xvzf dotnet_package -C $DOTNET_INSTALL_DIR

# Add dotnet to PATH
- export PATH="$DOTNET_INSTALL_DIR:$PATH"

install:
# Update submodules
- git submodule update --init --recursive

install:
# Display dotnet version info
- which dotnet;
if [ $? -eq 0 ]; then
echo "Using dotnet:";
Expand All @@ -56,20 +68,26 @@ install:
exit 1;
fi

# Restore dependencies
- dotnet restore
# Hack for: https://github.com/dotnet/cli/issues/3658
- if test "$TRAVIS_OS_NAME" == "linux"; then
nvm install stable && nvm use stable;
fi
- node -e "jsonPath='./GeoIP2.Benchmark/project.json';data=require(jsonPath);fs=require('fs');delete data.frameworks.net45;fs.writeFileSync(jsonPath, JSON.stringify(data, null, 2))"

- FrameworkLibsMoniker="netstandard1.4"
# Restore Packages
- dotnet restore

# Build projects
- dotnet build -c $Configuration -f $FrameworkLibsMoniker ./GeoIP2
- dotnet build -c $Configuration -f $Framework ./GeoIP2.Benchmark
- dotnet build -c $Configuration -f $Framework ./GeoIP2.UnitTests
# Build Projects
- dotnet build -c $CONFIGURATION -f netstandard1.4 ./GeoIP2
- dotnet build -c $CONFIGURATION -f netcoreapp1.0 ./GeoIP2.Benchmark
- dotnet build -c $CONFIGURATION -f netcoreapp1.0 ./GeoIP2.UnitTests

script:
# Run tests
- cd ./GeoIP2.UnitTests
- dotnet run -f $Framework -c $Configuration
# Run Benchmark
- dotnet run -f netcoreapp1.0 -c $CONFIGURATION -p GeoIP2.Benchmark

# Run Unit Tests
- dotnet test -f netcoreapp1.0 -c $CONFIGURATION GeoIP2.UnitTests

notifications:
email:
Expand Down
40 changes: 37 additions & 3 deletions GeoIP2.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,50 @@
using System;
using System.Diagnostics;
using System.Net;
using System.IO;

namespace MaxMind.GeoIP2.Benchmark
{
internal class Program
public class Program
{
private static readonly int COUNT = 200000;

private static void Main(string[] args)
public static void Main(string[] args)
{
using (var reader = new DatabaseReader("GeoLite2-City.mmdb", FileAccessMode.Memory))
// first we check if the command-line argument is provided
string dbPath = args.Length > 0 ? args[0] : null;
if (dbPath != null)
{
if (!File.Exists(dbPath))
{
throw new Exception("Path provided by command-line argument does not exist!");
}
}
else
{
// check if environment variable MAXMIND_BENCHMARK_DB is set
dbPath = Environment.GetEnvironmentVariable("MAXMIND_BENCHMARK_DB");

if (!string.IsNullOrEmpty(dbPath))
{
if (!File.Exists(dbPath))
{
throw new Exception("Path set as environment variable MAXMIND_BENCHMARK_DB does not exist!");
}
}
else
{
// check if GeoLite2-City.mmdb exists in CWD
dbPath = "GeoLite2-City.mmdb";

if (!File.Exists(dbPath))
{
throw new Exception($"{dbPath} does not exist in current directory!");
}
}
}

using (var reader = new DatabaseReader(dbPath, FileAccessMode.Memory))
{
Bench("Warm-up for Memory mode", reader);
Bench("Memory mode", reader);
Expand Down
8 changes: 0 additions & 8 deletions GeoIP2.Benchmark/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
"name": "MaxMind.GeoIP2.Benchmark",
"description": "Benchmark project to validate MaxMind GeoIP2 Database Reader and Web Service Client",

"packOptions": {
"authors": ["MaxMind, Inc."],
"tags": [""],
"projectUrl": "https://github.com/maxmind/MaxMind-DB-Reader-dotnet",
"licenseUrl": "https://github.com/maxmind/MaxMind-DB-Reader-dotnet/blob/v2.0.0/LICENSE",
"copyright": "Copyright © 2013-2016"
},

"buildOptions": {
"emitEntryPoint": true,
"keyFile": "../MaxMind.snk"
Expand Down
2 changes: 1 addition & 1 deletion GeoIP2.UnitTests/DatabaseReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DatabaseReaderTests

public DatabaseReaderTests()
{
var databaseDir = Path.Combine(Program.CurrentDirectory, "TestData", "MaxMind-DB", "test-data");
var databaseDir = Path.Combine(TestUtils.TestDirectory, "TestData", "MaxMind-DB", "test-data");

_anonymousIpDatabaseFile = Path.Combine(databaseDir, "GeoIP2-Anonymous-IP-Test.mmdb");
_cityDatabaseFile = Path.Combine(databaseDir, "GeoIP2-City-Test.mmdb");
Expand Down
2 changes: 1 addition & 1 deletion GeoIP2.UnitTests/DeserializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void CanDeserializeCountryResponseNewtonsoftJson()
public void CanDeserializeFromDatabaseType()
{
var reader =
new DatabaseReader(Path.Combine(Program.CurrentDirectory, "TestData", "MaxMind-DB", "test-data", "GeoIP2-City-Test.mmdb"));
new DatabaseReader(Path.Combine(TestUtils.TestDirectory, "TestData", "MaxMind-DB", "test-data", "GeoIP2-City-Test.mmdb"));

var response = reader.City(IPAddress.Parse("216.160.83.56"));

Expand Down
27 changes: 0 additions & 27 deletions GeoIP2.UnitTests/Program.cs

This file was deleted.

32 changes: 32 additions & 0 deletions GeoIP2.UnitTests/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;

namespace MaxMind.GeoIP2.UnitTests
{
internal static class TestUtils
{
public static string TestDirectory { get; } = GetTestDirectory();

private static string GetTestDirectory()
{
// check if environment variable MAXMIND_TEST_BASE_DIR is set
string dbPath = Environment.GetEnvironmentVariable("MAXMIND_TEST_BASE_DIR");

if (!string.IsNullOrEmpty(dbPath))
{
if (!Directory.Exists(dbPath))
{
throw new Exception("Path set as environment variable MAXMIND_TEST_BASE_DIR does not exist!");
}

return dbPath;
}

#if !NETCOREAPP1_0
return Environment.CurrentDirectory;
#else
return Directory.GetCurrentDirectory();
#endif
}
}
}
22 changes: 6 additions & 16 deletions GeoIP2.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@
"name": "MaxMind.GeoIP2.UnitTests",
"description": "Test project to validate MaxMind GeoIP2 Database Reader and Web Service Client",

"packOptions": {
"authors": ["MaxMind, Inc."],
"tags": [""],
"projectUrl": "https://github.com/maxmind/GeoIP2-dotnet",
"licenseUrl": "https://github.com/maxmind/GeoIP2-dotnet/blob/master/LICENSE",
"copyright": "Copyright © 2013-2016"
},

"commands": {
"test": "MaxMind.GeoIP2.UnitTests"
},

"buildOptions": {
"emitEntryPoint": true,
"keyFile": "../MaxMind.snk"
},

"dependencies": {
"GeoIP2": {
"target": "project"
},
"NUnitLite": "3.2.1",
"NUnit": "3.4.0",
"dotnet-test-nunit": "3.4.0-beta-1",
"MockHttpSigned": "1.3.0-netstandard-alpha3"
},

"testRunner": "nunit",

"frameworks": {
"net45": {},
"net451": {},
"netcoreapp1.0": {
"imports": "dnxcore50",
"imports": "portable-net45+win8",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
Expand Down
19 changes: 11 additions & 8 deletions GeoIP2/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@
"version": "2.7.0-beta2",
"name": "MaxMind.GeoIP2",
"description": "MaxMind GeoIP2 Database Reader and Web Service Client",

"packOptions": {
"authors": [
"MaxMind, Inc."
],
"tags": [
""
],
"authors": ["Gregory Oschwald", "Mark Fowler"],
"tags": ["maxmind", "ip", "geoip", "geoip2", "geolocation", "ip2location", "iptolocation", "maxmind", "ipv4", "ipv6"],
"iconUrl": "https://raw.githubusercontent.com/maxmind/GeoIP2-dotnet/master/MaxMind-logo.png",
"projectUrl": "https://github.com/maxmind/GeoIP2-dotnet",
"licenseUrl": "https://github.com/maxmind/GeoIP2-dotnet/blob/master/LICENSE",
"copyright": "Copyright © 2013-2016"
"copyright": "Copyright © 2013-2016 MaxMind, Inc.",
"repository": {
"type": "git",
"url": "https://github.com/maxmind/GeoIP2-dotnet"
}
},

"buildOptions": {
"keyFile": "../MaxMind.snk",
"outputName": "MaxMind.GeoIP2",
"xmlDoc": true
},
"dependencies": {
"MaxMind.Db": "2.1.1-*",
"Newtonsoft.Json": "9.0.1-beta1"
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"net45": {
Expand Down
Binary file added MaxMind-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 91248e3

Please sign in to comment.