-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathImageDomainValidatorFacts.cs
More file actions
54 lines (49 loc) · 3.57 KB
/
ImageDomainValidatorFacts.cs
File metadata and controls
54 lines (49 loc) · 3.57 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
// 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.
using System;
using Moq;
using Xunit;
namespace NuGetGallery.Services
{
public class ImageDomainValidatorFacts
{
public class GetReadMeHtmlMethod
{
private readonly ImageDomainValidator _imageDomainValidator;
private readonly Mock<IContentObjectService> _contentObjectService;
public GetReadMeHtmlMethod()
{
_contentObjectService = new Mock<IContentObjectService>();
_imageDomainValidator = new ImageDomainValidator(_contentObjectService.Object);
}
[Fact]
public void ThrowsArgumentNullExceptionForNullUrl()
{
Assert.Throws<ArgumentNullException>(() => _imageDomainValidator.TryPrepareImageUrlForRendering(null, out string readyUriString));
}
[Theory]
[InlineData("https://api.codacy.com/example/image.svg", true, "https://api.codacy.com/example/image.svg", true)]
[InlineData("http://api.codacy.com/example/image.svg", true, "https://api.codacy.com/example/image.svg", true)]
[InlineData("http://www.api.codacy.com/example/image.svg", false, null, false)]
[InlineData("https://www.codefactor.io/repository/github/andy840119/Synthesia.MetaDataParser/badge", true, "https://www.codefactor.io/repository/github/andy840119/Synthesia.MetaDataParser/badge", true)]
[InlineData("https://www.api.codefactor.io/repository/github/andy840119/Synthesia.MetaDataParser/badge", false, null, false)]
[InlineData("https://travis-ci.com/Azure/azure-relay-aspnetserver.svg?branch=dev", false, null, false)]
[InlineData("https://github.com/cedx/where.dart/actions/workflows/build.yaml/badge.svg?branch=develop", false, "https://github.com/cedx/where.dart/actions/workflows/build.yaml/badge.svg?branch=develop", true)]
[InlineData("https://[email protected]/peaceiris/actions-gh-pages/actions/workflows/dev-image.yml/something/badge.svg", false, null, false)]
[InlineData("https://github.com/cedx/where.dart/workflows/build.yaml/badge.svg?branch=develop", false, "https://github.com/cedx/where.dart/workflows/build.yaml/badge.svg?branch=develop", true)]
[InlineData("https://[email protected]/peaceiris/actions-gh-pages/workflows/dev-image.yml/something/badge.svg", false, null, false)]
[InlineData("https://bestpractices.dev/projects/1234/badge", true, "https://bestpractices.dev/projects/1234/badge", true)]
[InlineData("http://bestpractices.dev/projects/1234/badge", true, "https://bestpractices.dev/projects/1234/badge", true)]
[InlineData("https://www.bestpractices.dev/projects/1234/badge", true, "https://www.bestpractices.dev/projects/1234/badge", true)]
[InlineData("http://www.bestpractices.dev/projects/1234/badge", true, "https://www.bestpractices.dev/projects/1234/badge", true)]
public void TryPrepareImageUrlForRendering(string input, bool istrusted, string expectedOutput, bool expectConversion)
{
_contentObjectService
.Setup(x => x.TrustedImageDomains.IsImageDomainTrusted(It.IsAny<string>()))
.Returns(istrusted);
Assert.Equal(expectConversion, _imageDomainValidator.TryPrepareImageUrlForRendering(input, out string readyUriString));
Assert.Equal(expectedOutput, readyUriString);
}
}
}
}