56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
// 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 Microsoft.AspNetCore.Blazor.Browser.Services;
|
|
using System;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNetCore.Blazor.Browser.Test
|
|
{
|
|
public class BrowserUriHelperTest
|
|
{
|
|
private BrowserUriHelper _browserUriHelper = new BrowserUriHelper();
|
|
|
|
[Theory]
|
|
[InlineData("scheme://host/", "scheme://host/")]
|
|
[InlineData("scheme://host:123/", "scheme://host:123/")]
|
|
[InlineData("scheme://host/path", "scheme://host/")]
|
|
[InlineData("scheme://host/path/", "scheme://host/path/")]
|
|
[InlineData("scheme://host/path/page?query=string&another=here", "scheme://host/path/")]
|
|
public void ComputesCorrectBaseUri(string baseUri, string expectedResult)
|
|
{
|
|
var actualResult = BrowserUriHelper.ToBaseUri(baseUri);
|
|
Assert.Equal(expectedResult, actualResult);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("scheme://host/", "scheme://host", "")]
|
|
[InlineData("scheme://host/", "scheme://host/", "")]
|
|
[InlineData("scheme://host/", "scheme://host/path", "path")]
|
|
[InlineData("scheme://host/path/", "scheme://host/path/", "")]
|
|
[InlineData("scheme://host/path/", "scheme://host/path/more", "more")]
|
|
[InlineData("scheme://host/path/", "scheme://host/path", "")]
|
|
public void ComputesCorrectValidBaseRelativePaths(string baseUri, string absoluteUri, string expectedResult)
|
|
{
|
|
var actualResult = _browserUriHelper.ToBaseRelativePath(baseUri, absoluteUri);
|
|
Assert.Equal(expectedResult, actualResult);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("scheme://host/", "otherscheme://host/")]
|
|
[InlineData("scheme://host/", "scheme://otherhost/")]
|
|
[InlineData("scheme://host/path/", "scheme://host/")]
|
|
public void ThrowsForInvalidBaseRelativePaths(string baseUri, string absoluteUri)
|
|
{
|
|
var ex = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
_browserUriHelper.ToBaseRelativePath(baseUri, absoluteUri);
|
|
});
|
|
|
|
Assert.Equal(
|
|
$"The URI '{absoluteUri}' is not contained by the base URI '{baseUri}'.",
|
|
ex.Message);
|
|
}
|
|
}
|
|
}
|