Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit c9f771e

Browse files
author
N. Taylor Mullen
committed
- Removed PluginProtocolMessage because it's now handled by the PluginHandler in the DTH. - Updated ProcessMessage to match the new IPlugin contract. This included indicating if a message was handled or not via the return message. - Removed PluginProtocolMessage tests. - Added handled checking to existing tests.
1 parent 247084b commit c9f771e

4 files changed

Lines changed: 17 additions & 47 deletions

File tree

src/Microsoft.AspNet.Tooling.Razor/Models/OutgoingMessages/PluginProtocolMessage.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Microsoft.AspNet.Tooling.Razor/RazorPlugin.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ namespace Microsoft.AspNet.Tooling.Razor
1515
{
1616
public class RazorPlugin : IPlugin
1717
{
18-
private static readonly Version Protocol = new Version(1, 0, 0);
1918
private readonly IPluginMessageBroker _messageBroker;
2019

2120
public RazorPlugin(IPluginMessageBroker messageBroker)
2221
{
2322
_messageBroker = messageBroker;
2423
}
2524

26-
public void ProcessMessage(JObject data, IAssemblyLoadContext assemblyLoadContext)
25+
public int Protocol { get; set; } = 1;
26+
27+
public bool ProcessMessage(JObject data, IAssemblyLoadContext assemblyLoadContext)
2728
{
2829
var message = data.ToObject<RazorPluginRequestMessage>();
2930

@@ -37,9 +38,6 @@ public void ProcessMessage(JObject data, IAssemblyLoadContext assemblyLoadContex
3738

3839
switch (message.MessageType)
3940
{
40-
case RazorPluginMessageTypes.PluginProtocol:
41-
_messageBroker.SendMessage(new PluginProtocolMessage(Protocol));
42-
break;
4341
case RazorPluginMessageTypes.ResolveTagHelperDescriptors:
4442
if (message.Data == null)
4543
{
@@ -86,7 +84,12 @@ public void ProcessMessage(JObject data, IAssemblyLoadContext assemblyLoadContex
8684

8785
_messageBroker.SendMessage(responseMessage);
8886
break;
87+
default:
88+
// Unknown message.
89+
return false;
8990
}
91+
92+
return true;
9093
}
9194
}
9295
}

src/Microsoft.AspNet.Tooling.Razor/RazorPluginMessageTypes.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ namespace Microsoft.AspNet.Tooling.Razor
66
public static class RazorPluginMessageTypes
77
{
88
public const string ResolveTagHelperDescriptors = nameof(ResolveTagHelperDescriptors);
9-
public const string PluginProtocol = nameof(PluginProtocol);
109
}
1110
}

test/Microsoft.AspNet.Tooling.Razor.Tests/RazorPluginTest.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void ProcessMessage_ThrowsWhenNoData()
7070
[Fact]
7171
public void ProcessMessage_NoOpsForUnknownMessageType()
7272
{
73+
// Arrange
7374
var messageData = new JObject();
7475
var message = new JObject
7576
{
@@ -81,9 +82,12 @@ public void ProcessMessage_NoOpsForUnknownMessageType()
8182
var assemblyLoadContext = new TestAssemblyLoadContext();
8283
var plugin = new RazorPlugin(messageBroker);
8384

84-
plugin.ProcessMessage(message, assemblyLoadContext);
85+
// Act
86+
var handled = plugin.ProcessMessage(message, assemblyLoadContext);
8587

88+
// Assert
8689
Assert.False(called);
90+
Assert.False(handled);
8791
}
8892

8993
[Fact]
@@ -131,29 +135,6 @@ public void ProcessMessage_ResolveTagHelperDescriptors_ThrowsWhenNoSourceLocatio
131135
Assert.Equal(expectedMessage, error.Message, StringComparer.Ordinal);
132136
}
133137

134-
[Fact]
135-
public void ProcessMessage_PluginProtocol_ResolvesCurrentProtocol()
136-
{
137-
// Arrange
138-
var message = new JObject
139-
{
140-
{ "MessageType", RazorPluginMessageTypes.PluginProtocol },
141-
};
142-
PluginProtocolMessage responseMessage = null;
143-
var messageBroker = new TestPluginMessageBroker(data => responseMessage = (PluginProtocolMessage)data);
144-
var assemblyLoadContext = new TestAssemblyLoadContext();
145-
var plugin = new RazorPlugin(messageBroker);
146-
147-
// Act
148-
plugin.ProcessMessage(message, assemblyLoadContext);
149-
150-
// Assert
151-
Assert.NotNull(responseMessage);
152-
Assert.Equal(RazorPluginMessageTypes.PluginProtocol, responseMessage.MessageType, StringComparer.Ordinal);
153-
var responseData = responseMessage.Data;
154-
Assert.Equal("1.0.0", responseData, StringComparer.Ordinal);
155-
}
156-
157138
[Fact]
158139
public void ProcessMessage_ResolveTagHelperDescriptors_ResolvesTagHelperDescriptors()
159140
{
@@ -182,7 +163,7 @@ public void ProcessMessage_ResolveTagHelperDescriptors_ResolvesTagHelperDescript
182163
var plugin = new RazorPlugin(messageBroker);
183164

184165
// Act
185-
plugin.ProcessMessage(message, assemblyLoadContext);
166+
var handled = plugin.ProcessMessage(message, assemblyLoadContext);
186167

187168
// Assert
188169
Assert.NotNull(responseMessage);
@@ -195,6 +176,7 @@ public void ProcessMessage_ResolveTagHelperDescriptors_ResolvesTagHelperDescript
195176
var actualDescriptor = Assert.Single(responseData.Descriptors);
196177
Assert.Equal(CustomTagHelperDescriptor, actualDescriptor, TagHelperDescriptorComparer.Default);
197178
Assert.Empty(responseData.Errors);
179+
Assert.True(handled);
198180
}
199181

200182
[Fact]
@@ -220,7 +202,7 @@ public void ProcessMessage_ResolveTagHelperDescriptors_ReturnsErrors()
220202
var plugin = new RazorPlugin(messageBroker);
221203

222204
// Act
223-
plugin.ProcessMessage(message, assemblyLoadContext);
205+
var handled = plugin.ProcessMessage(message, assemblyLoadContext);
224206

225207
// Assert
226208
Assert.NotNull(responseMessage);
@@ -238,6 +220,7 @@ public void ProcessMessage_ResolveTagHelperDescriptors_ReturnsErrors()
238220
StringComparer.Ordinal);
239221
Assert.Equal(expectedSourceLocation, error.Location);
240222
Assert.Equal(1, error.Length);
223+
Assert.True(handled);
241224
}
242225

243226
private class ThrowingAssemblyLoadContext : TestAssemblyLoadContext, IAssemblyLoadContext

0 commit comments

Comments
 (0)