public static async Task ExecuteViaReflectionAsync_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 protocol = new SiblingOperationProtocol(); // Act var actual1 = await protocol.ExecuteViaReflectionAsync <int>(operation1); var actual2 = await protocol.ExecuteViaReflectionAsync <int>(operation2); var actual3 = await protocol.ExecuteViaReflectionAsync <int>(operation3); // Assert actual1.AsTest().Must().BeEqualTo(7); actual2.AsTest().Must().BeEqualTo(10); actual3.AsTest().Must().BeEqualTo(4); }
public static async Task ExecuteViaReflectionAsync_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 protocol = new SiblingOperationProtocol(); // Act, Assert await protocol.ExecuteViaReflectionAsync(operation1); operation1Counter.AsTest().Must().BeEqualTo(6); await protocol.ExecuteViaReflectionAsync(operation2); operation2Counter.AsTest().Must().BeEqualTo(12); await protocol.ExecuteViaReflectionAsync(operation1); operation1Counter.AsTest().Must().BeEqualTo(8); }
public static async Task ExecuteViaReflectionAsync_TResult___Should_throw_ArgumentException___When_protocol_cannot_execute_operation() { // Arrange var operation = new DummyReturningOperation(); var protocol1 = new ProtocolWithNoOperations(); var protocol2 = new SiblingOperationProtocol(); // Act var actual1 = await Record.ExceptionAsync(() => protocol1.ExecuteViaReflectionAsync <int>(operation)); var actual2 = await Record.ExceptionAsync(() => protocol2.ExecuteViaReflectionAsync <int>(operation)); // Assert actual1.AsTest().Must().BeOfType <ArgumentException>(); actual1.Message.AsTest().Must().ContainString(Invariant($"The specified '{nameof(ProtocolExtensionsTest)}.{nameof(ProtocolWithNoOperations)}' protocol does not have a returning ExecuteAsync method with a single parameter that the specified '{nameof(ProtocolExtensionsTest)}.{nameof(DummyReturningOperation)}' operation is assignable to AND a return type that is assignable to the specified 'int' return type.")); actual2.AsTest().Must().BeOfType <ArgumentException>(); actual2.Message.AsTest().Must().ContainString(Invariant($"The specified '{nameof(ProtocolExtensionsTest)}.{nameof(SiblingOperationProtocol)}' protocol does not have a returning ExecuteAsync method with a single parameter that the specified '{nameof(ProtocolExtensionsTest)}.{nameof(DummyReturningOperation)}' operation is assignable to AND a return type that is assignable to the specified 'int' return type.")); }