mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixing RunningShellTableTests after multi-tenancy change to allow for comma-separated lists of tenants.
--HG-- branch : 1.x
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Tests.Stubs;
|
||||
@@ -19,7 +20,7 @@ namespace Orchard.Tests.Environment {
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
table.Add(settings);
|
||||
var match = table.Match(new StubHttpContext());
|
||||
Assert.That(match, Is.SameAs(settings));
|
||||
Assert.That(match, Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -30,7 +31,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "a.example.com"));
|
||||
Assert.That(match, Is.SameAs(settingsA));
|
||||
Assert.That(match, Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -41,7 +42,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "b.example.com"));
|
||||
Assert.That(match, Is.SameAs(settings));
|
||||
Assert.That(match, Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -63,7 +64,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "www.example.com"));
|
||||
Assert.That(match, Is.EqualTo(settings));
|
||||
Assert.That(match, Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -74,7 +75,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "b.example.com"));
|
||||
Assert.That(match, Is.EqualTo(settingsA));
|
||||
Assert.That(match, Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -89,7 +90,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settingsB);
|
||||
table.Add(settingsG);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "a.example.com"));
|
||||
Assert.That(match, Is.EqualTo(settings));
|
||||
Assert.That(match, Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -115,7 +116,7 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
var match = table.Match(new StubHttpContext("~/foo/bar", "a.example.com"));
|
||||
Assert.That(match, Is.SameAs(settingsA));
|
||||
Assert.That(match, Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -132,19 +133,19 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settingsG);
|
||||
table.Add(settingsD);
|
||||
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.SameAs(settingsB));
|
||||
Assert.That(table.Match(new StubHttpContext("~/baaz", "wiki.example.com")), Is.SameAs(settingsG));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "www.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/baaz", "www.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/baaz", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/baaz", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "a.example.com")), Is.Null);
|
||||
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "wiki.example.com")), Is.SameAs(settingsG));
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "www.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "a.example.com")), Is.SameAs(settingsD));
|
||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "wiki.example.com")), Is.SameAs(settingsG));
|
||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "www.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/quux/quad", "a.example.com")), Is.EqualTo(settingsD).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "www.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/yarg", "a.example.com")), Is.Null);
|
||||
}
|
||||
|
||||
@@ -154,7 +155,7 @@ namespace Orchard.Tests.Environment {
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlPrefix = "~/foo" };
|
||||
table.Add(settingsA);
|
||||
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/bar/foo", "wiki.example.com")), Is.Null);
|
||||
}
|
||||
|
||||
@@ -165,10 +166,10 @@ namespace Orchard.Tests.Environment {
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -183,10 +184,10 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settingsB);
|
||||
table.Add(settingsG);
|
||||
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.SameAs(settingsA));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.SameAs(settingsG));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "username.example.com")), Is.SameAs(settingsB));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.EqualTo(settingsA).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "wiki.example.com")), Is.EqualTo(settingsG).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "username.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
|
||||
@@ -200,9 +201,42 @@ namespace Orchard.Tests.Environment {
|
||||
table.Add(settingsA);
|
||||
table.Add(settingsB);
|
||||
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "removed.example.com")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "added.example.com")), Is.SameAs(settingsB));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.SameAs(settings));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "removed.example.com")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "added.example.com")), Is.EqualTo(settingsB).Using(new ShellComparer()));
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.EqualTo(settings).Using(new ShellComparer()));
|
||||
}
|
||||
|
||||
public class ShellComparer : IEqualityComparer<ShellSettings> {
|
||||
public bool Equals(ShellSettings x, ShellSettings y) {
|
||||
return x == y || (
|
||||
x != null && y != null &&
|
||||
x.DataConnectionString == y.DataConnectionString &&
|
||||
x.DataProvider == y.DataProvider &&
|
||||
x.DataTablePrefix == y.DataTablePrefix &&
|
||||
x.EncryptionAlgorithm == y.EncryptionAlgorithm &&
|
||||
x.EncryptionKey == y.EncryptionKey &&
|
||||
x.HashAlgorithm == y.HashAlgorithm &&
|
||||
x.HashKey == y.HashKey &&
|
||||
x.Name == y.Name &&
|
||||
x.RequestUrlHost == y.RequestUrlHost &&
|
||||
x.RequestUrlPrefix == y.RequestUrlPrefix &&
|
||||
x.State == y.State
|
||||
);
|
||||
}
|
||||
|
||||
public int GetHashCode(ShellSettings obj) {
|
||||
return obj.DataConnectionString.GetHashCode() ^
|
||||
obj.DataProvider.GetHashCode() ^
|
||||
obj.DataTablePrefix.GetHashCode() ^
|
||||
obj.EncryptionAlgorithm.GetHashCode() ^
|
||||
obj.EncryptionKey.GetHashCode() ^
|
||||
obj.HashAlgorithm.GetHashCode() ^
|
||||
obj.HashKey.GetHashCode() ^
|
||||
obj.Name.GetHashCode() ^
|
||||
obj.RequestUrlHost.GetHashCode() ^
|
||||
obj.RequestUrlPrefix.GetHashCode() ^
|
||||
obj.State.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace Orchard.Environment {
|
||||
_shells.Where(x => string.IsNullOrEmpty(x.RequestUrlHost) && string.IsNullOrEmpty(x.RequestUrlPrefix));
|
||||
|
||||
_shellsByHost = qualified
|
||||
.SelectMany(s =>
|
||||
.SelectMany(s => s.RequestUrlHost == null || s.RequestUrlHost.IndexOf(',') == -1 ? new[] {s} :
|
||||
s.RequestUrlHost.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(h => new ShellSettings(s) {RequestUrlHost = h}))
|
||||
.GroupBy(s => s.RequestUrlHost ?? "")
|
||||
|
||||
Reference in New Issue
Block a user