// 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 System.Globalization;
using System.IO;
using System.Reflection;
namespace Microsoft.AspNetCore.Mvc.Testing
{
///
/// Metadata that uses to find out the content
/// root for the web application represented by TEntryPoint.
/// will iterate over all the instances of
/// , filter the instances whose
/// is equal to TEntryPoint ,
/// order them by in ascending order.
/// will check for the existence of the marker
/// in Path.Combine(, Path.GetFileName())"
/// and if the file exists it will set the content root to .
///
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
public sealed class WebApplicationFactoryContentRootAttribute : Attribute
{
///
/// Initializes a new instance of .
///
///
/// The key of this . This
/// key is used by to determine what of the
/// instances on the test assembly should be used
/// to match a given TEntryPoint class.
///
/// The path to the content root. This path can be either relative or absolute.
/// In case the path is relative, the path will be combined with
///
///
/// A file that will be use as a marker to determine that the content root path for the given context is correct.
///
///
/// The priority of this content root attribute compared to other attributes. When
/// multiple instances are applied for the
/// same key, they are processed with , ordered in ascending order and applied
/// in priority until a match is found.
///
public WebApplicationFactoryContentRootAttribute(
string key,
string contentRootPath,
string contentRootTest,
string priority)
{
Key = key;
ContentRootPath = contentRootPath;
ContentRootTest = contentRootTest;
if (int.TryParse(priority, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedPriority))
{
Priority = parsedPriority;
}
}
///
/// Gets the key for the content root associated with this project. Typically .
///
public string Key { get; }
///
/// Gets the content root path for a given project. This content root can be relative or absolute. If it is a
/// relative path, it will be combined with .
///
public string ContentRootPath { get; }
///
/// A marker file used to ensure that the path the content root is being set to is correct.
///
public string ContentRootTest { get; }
///
/// Gets a number for determining the probing order when multiple
/// instances with the same key are present on the test .
///
public int Priority { get; }
}
}