-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathTextDocumentIdentifierTests.cs
62 lines (53 loc) · 2.33 KB
/
TextDocumentIdentifierTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using FluentAssertions;
using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
using Xunit;
namespace Lsp.Tests.Models
{
public class TextDocumentIdentifierTests
{
[Theory, JsonFixture]
public void SimpleTest(string expected)
{
var model = new TextDocumentIdentifier(new Uri("file:///abc/123/d.cs"));
var result = Fixture.SerializeObject(model);
result.Should().Be(expected);
var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject<TextDocumentIdentifier>(expected);
deresult.Should().BeEquivalentTo(model);
}
[Fact]
public void Should_Fail_To_Serialize_When_Given_A_Non_Relative_Uri()
{
var serializer = new Serializer(ClientVersion.Lsp3);
var model = new TextDocumentIdentifier()
{
Uri = new Uri("./abc23.cs", UriKind.Relative),
};
Action a = () => serializer.SerializeObject(model);
a.Should().Throw<JsonSerializationException>();
}
[Fact]
public void Should_Fail_To_Deserialize_When_Given_A_Non_Relative_Uri()
{
var serializer = new Serializer(ClientVersion.Lsp3);
var json = @"{
""uri"":""./0b0jnxg2.kgh.ps1""
}";
Action a = () => serializer.DeserializeObject<TextDocumentIdentifier>(json);
a.Should().Throw<JsonSerializationException>();
}
[Fact]
public void Should_Deserialize_For_Example_Value()
{
var serializer = new Serializer(ClientVersion.Lsp3);
var result = serializer.DeserializeObject<TextDocumentIdentifier>(@"{
""uri"":""file:///Users/tyler/Code/PowerShell/vscode/PowerShellEditorServices/test/PowerShellEditorServices.Test.E2E/bin/Debug/netcoreapp2.1/0b0jnxg2.kgh.ps1""
}");
result.Uri.Should().Be(new Uri("file:///Users/tyler/Code/PowerShell/vscode/PowerShellEditorServices/test/PowerShellEditorServices.Test.E2E/bin/Debug/netcoreapp2.1/0b0jnxg2.kgh.ps1", UriKind.Absolute));
}
}
}