Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 0b7c421

Browse files
committed
Don't throw if VsTippingService API has changed
1 parent 04833b9 commit 0b7c421

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/GitHub.Services.Vssdk/Services/TippingService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string m
6464
Assumes.Present(tippingService);
6565
var currentMethod = MethodBase.GetCurrentMethod();
6666
var parameterTypes = currentMethod.GetParameters().Select(p => p.ParameterType).ToArray();
67-
var method = tippingService.GetType().GetMethod(currentMethod.Name, parameterTypes);
67+
var tippingServiceType = tippingService.GetType();
68+
var method = tippingServiceType.GetMethod(currentMethod.Name, parameterTypes);
69+
if (method == null)
70+
{
71+
log.Error("Couldn't find method on {Type} with parameters like {Method}", tippingServiceType, currentMethod);
72+
return;
73+
}
74+
6875
var arguments = new object[] { clientId, calloutId, title, message, isPermanentlyDismissible, anchor,
6976
vsCommandGroupId, vsCommandId };
7077
method.Invoke(tippingService, arguments);

test/GitHub.Services.Vssdk.UnitTests/TippingServiceTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.InteropServices;
23
using NUnit.Framework;
34
using GitHub.Services.Vssdk.Services;
45
using NSubstitute;
@@ -16,5 +17,16 @@ public void No_Exception_When_Cant_Find_SVsTippingService()
1617
Assert.DoesNotThrow(() =>
1718
target.RequestCalloutDisplay(Guid.Empty, "title", "message", true, null, Guid.Empty, 0));
1819
}
20+
21+
[Test]
22+
public void No_Exception_When_Api_Has_Changed()
23+
{
24+
var serviceProvider = Substitute.For<IServiceProvider>();
25+
serviceProvider.GetService(null).ReturnsForAnyArgs(new object());
26+
var target = new TippingService(serviceProvider);
27+
28+
Assert.DoesNotThrow(() =>
29+
target.RequestCalloutDisplay(Guid.Empty, "title", "message", true, null, Guid.Empty, 0));
30+
}
1931
}
2032
}

0 commit comments

Comments
 (0)