public void ProcessMessage_ResolveTagHelperDescriptors_ReturnsErrors()
        {
            // Arrange
            var expectedSourceLocation = new SourceLocation(absoluteIndex: 1, lineIndex: 2, characterIndex: 3);
            var sourceLocationJson     = JsonConvert.SerializeObject(expectedSourceLocation);
            var messageData            = new JObject
            {
                { "AssemblyName", "invalid" },
                { "SourceLocation", JObject.Parse(sourceLocationJson) }
            };
            var message = new JObject
            {
                { "MessageType", RazorPluginMessageTypes.ResolveTagHelperDescriptors },
                { "Data", messageData },
            };
            ResolveTagHelperDescriptorsMessage responseMessage = null;
            var messageBroker = new TestPluginMessageBroker(
                data => responseMessage = (ResolveTagHelperDescriptorsMessage)data);
            var assemblyLoadContext = new ThrowingAssemblyLoadContext("Invalid assembly");
            var plugin = new RazorPlugin(messageBroker);

            // Act
            var handled = plugin.ProcessMessage(message, assemblyLoadContext);

            // Assert
            Assert.NotNull(responseMessage);
            Assert.Equal(
                RazorPluginMessageTypes.ResolveTagHelperDescriptors,
                responseMessage.MessageType,
                StringComparer.Ordinal);
            var responseData = responseMessage.Data;

            Assert.Equal("invalid", responseData.AssemblyName, StringComparer.Ordinal);
            Assert.Empty(responseData.Descriptors);
            var error = Assert.Single(responseData.Errors);

            Assert.Equal(
                "Cannot resolve TagHelper containing assembly 'invalid'. Error: Invalid assembly: invalid",
                error.Message,
                StringComparer.Ordinal);
            Assert.Equal(expectedSourceLocation, error.Location);
            Assert.Equal(7, error.Length);
            Assert.True(handled);
        }
        public void ProcessMessage_ResolveTagHelperDescriptors_ReturnsErrors()
        {
            // Arrange
            var expectedSourceLocation = new SourceLocation(absoluteIndex: 1, lineIndex: 2, characterIndex: 3);
            var sourceLocationJson = JsonConvert.SerializeObject(expectedSourceLocation);
            var messageData = new JObject
            {
                { "AssemblyName", "invalid" },
                { "SourceLocation", JObject.Parse(sourceLocationJson) }
            };
            var message = new JObject
            {
                { "MessageType", RazorPluginMessageTypes.ResolveTagHelperDescriptors },
                { "Data", messageData },
            };
            ResolveTagHelperDescriptorsMessage responseMessage = null;
            var messageBroker = new TestPluginMessageBroker(
                data => responseMessage = (ResolveTagHelperDescriptorsMessage)data);
            var assemblyLoadContext = new ThrowingAssemblyLoadContext("Invalid assembly");
            var plugin = new RazorPlugin(messageBroker);

            // Act
            var handled = plugin.ProcessMessage(message, assemblyLoadContext);

            // Assert
            Assert.NotNull(responseMessage);
            Assert.Equal(
                RazorPluginMessageTypes.ResolveTagHelperDescriptors,
                responseMessage.MessageType,
                StringComparer.Ordinal);
            var responseData = responseMessage.Data;
            Assert.Equal("invalid", responseData.AssemblyName, StringComparer.Ordinal);
            Assert.Empty(responseData.Descriptors);
            var error = Assert.Single(responseData.Errors);
            Assert.Equal(
                "Cannot resolve TagHelper containing assembly 'invalid'. Error: Invalid assembly: invalid",
                error.Message,
                StringComparer.Ordinal);
            Assert.Equal(expectedSourceLocation, error.Location);
            Assert.Equal(7, error.Length);
            Assert.True(handled);
        }