public static void GetProtocolAndExecuteViaReflection_void___Should_execute_the_operation___When_called() { // Arrange var operation1Counter = 4; var operation2Counter = 10; var operation1 = new SiblingOperation1 { ActionToRun = () => operation1Counter++, }; var operation2 = new SiblingOperation2 { ActionToRun = () => operation2Counter++, }; var protocolFactory = new ProtocolFactory(); protocolFactory.RegisterProtocolForSupportedOperations(typeof(SiblingOperationProtocol), () => new SiblingOperationProtocol()); // Act, Assert protocolFactory.GetProtocolAndExecuteViaReflection(operation1); operation1Counter.AsTest().Must().BeEqualTo(5); protocolFactory.GetProtocolAndExecuteViaReflection(operation2); operation2Counter.AsTest().Must().BeEqualTo(11); protocolFactory.GetProtocolAndExecuteViaReflection(operation1); operation1Counter.AsTest().Must().BeEqualTo(6); }
public static void GetProtocolAndExecuteViaReflection_TResult___Should_execute_the_operation___When_called() { // Arrange var operation1 = new SiblingOperation3 { Value = 4, }; var operation2 = new SiblingOperation4 { Value = 6, }; var operation3 = new SiblingOperation3 { Value = 1, }; var protocolFactory = new ProtocolFactory(); protocolFactory.RegisterProtocolForSupportedOperations(typeof(SiblingOperationProtocol), () => new SiblingOperationProtocol()); // Act var actual1 = protocolFactory.GetProtocolAndExecuteViaReflection <int>(operation1); var actual2 = protocolFactory.GetProtocolAndExecuteViaReflection <int>(operation2); var actual3 = protocolFactory.GetProtocolAndExecuteViaReflection <int>(operation3); // Assert actual1.AsTest().Must().BeEqualTo(5); actual2.AsTest().Must().BeEqualTo(8); actual3.AsTest().Must().BeEqualTo(2); }