diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/Completion/CallbackMethodProviderTests.cs b/Abc.MoqComplete/Abc.MoqComplete.Tests/Completion/CallbackMethodProviderTests.cs index c5c94d9..9017e93 100644 --- a/Abc.MoqComplete/Abc.MoqComplete.Tests/Completion/CallbackMethodProviderTests.cs +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/Completion/CallbackMethodProviderTests.cs @@ -12,6 +12,9 @@ public class CallbackMethodProviderTests: CodeCompletionTestBase [TestCase("callbackCompletion")] [TestCase("callbackCompletion_afterReturn")] + [TestCase("callbackCompletion_afterReturnAsync")] + [TestCase("callbackCompletion_afterReturnAsyncMultiple")] + [TestCase("callbackCompletion_afterReturnAsyncMultiple2")] [TestCase("callbackCompletion_generic")] public void should_fill_with_callback(string testSrc) => DoOneTest(testSrc); } diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs new file mode 100644 index 0000000..2bf7a00 --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync(0) + .c{caret} + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs.gold b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs.gold new file mode 100644 index 0000000..ff99f93 --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsync.cs.gold @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync(0) + .Callback((i,toto,ok) => {{caret}}) + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs new file mode 100644 index 0000000..52c36f3 --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync((i, j, k) => 42) + .c{caret} + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs.gold b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs.gold new file mode 100644 index 0000000..ae23e6d --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple.cs.gold @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync((i, j, k) => 42) + .Callback((i,toto,ok) => {{caret}}) + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs new file mode 100644 index 0000000..8d2a41c --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync((int i, string j, bool k) => 42) + .c{caret} + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs.gold b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs.gold new file mode 100644 index 0000000..25218f2 --- /dev/null +++ b/Abc.MoqComplete/Abc.MoqComplete.Tests/data/CallbackCompletion/callbackCompletion_afterReturnAsyncMultiple2.cs.gold @@ -0,0 +1,25 @@ +// ${COMPLETE_ITEM:Callback((i,toto,ok) => {\})} +using Moq; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace ConsoleApp1.Tests +{ + public interface ITestInterface + { + Task BuildSomething(int i, string toto, bool ok); + } + + [TestFixture] + public class Test1 + { + [Test] + public void METHOD() + { + Mock temp = new Mock(); + temp.Setup(x => x.BuildSomething(It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync((int i, string j, bool k) => 42) + .Callback((i,toto,ok) => {{caret}}) + } + } +} \ No newline at end of file diff --git a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/Callback/BaseCallbackMethodProvider.cs b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/Callback/BaseCallbackMethodProvider.cs index a71080a..e8c57c5 100644 --- a/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/Callback/BaseCallbackMethodProvider.cs +++ b/Abc.MoqComplete/Abc.MoqComplete/CompletionProvider/Callback/BaseCallbackMethodProvider.cs @@ -56,7 +56,7 @@ protected override bool AddLookupItems(CSharpCodeCompletionContext context, IIte var solution = context.BasicContext.Solution; var methodIdentifier = solution.GetComponent(); - if (methodIdentifier.IsMoqReturnMethod(invocation)) + if (methodIdentifier.IsMoqReturnMethod(invocation) || methodIdentifier.IsMoqReturnAsyncMethod(invocation)) { invocation = invocation.InvokedExpression?.FirstChild as IInvocationExpression; } diff --git a/Abc.MoqComplete/Abc.MoqComplete/Services/IMoqMethodIdentifier.cs b/Abc.MoqComplete/Abc.MoqComplete/Services/IMoqMethodIdentifier.cs index d5a33d2..6a34876 100644 --- a/Abc.MoqComplete/Abc.MoqComplete/Services/IMoqMethodIdentifier.cs +++ b/Abc.MoqComplete/Abc.MoqComplete/Services/IMoqMethodIdentifier.cs @@ -9,6 +9,7 @@ public interface IMoqMethodIdentifier bool IsMoqSetupMethod([CanBeNull] IInvocationExpression invocationExpression); bool IsMoqVerifyMethod([CanBeNull] IInvocationExpression invocationExpression); bool IsMoqReturnMethod([CanBeNull] IInvocationExpression invocationExpression); + bool IsMoqReturnAsyncMethod([CanBeNull] IInvocationExpression invocationExpression); bool IsMoqCallbackMethod([CanBeNull] IInvocationExpression invocationExpression); } } diff --git a/Abc.MoqComplete/Abc.MoqComplete/Services/MoqMethodIdentifier.cs b/Abc.MoqComplete/Abc.MoqComplete/Services/MoqMethodIdentifier.cs index 2260a96..ea234d5 100644 --- a/Abc.MoqComplete/Abc.MoqComplete/Services/MoqMethodIdentifier.cs +++ b/Abc.MoqComplete/Abc.MoqComplete/Services/MoqMethodIdentifier.cs @@ -36,6 +36,12 @@ public bool IsMoqReturnMethod(IInvocationExpression invocationExpression) "Method:Moq.Language.IReturns`2.Returns", "Method:Moq.Language.IReturns`1.Returns")); + public bool IsMoqReturnAsyncMethod(IInvocationExpression invocationExpression) + => IsMethod(invocationExpression, + declaredElement => IsMethodStartingWithString(declaredElement, + "Method:Moq.GeneratedReturnsExtensions.ReturnsAsync(Moq.Language.IReturns`2", + "Method:Moq.ReturnsExtensions.ReturnsAsync(Moq.Language.IReturns`2")); + public bool IsMoqCallbackMethod(IInvocationExpression expression) => IsMethod(expression, declaredElement => IsMethodStartingWithString(declaredElement,