Commit de7da51a authored by Nick Craver's avatar Nick Craver

Fix geo tests to run locally (if the version supports it)

parent 8976c8cc
using Xunit; using Xunit;
using System; using System;
using System.IO;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace StackExchange.Redis.Tests namespace StackExchange.Redis.Tests
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class AzureTestAttribute : FactAttribute
{
}
public class GeoTests : TestBase public class GeoTests : TestBase
{ {
public GeoTests(ITestOutputHelper output) : base (output) { } public GeoTests(ITestOutputHelper output) : base (output) { }
private ConnectionMultiplexer Create()
{
Skip.IfNoConfig(nameof(TestConfig.Config.AzureCacheServer), TestConfig.Current.AzureCacheServer);
Skip.IfNoConfig(nameof(TestConfig.Config.AzureCachePassword), TestConfig.Current.AzureCachePassword);
var options = new ConfigurationOptions();
options.EndPoints.Add(TestConfig.Current.AzureCacheServer);
options.Ssl = true;
options.ConnectTimeout = 5000;
options.Password = TestConfig.Current.AzureCachePassword;
options.TieBreaker = "";
var log = new StringWriter();
var conn = ConnectionMultiplexer.Connect(options, log);
var s = log.ToString();
Output.WriteLine(s);
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
return conn;
}
public const int Db = 0;
public static GeoEntry public static GeoEntry
palermo = new GeoEntry(13.361389, 38.115556, "Palermo"), palermo = new GeoEntry(13.361389, 38.115556, "Palermo"),
catania = new GeoEntry(15.087269, 37.502669, "Catania"), catania = new GeoEntry(15.087269, 37.502669, "Catania"),
...@@ -42,12 +15,13 @@ public static GeoEntry ...@@ -42,12 +15,13 @@ public static GeoEntry
cefalù = new GeoEntry(14.0188, 38.0084, "Cefalù"); cefalù = new GeoEntry(14.0188, 38.0084, "Cefalù");
public static GeoEntry[] all = { palermo, catania, agrigento, cefalù }; public static GeoEntry[] all = { palermo, catania, agrigento, cefalù };
[AzureTest] [Fact]
public void GeoAdd() public void GeoAdd()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
...@@ -63,12 +37,13 @@ public void GeoAdd() ...@@ -63,12 +37,13 @@ public void GeoAdd()
} }
} }
[AzureTest] [Fact]
public void GetDistance() public void GetDistance()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
db.GeoAdd(key, all); db.GeoAdd(key, all);
...@@ -82,12 +57,13 @@ public void GetDistance() ...@@ -82,12 +57,13 @@ public void GetDistance()
} }
} }
[AzureTest] [Fact]
public void GeoHash() public void GeoHash()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
db.GeoAdd(key, all); db.GeoAdd(key, all);
...@@ -106,12 +82,13 @@ public void GeoHash() ...@@ -106,12 +82,13 @@ public void GeoHash()
} }
} }
[AzureTest] [Fact]
public void GeoGetPosition() public void GeoGetPosition()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
db.GeoAdd(key, all); db.GeoAdd(key, all);
...@@ -126,12 +103,13 @@ public void GeoGetPosition() ...@@ -126,12 +103,13 @@ public void GeoGetPosition()
} }
} }
[AzureTest] [Fact]
public void GeoRemove() public void GeoRemove()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
db.GeoAdd(key, all); db.GeoAdd(key, all);
...@@ -148,12 +126,13 @@ public void GeoRemove() ...@@ -148,12 +126,13 @@ public void GeoRemove()
} }
} }
[AzureTest] [Fact]
public void GeoRadius() public void GeoRadius()
{ {
using (var conn = Create()) using (var conn = Create())
{ {
var db = conn.GetDatabase(Db); Skip.IfMissingFeature(conn, nameof(RedisFeatures.Geo), r => r.Geo);
var db = conn.GetDatabase();
RedisKey key = Me(); RedisKey key = Me();
db.KeyDelete(key); db.KeyDelete(key);
db.GeoAdd(key, all); db.GeoAdd(key, all);
...@@ -187,4 +166,4 @@ public void GeoRadius() ...@@ -187,4 +166,4 @@ public void GeoRadius()
} }
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment