2010-04-08 19:54:41 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Orchard.Commands;
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Tests.Commands {
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class CommandHandlerDescriptorBuilderTests {
|
|
|
|
|
[Test]
|
|
|
|
|
public void BuilderShouldCreateDescriptor() {
|
|
|
|
|
var builder = new CommandHandlerDescriptorBuilder();
|
|
|
|
|
var descriptor = builder.Build(typeof(MyCommand));
|
|
|
|
|
Assert.That(descriptor, Is.Not.Null);
|
|
|
|
|
Assert.That(descriptor.Commands.Count(), Is.EqualTo(4));
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "FooBar"), Is.Not.Null);
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "FooBar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("FooBar")));
|
2010-04-12 17:49:16 -07:00
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "MyCommand"), Is.Not.Null);
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "MyCommand").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("FooBar2")));
|
2010-04-08 19:54:41 -07:00
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "Foo Bar"), Is.Not.Null);
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "Foo Bar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("Foo_Bar")));
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "Foo_Bar"), Is.Not.Null);
|
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "Foo_Bar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("Foo_Bar3")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MyCommand : DefaultOrchardCommandHandler {
|
|
|
|
|
public void FooBar() {
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 17:49:16 -07:00
|
|
|
|
[CommandName("MyCommand")]
|
2010-04-08 19:54:41 -07:00
|
|
|
|
public void FooBar2() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Foo_Bar() {
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 17:49:16 -07:00
|
|
|
|
[CommandName("Foo_Bar")]
|
2010-04-08 19:54:41 -07:00
|
|
|
|
public void Foo_Bar3() {
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-26 18:11:13 -07:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BuilderShouldReturnPublicMethodsOnly() {
|
|
|
|
|
var builder = new CommandHandlerDescriptorBuilder();
|
|
|
|
|
var descriptor = builder.Build(typeof(PublicMethodsOnly));
|
|
|
|
|
Assert.That(descriptor, Is.Not.Null);
|
2010-10-18 15:05:27 -07:00
|
|
|
|
Assert.That(descriptor.Commands.Count(), Is.EqualTo(3));
|
2010-04-26 18:11:13 -07:00
|
|
|
|
Assert.That(descriptor.Commands.Single(d => d.Name == "Method"), Is.Not.Null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PublicMethodsOnly {
|
|
|
|
|
public bool Bar { get; set; } // no accessors
|
|
|
|
|
public bool Field = true; // no field
|
|
|
|
|
|
|
|
|
|
// no private method
|
|
|
|
|
private void Blah() {
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-27 14:44:55 -07:00
|
|
|
|
// no private method
|
|
|
|
|
public static void Foo() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no operator
|
|
|
|
|
public static bool operator ==(PublicMethodsOnly a, PublicMethodsOnly b) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-10-18 14:53:00 -07:00
|
|
|
|
|
2010-04-27 14:44:55 -07:00
|
|
|
|
public static bool operator !=(PublicMethodsOnly a, PublicMethodsOnly b) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-18 14:53:00 -07:00
|
|
|
|
public override int GetHashCode() {
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(Object obj) {
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 18:11:13 -07:00
|
|
|
|
public void Method() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 19:54:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|