예제 #1
0
        protected virtual IReadOnlyCollection <TagHelperDescriptor> ProduceTagHelpersFromDelta(string projectFilePath, int lastResultId, TagHelperDeltaResult deltaResult)
        {
            if (!_resultCache.TryGet(projectFilePath, lastResultId, out var tagHelpers))
            {
                // We most likely haven't made a request to the server yet so there's no delta to apply
                tagHelpers = Array.Empty <TagHelperDescriptor>();

                if (deltaResult.Delta)
                {
                    // We somehow failed to retrieve a cached object yet the server was able to apply a delta. This
                    // is entirely unexpected and means the server & client are catastrophically de-synchronized.
                    throw new InvalidOperationException("This should never happen. Razor server & client are de-synchronized. Tearing down");
                }
            }
            else if (!deltaResult.Delta)
            {
                // Not a delta based response, we should treat it as a "refresh"
                tagHelpers = Array.Empty <TagHelperDescriptor>();
            }

            if (deltaResult.ResultId != lastResultId)
            {
                // New results, lets build a coherent TagHelper collection and then cache it
                tagHelpers = deltaResult.Apply(tagHelpers);
                _resultCache.Set(projectFilePath, deltaResult.ResultId, tagHelpers);
            }

            return(tagHelpers);
        }
예제 #2
0
        public void Apply_AddAndRemoved()
        {
            // Arrange
            var delta = new TagHelperDeltaResult(Delta: true, ResultId: 1337, Project1TagHelpers, Project2TagHelpers);

            // Act
            var tagHelpers = delta.Apply(Project2TagHelpers);

            // Assert
            Assert.Equal(Project1TagHelpers, tagHelpers);
        }
예제 #3
0
        public void Apply_Removed()
        {
            // Arrange
            var delta = new TagHelperDeltaResult(Delta: true, ResultId: 1337, Array.Empty <TagHelperDescriptor>(), Project1TagHelpers);

            // Act
            var tagHelpers = delta.Apply(Project1AndProject2TagHelpers);

            // Assert
            Assert.Equal(Project2TagHelpers, tagHelpers);
        }