-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathOwnerDetailsUriTemplateResourceV3Tests.cs
More file actions
116 lines (93 loc) · 3.65 KB
/
OwnerDetailsUriTemplateResourceV3Tests.cs
File metadata and controls
116 lines (93 loc) · 3.65 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using FluentAssertions;
using NuGet.Protocol.Resources;
using Xunit;
namespace NuGet.Protocol.Tests.Resources
{
public class OwnerDetailsUriTemplateResourceV3Tests
{
private readonly Uri _template = new Uri("https://nuget.test/profiles/{owner}?_src=template");
[Fact]
public void CreateOrNull_WhenNullTemplate_Throws()
{
// Arrange
Uri? template = null;
// Act & Assert
Assert.Throws<ArgumentNullException>(() => OwnerDetailsUriTemplateResourceV3.CreateOrNull(template!));
}
[Fact]
public void CreateOrNull_WhenTemplateNotAbsoluteUri_CreatesNullResource()
{
// Arrange
var template = new Uri("/owner/profile", UriKind.Relative);
// Act
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(template);
// Assert
target.Should().BeNull();
}
[Fact]
public void CreateOrNull_WhenTemplateNotHttps_CreatesNullResource()
{
// Arrange
var template = new Uri("http://nuget.test/profiles/{owner}?_src=template");
// Act
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(template);
// Assert
target.Should().BeNull();
}
[Fact]
public void CreateOrNull_WhenValidTemplateHttps_CreatesResource()
{
// Arrange & Act
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(_template);
// Assert
target.Should().NotBeNull();
}
[Fact]
public void GetUri_WithSpacesInOwnerParameter_CreatesValidOwnerUriWithEncoding()
{
// Arrange
string owner = "Microsoft Microsoft Microsoft";
string formattedOwner = "Microsoft%20Microsoft%20Microsoft";
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(_template);
// Act
Uri ownerUri = target!.GetUri(owner);
// Assert
ownerUri.Should().NotBeNull();
ownerUri.IsAbsoluteUri.Should().BeTrue();
ownerUri.AbsoluteUri.Should().Be($"https://nuget.test/profiles/{formattedOwner}?_src=template");
}
[Theory]
[InlineData("microsoft")]
[InlineData("MiCroSoFT")]
public void GetUri_WithValidOwnerParameter_CreatesValidOwnerUriWithSameCasing(string owner)
{
// Arrange
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(_template);
// Act
Uri ownerUri = target!.GetUri(owner);
// Assert
ownerUri.Should().NotBeNull();
ownerUri.IsAbsoluteUri.Should().BeTrue();
ownerUri.AbsoluteUri.Should().Be($"https://nuget.test/profiles/{owner}?_src=template");
}
[Theory]
[InlineData(null)]
[InlineData("")]
public void GetUri_WithInvalidOwnerParameter_ReturnsOriginalTemplate(string owner)
{
// Arrange
var target = OwnerDetailsUriTemplateResourceV3.CreateOrNull(_template);
string templateWithoutOwner = "https://nuget.test/profiles/?_src=template";
// Act
Uri ownerUri = target!.GetUri(owner);
// Assert
ownerUri.Should().NotBeNull();
ownerUri.IsAbsoluteUri.Should().BeTrue();
ownerUri.AbsoluteUri.Should().Be(templateWithoutOwner);
}
}
}