Skip to content
Browse files

More test and minor fixes for IronScriptHost

  • Loading branch information...
1 parent 5ae59e8 commit ff8278992f71819a24b0eb1d9f1c8f89648aa7a4 @kmees kmees committed Mar 8, 2013
View
23 src/IronSharePoint.Framework/Administration/HiveSetup.cs
@@ -1,5 +1,8 @@
using System;
+using System.Collections.Generic;
+using IronSharePoint.Hives;
using Microsoft.SharePoint.Administration;
+using System.Linq;
namespace IronSharePoint.Administration
{
@@ -74,7 +77,8 @@ public int Priority
protected bool Equals(HiveSetup other)
{
- return Equals(_hiveArguments, other._hiveArguments) && Equals(_hiveType, other._hiveType);
+ return (_hiveArguments ?? new object[0]).SequenceEqual(other._hiveArguments ?? new object[0])
+ && Equals(_hiveType, other._hiveType);
}
public override bool Equals(object obj)
@@ -92,5 +96,22 @@ public override int GetHashCode()
return ((_hiveArguments != null ? _hiveArguments.GetHashCode() : 0)*397) ^ (_hiveType != null ? _hiveType.GetHashCode() : 0);
}
}
+
+ /// <summary>
+ /// Hive Setup for the IronSP Ruby Framework
+ /// </summary>
+ public static HiveSetup IronSPRoot
+ {
+ get
+ {
+ return new HiveSetup
+ {
+ DisplayName = "IronSP Root",
+ Description = "Contains the Ruby part of the IronSP Framework",
+ HiveArguments = new object[] {IronConstant.IronSPRootDirectory},
+ HiveType = typeof (PhysicalHive)
+ };
+ }
+ }
}
}
View
47 src/IronSharePoint.Framework/IronScriptHost.cs
@@ -4,6 +4,7 @@
using System.Linq;
using IronSharePoint.Administration;
using IronSharePoint.Hives;
+using IronSharePoint.Util;
using Microsoft.Scripting.Hosting;
using Microsoft.SharePoint.Administration;
@@ -34,35 +35,39 @@ public override Microsoft.Scripting.PlatformAdaptationLayer PlatformAdaptationLa
private IHive CreateHive()
{
- var hives = CreateHivesFromRegistry().ToList();
+ var hives = GetHiveSetups().OrderBy(x => x.Priority).Select(x =>
+ {
+ var argTypes = x.HiveArguments.Select(y => y.GetType()).ToArray();
+ var ctor = x.HiveType.GetConstructor(argTypes);
+ return ctor != null ? (IHive) ctor.Invoke(x.HiveArguments) : null;
+ }).Compact().ToArray();
- if (!hives.Any(x => x is PhysicalHive &&
- (x as PhysicalHive).Root == IronConstant.IronSPRootDirectory))
- {
- var spRootHive = new PhysicalHive(IronConstant.IronSPRootDirectory);
- hives.Add(spRootHive);
- }
+ return new OrderedHiveList(hives);
+ }
- return new OrderedHiveList(hives.ToArray());
+ private HiveSetupCollection GetHiveSetups()
+ {
+ var hiveSetups = GetHiveSetupsFromRegistry();
+
+ var ironSPRootHiveSetup = new HiveSetup()
+ {
+ DisplayName = "IronSP Root",
+ HiveArguments = new object[] {IronConstant.IronSPRootDirectory},
+ HiveType = typeof (PhysicalHive)
+ };
+ if (!hiveSetups.Contains(ironSPRootHiveSetup)) hiveSetups.Add(ironSPRootHiveSetup);
+ return hiveSetups;
}
- private IEnumerable<IHive> CreateHivesFromRegistry()
+ private HiveSetupCollection GetHiveSetupsFromRegistry()
{
var registry = HiveRegistry.Local;
- try
- {
- var descriptions = registry.GetMappedHivesForSite(_siteId).OrderBy(x => x.Priority);
- return descriptions.Select(x =>
- {
- var argTypes = x.HiveArguments.Select(y => y.GetType()).ToArray();
- var ctor = x.HiveType.GetConstructor(argTypes);
- return (IHive) ctor.Invoke(x.HiveArguments);
- });
- }
- catch (ArgumentException)
+ HiveSetupCollection setups;
+ if (!registry.TryGetHiveSetups(_siteId, out setups))
{
- return new IHive[0];
+ setups = new HiveSetupCollection();
}
+ return setups;
}
}
}
View
124 test/IronSharePoint.Framework.Test/Administration/HiveSetupCollection_Fixture.cs
@@ -0,0 +1,124 @@
+using System;
+using FluentAssertions;
+using IronSharePoint.Administration;
+using IronSharePoint.Hives;
+using Moq;
+using NUnit.Framework;
+
+namespace IronSharePoint.Framework.Test.Administration
+{
+ [TestFixture]
+ public class HiveSetupCollection_Fixture
+ {
+ HiveSetupCollection Sut;
+
+ public HiveSetup HiveSetup;
+ public HiveSetup OtherHiveSetup;
+
+ [SetUp]
+ public void SetUp()
+ {
+ Sut = new HiveSetupCollection();
+
+ HiveSetup = new HiveSetup()
+ {
+ DisplayName = "Test Hive",
+ HiveType = typeof(SPDocumentHive),
+ HiveArguments = new object[] { new Guid("23D9567E-AA85-45E8-A21E-522B18B4CCF2") }
+ };
+ OtherHiveSetup = new HiveSetup()
+ {
+ DisplayName = "Other Test Hive",
+ HiveType = typeof(SPDocumentHive),
+ HiveArguments = new object[] { new Guid("DB479166-77D4-484B-B3A4-D839E5824008") }
+ };
+ }
+
+ [Test]
+ public void AddItem_EnsuresTrustedHive()
+ {
+ var registryMock = new Mock<HiveRegistry>();
+ registryMock.Setup(x => x.EnsureTrustedHive(HiveSetup)).Verifiable();
+ Sut.Registry = registryMock.Object;
+
+ Sut.Add(HiveSetup);
+
+ registryMock.VerifyAll();
+ }
+
+ [Test]
+ public void AddItem_UpdatesHiveSetupPriority()
+ {
+ HiveSetup.Priority = -1;
+
+ Sut.Add(HiveSetup);
+
+ HiveSetup.Priority.Should().Be(0);
+ }
+
+ [Test]
+ public void RemoveItem_UpdatesRemainingHiveSetupPriorities()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+ Sut.Remove(HiveSetup);
+
+ OtherHiveSetup.Priority.Should().Be(0);
+ }
+
+ [Test]
+ public void Swap_SwapsItems()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+
+ Sut.Swap(0, 1);
+
+ Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
+ }
+
+ [Test]
+ public void MoveUp_MovesItemAtIndexOneUp()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+
+ Sut.MoveUp(1);
+
+ Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
+ }
+
+ [Test]
+ public void MoveUp_WithFirstItem_DoesNothing()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+
+ Sut.MoveUp(0);
+
+ Sut.Should().ContainInOrder(new[] {HiveSetup, OtherHiveSetup});
+ }
+
+ [Test]
+ public void MoveDown_MovesItemAtIndexOneDown()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+
+ Sut.MoveDown(0);
+
+ Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
+ }
+
+ [Test]
+ public void MoveDown_WithLastItem_DoesNothing()
+ {
+ Sut.Add(HiveSetup);
+ Sut.Add(OtherHiveSetup);
+
+ Sut.MoveDown(1);
+
+ Sut.Should().ContainInOrder(new[] { HiveSetup, OtherHiveSetup });
+ }
+ }
+}
View
137 test/IronSharePoint.Framework.Test/Administration/HiveSetup_Fixture.cs
@@ -1,149 +1,64 @@
using System;
using IronSharePoint.Administration;
using IronSharePoint.Hives;
-using Moq;
using NUnit.Framework;
using FluentAssertions;
namespace IronSharePoint.Framework.Test.Administration
{
[TestFixture]
- public class HiveSetupCollection_Fixture
+ public class HiveSetup_Fixture
{
- HiveSetupCollection Sut;
-
- public HiveSetup HiveSetup;
- public HiveSetup OtherHiveSetup;
-
- [SetUp]
- public void SetUp()
- {
- Sut = new HiveSetupCollection();
-
- HiveSetup = new HiveSetup()
- {
- DisplayName = "Test Hive",
- HiveType = typeof(SPDocumentHive),
- HiveArguments = new object[] { new Guid("23D9567E-AA85-45E8-A21E-522B18B4CCF2") }
- };
- OtherHiveSetup = new HiveSetup()
- {
- DisplayName = "Other Test Hive",
- HiveType = typeof(SPDocumentHive),
- HiveArguments = new object[] { new Guid("DB479166-77D4-484B-B3A4-D839E5824008") }
- };
- }
-
- [Test]
- public void AddItem_EnsuresTrustedHive()
- {
- var registryMock = new Mock<HiveRegistry>();
- registryMock.Setup(x => x.EnsureTrustedHive(HiveSetup)).Verifiable();
- Sut.Registry = registryMock.Object;
-
- Sut.Add(HiveSetup);
-
- registryMock.VerifyAll();
- }
-
- [Test]
- public void AddItem_UpdatesHiveSetupPriority()
- {
- HiveSetup.Priority = -1;
-
- Sut.Add(HiveSetup);
-
- HiveSetup.Priority.Should().Be(0);
- }
-
- [Test]
- public void RemoveItem_UpdatesRemainingHiveSetupPriorities()
- {
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
- Sut.Remove(HiveSetup);
-
- OtherHiveSetup.Priority.Should().Be(0);
- }
-
- [Test]
- public void Swap_SwapsItems()
- {
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
-
- Sut.Swap(0, 1);
-
- Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
- }
+ public HiveSetup Sut;
[Test]
- public void MoveUp_MovesItemAtIndexOneUp()
+ [ExpectedException(typeof(ArgumentException))]
+ public void HiveType_WithTypeNotImplementingIHive_ThrowsArgumentException()
{
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
-
- Sut.MoveUp(1);
-
- Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
+ Sut = new HiveSetup
+ {
+ HiveType = typeof (Object)
+ };
}
[Test]
- public void MoveUp_WithFirstItem_DoesNothing()
+ public void HiveType_WithTypeImplementingIHive_SetsValue()
{
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
-
- Sut.MoveUp(0);
-
- Sut.Should().ContainInOrder(new[] {HiveSetup, OtherHiveSetup});
+ Sut = new HiveSetup
+ {
+ HiveType = typeof (SPDocumentHive)
+ };
}
[Test]
- public void MoveDown_MovesItemAtIndexOneDown()
+ public void IronSPRoot_HiveArgument_ReturnIronSPRootDirectory()
{
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
+ HiveSetup.IronSPRoot.HiveArguments.Should().ContainInOrder(new[] {IronConstant.IronSPRootDirectory});
- Sut.MoveDown(0);
-
- Sut.Should().ContainInOrder(new[] {OtherHiveSetup, HiveSetup});
}
[Test]
- public void MoveDown_WithLastItem_DoesNothing()
+ public void IronSPRoot_HiveType_IsPysicalHive()
{
- Sut.Add(HiveSetup);
- Sut.Add(OtherHiveSetup);
-
- Sut.MoveDown(1);
+ HiveSetup.IronSPRoot.HiveType.Should().Be(typeof (PhysicalHive));
- Sut.Should().ContainInOrder(new[] { HiveSetup, OtherHiveSetup });
}
- }
-
- [TestFixture]
- public class HiveSetup_Fixture
- {
- public HiveSetup Sut;
[Test]
- [ExpectedException(typeof(ArgumentException))]
- public void HiveType_WithTypeNotImplementingIHive_ThrowsArgumentException()
+ public void Equals_WhenHiveTypeAndHiveArgumentAreEqual_ReturnsTrue()
{
- Sut = new HiveSetup
+ var hiveSetup = new HiveSetup
{
- HiveType = typeof (Object)
+ HiveType = typeof (PhysicalHive),
+ HiveArguments = new object[] {1}
};
- }
-
- [Test]
- public void HiveType_WithTypeImplementingIHive_SetsValue()
- {
- Sut = new HiveSetup
+ var otherHiveSetup = new HiveSetup
{
- HiveType = typeof (SPDocumentHive)
+ HiveType = typeof (PhysicalHive),
+ HiveArguments = new object[] {1}
};
+
+ hiveSetup.Equals(otherHiveSetup).Should().BeTrue();
}
}
}
View
86 test/IronSharePoint.Framework.Test/IronScriptHost_Fixture.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using IronSharePoint.Administration;
+using IronSharePoint.Hives;
+using NUnit.Framework;
+using TypeMock.ArrangeActAssert;
+using FluentAssertions;
+
+namespace IronSharePoint.Framework.Test
+{
+ [TestFixture]
+ public class IronScriptHost_Fixture
+ {
+ IronScriptHost Sut;
+
+ [Test]
+ public void Hive_WhenNoHiveSetupsInRegistry_ContainsOnlyIronSPRootHive()
+ {
+ var siteId = Guid.NewGuid();
+ var hiveSetups = new HiveSetupCollection();
+ Isolate.Fake.StaticMethods<HiveRegistry>(Members.ReturnRecursiveFakes);
+ var registry = HiveRegistry.Local;
+ Isolate.WhenCalled(() => registry.TryGetHiveSetups(siteId, out hiveSetups)).WillReturn(true);
+
+ Sut = new IronScriptHost(siteId);
+
+ Sut.Hive.Should().BeOfType<OrderedHiveList>();
+ (Sut.Hive as OrderedHiveList).Should()
+ .Contain(
+ hive =>
+ hive is PhysicalHive &&
+ (hive as PhysicalHive).Root == IronConstant.IronSPRootDirectory);
+ }
+
+ [Test]
+ public void Hive_WhenOneHiveSetup_CreatesHiveFromSetup()
+ {
+ var siteId = Guid.NewGuid();
+ var hiveSetups = new HiveSetupCollection()
+ {
+ new HiveSetup()
+ {
+ HiveType = typeof(PhysicalHive),
+ HiveArguments = new[]{"c:\\"}
+ }
+ };
+ Isolate.Fake.StaticMethods<HiveRegistry>(Members.ReturnRecursiveFakes);
+ var registry = HiveRegistry.Local;
+ Isolate.WhenCalled(() => registry.TryGetHiveSetups(siteId, out hiveSetups)).WillReturn(true);
+
+ Sut = new IronScriptHost(siteId);
+
+ Sut.Hive.Should().BeOfType<OrderedHiveList>();
+ (Sut.Hive as OrderedHiveList).Should()
+ .Contain(
+ hive =>
+ hive is PhysicalHive &&
+ (hive as PhysicalHive).Root == "c:\\");
+ }
+
+ [Test]
+ public void Hive_WhenRegistryHasIronSPRootSetup_DoesntCreateItTwice()
+ {
+ var siteId = Guid.NewGuid();
+ var hiveSetups = new HiveSetupCollection()
+ {
+ HiveSetup.IronSPRoot
+ };
+ Isolate.Fake.StaticMethods<HiveRegistry>(Members.ReturnRecursiveFakes);
+ var registry = HiveRegistry.Local;
+ Isolate.WhenCalled(() => registry.TryGetHiveSetups(siteId, out hiveSetups)).WillReturn(true);
+
+ Sut = new IronScriptHost(siteId);
+
+ Sut.Hive.Should().BeOfType<OrderedHiveList>();
+ (Sut.Hive as OrderedHiveList).Should()
+ .ContainSingle(
+ hive =>
+ hive is PhysicalHive &&
+ (hive as PhysicalHive).Root == IronConstant.IronSPRootDirectory);
+ }
+ }
+}
View
4 test/IronSharePoint.Framework.Test/IronSharePoint.Framework.Test.csproj
@@ -63,13 +63,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Administration\HiveSetupCollection_Fixture.cs" />
<Compile Include="Administration\HiveSetup_Fixture.cs" />
<Compile Include="Administration\HiveRegistry_Fixture.cs" />
- <Compile Include="Dummy.cs" />
<Compile Include="Hive\OrderedHiveList_Fixture.cs" />
<Compile Include="Hive\PhysicalHive_Fixture.cs" />
<Compile Include="Hive\SPDocumentHive_Fixture.cs" />
+ <Compile Include="IronScriptHost_Fixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Util\EnumerableExtensions_Fixture.cs" />
<Compile Include="Util\StringExtensions_Fixture.cs" />
</ItemGroup>
<ItemGroup>
View
16 test/IronSharePoint.Framework.Test/Util/EnumerableExtensions_Fixture.cs
@@ -0,0 +1,16 @@
+using FluentAssertions;
+using IronSharePoint.Util;
+using NUnit.Framework;
+
+namespace IronSharePoint.Framework.Test.Util
+{
+ [TestFixture]
+ public class EnumerableExtensions_Fixture
+ {
+ [Test]
+ public void Compact_RemovesAllNulls()
+ {
+ new[] {"Foo", null, "Bar", null}.Compact().Should().ContainInOrder(new[] {"Foo", "Bar"});
+ }
+ }
+}

0 comments on commit ff82789

Please sign in to comment.
Something went wrong with that request. Please try again.