CORS/test/Microsoft.AspNetCore.Cors.Test/CorsResultTests.cs

69 строки
2.1 KiB
C#
Исходник Обычный вид История

// Copyright (c) .NET Foundation. All rights reserved.
2015-02-25 04:08:37 +03:00
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Xunit;
namespace Microsoft.AspNetCore.Cors.Infrastructure
2015-02-25 04:08:37 +03:00
{
public class CorsResultTest
{
[Fact]
public void Default_Constructor()
{
// Arrange & Act
var result = new CorsResult();
// Assert
Assert.Empty(result.AllowedHeaders);
Assert.Empty(result.AllowedExposedHeaders);
Assert.Empty(result.AllowedMethods);
Assert.False(result.SupportsCredentials);
Assert.Null(result.AllowedOrigin);
Assert.Null(result.PreflightMaxAge);
}
[Fact]
public void SettingNegativePreflightMaxAge_Throws()
{
// Arrange
var result = new CorsResult();
// Act
var exception = Assert.Throws<ArgumentOutOfRangeException>(() =>
{
result.PreflightMaxAge = TimeSpan.FromSeconds(-1);
});
// Assert
Assert.Equal(
2015-09-03 07:33:47 +03:00
$"PreflightMaxAge must be greater than or equal to 0.{Environment.NewLine}Parameter name: value",
2015-02-25 04:08:37 +03:00
exception.Message);
}
[Fact]
public void ToString_ReturnsThePropertyValues()
{
// Arrange
var corsResult = new CorsResult
{
SupportsCredentials = true,
PreflightMaxAge = TimeSpan.FromSeconds(30),
AllowedOrigin = "*"
};
corsResult.AllowedExposedHeaders.Add("foo");
corsResult.AllowedHeaders.Add("bar");
corsResult.AllowedHeaders.Add("baz");
corsResult.AllowedMethods.Add("GET");
2015-10-08 21:51:12 +03:00
// Act
2015-02-25 04:08:37 +03:00
var result = corsResult.ToString();
// Assert
Assert.Equal(
@"AllowCredentials: True, PreflightMaxAge: 30, AllowOrigin: *," +
" AllowExposedHeaders: {foo}, AllowHeaders: {bar,baz}, AllowMethods: {GET}",
result);
}
}
}