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

Commit 04833b9

Browse files
committed
Add first test for TippingService
1 parent cb7b1e2 commit 04833b9

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/GitHub.Services.Vssdk/Services/VsTippingService.cs renamed to src/GitHub.Services.Vssdk/Services/TippingService.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
using System.Reflection;
44
using System.Runtime.InteropServices;
55
using System.Windows;
6+
using GitHub.Logging;
67
using Microsoft;
8+
using Serilog;
79
using IServiceProvider = System.IServiceProvider;
810

911
namespace GitHub.Services.Vssdk.Services
1012
{
1113
public class TippingService : ITippingService
1214
{
15+
static readonly ILogger log = LogManager.ForContext<TippingService>();
16+
1317
// This is the only supported ClientId
1418
readonly Guid ClientId = new Guid("D5D3B674-05BB-4942-B8EC-C3D13B5BD6EE");
1519

@@ -24,7 +28,8 @@ public void RequestCalloutDisplay(Guid calloutId, string title, string message,
2428
bool isPermanentlyDismissible, FrameworkElement targetElement,
2529
Guid vsCommandGroupId, uint vsCommandId)
2630
{
27-
var screenPoint = targetElement.PointToScreen(new Point(targetElement.ActualWidth / 2, 0));
31+
var screenPoint = !Splat.ModeDetector.InUnitTestRunner() ?
32+
targetElement.PointToScreen(new Point(targetElement.ActualWidth / 2, 0)) : default;
2833
var point = new Microsoft.VisualStudio.OLE.Interop.POINT { x = (int)screenPoint.X, y = (int)screenPoint.Y };
2934
RequestCalloutDisplay(ClientId, calloutId, title, message, isPermanentlyDismissible,
3035
point, vsCommandGroupId, vsCommandId);
@@ -50,6 +55,12 @@ void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string m
5055
Microsoft.VisualStudio.OLE.Interop.POINT anchor, Guid vsCommandGroupId, uint vsCommandId)
5156
{
5257
var tippingService = serviceProvider.GetService(typeof(SVsTippingService));
58+
if (tippingService == null)
59+
{
60+
log.Error("Can't find {ServiceType}", typeof(SVsTippingService));
61+
return;
62+
}
63+
5364
Assumes.Present(tippingService);
5465
var currentMethod = MethodBase.GetCurrentMethod();
5566
var parameterTypes = currentMethod.GetParameters().Select(p => p.ParameterType).ToArray();

test/GitHub.Services.Vssdk.UnitTests/GitHub.Services.Vssdk.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<Compile Include="..\Helpers\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
9+
<Compile Include="..\Helpers\SplatModeDetectorSetUp.cs" Link="SplatModeDetectorSetUp.cs" />
910
</ItemGroup>
1011

1112
<ItemGroup>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using NUnit.Framework;
3+
using GitHub.Services.Vssdk.Services;
4+
using NSubstitute;
5+
6+
public class TippingServiceTests
7+
{
8+
public class TheRequestCalloutDisplayMethod
9+
{
10+
[Test]
11+
public void No_Exception_When_Cant_Find_SVsTippingService()
12+
{
13+
var serviceProvider = Substitute.For<IServiceProvider>();
14+
var target = new TippingService(serviceProvider);
15+
16+
Assert.DoesNotThrow(() =>
17+
target.RequestCalloutDisplay(Guid.Empty, "title", "message", true, null, Guid.Empty, 0));
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)