public void GetOrCreate_NoTextDocument_Creates()
        {
            // Arrange
            var uriProvider = new DefaultFileUriProvider(Mock.Of <ITextDocumentFactoryService>());

            // Act
            var uri = uriProvider.GetOrCreate(TextBuffer);

            // Assert
            Assert.NotNull(uri);
        }
        public void TryGet_DoesNotExist_ReturnsFalse()
        {
            // Arrange
            var uriProvider = new DefaultFileUriProvider(Mock.Of <ITextDocumentFactoryService>());

            // Act
            var result = uriProvider.TryGet(TextBuffer, out var uri);

            // Assert
            Assert.False(result);
            Assert.Null(uri);
        }
        public void AddOrUpdate_Adds()
        {
            // Arrange
            var expectedUri = new Uri("C:/path/to/file.razor");
            var uriProvider = new DefaultFileUriProvider(Mock.Of <ITextDocumentFactoryService>());

            // Act
            uriProvider.AddOrUpdate(TextBuffer, expectedUri);

            // Assert
            Assert.True(uriProvider.TryGet(TextBuffer, out var uri));
            Assert.Same(expectedUri, uri);
        }
        public void GetOrCreate_NoTextDocument_MemoizesGeneratedUri()
        {
            // Arrange
            var uriProvider = new DefaultFileUriProvider(Mock.Of <ITextDocumentFactoryService>());

            // Act
            var uri1 = uriProvider.GetOrCreate(TextBuffer);
            var uri2 = uriProvider.GetOrCreate(TextBuffer);

            // Assert
            Assert.NotNull(uri1);
            Assert.Same(uri1, uri2);
        }
        public void GetOrCreate_NoTextDocument_Creates()
        {
            // Arrange
            var textDocumentFactoryService = new Mock <ITextDocumentFactoryService>(MockBehavior.Strict);

            textDocumentFactoryService.Setup(s => s.TryGetTextDocument(TextBuffer, out It.Ref <ITextDocument> .IsAny)).Returns(false);
            var uriProvider = new DefaultFileUriProvider(textDocumentFactoryService.Object);

            // Act
            var uri = uriProvider.GetOrCreate(TextBuffer);

            // Assert
            Assert.NotNull(uri);
        }
        public void TryGet_Exists_ReturnsTrue()
        {
            // Arrange
            var expectedUri = new Uri("C:/path/to/file.razor");
            var uriProvider = new DefaultFileUriProvider(Mock.Of <ITextDocumentFactoryService>(MockBehavior.Strict));

            uriProvider.AddOrUpdate(TextBuffer, expectedUri);

            // Act
            var result = uriProvider.TryGet(TextBuffer, out var uri);

            // Assert
            Assert.True(result);
            Assert.Same(expectedUri, uri);
        }
        public void GetOrCreate_TurnsTextDocumentFilePathIntoUri()
        {
            // Arrange
            var factory          = new Mock <ITextDocumentFactoryService>();
            var expectedFilePath = "C:/path/to/file.razor";
            var textDocument     = Mock.Of <ITextDocument>(document => document.FilePath == expectedFilePath);

            factory.Setup(f => f.TryGetTextDocument(TextBuffer, out textDocument))
            .Returns(true);
            var uriProvider = new DefaultFileUriProvider(factory.Object);

            // Act
            var uri = uriProvider.GetOrCreate(TextBuffer);

            // Assert
            Assert.Equal(expectedFilePath, uri.OriginalString);
        }