本文整理汇总了C#中AnalyzeCSharp类的典型用法代码示例。如果您正苦于以下问题:C# AnalyzeCSharp类的具体用法?C# AnalyzeCSharp怎么用?C# AnalyzeCSharp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnalyzeCSharp类属于命名空间,在下文中一共展示了AnalyzeCSharp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TopLevelNamespaceContainsDirectlyNestedNamespaces
public void TopLevelNamespaceContainsDirectlyNestedNamespaces()
{
// Given
string code = @"
namespace Foo
{
}
namespace Foo.Baz
{
}
namespace Bar
{
}
";
IDocument document = GetDocument(code);
IExecutionContext context = GetContext();
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { string.Empty, "Foo", "Baz", "Bar" }, results.Select(x => x["Name"]));
CollectionAssert.AreEquivalent(new [] { "Foo", "Bar" },
results.Single(x => x["Name"].Equals(string.Empty)).Get<IEnumerable<IDocument>>("MemberNamespaces").Select(x => x["Name"]));
}
示例2: TopLevelNamespaceContainsDirectlyNestedNamespaces
public void TopLevelNamespaceContainsDirectlyNestedNamespaces()
{
// Given
string code = @"
namespace Foo
{
}
namespace Foo.Baz
{
}
namespace Bar
{
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(Environment.CurrentDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { string.Empty, "Foo", "Baz", "Bar" }, results.Select(x => x["Name"]));
CollectionAssert.AreEquivalent(new [] { "Foo", "Bar" },
results.Single(x => x["Name"].Equals(string.Empty)).Get<IEnumerable<IDocument>>("MemberNamespaces").Select(x => x["Name"]));
stream.Dispose();
}
示例3: ImplicitMemberAccessibility
public void ImplicitMemberAccessibility()
{
// Given
string code = @"
namespace Foo
{
class Green
{
void Blue()
{
}
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual(@"private void Blue()", GetMember(results, "Green", "Blue")["Syntax"]);
stream.Dispose();
}
示例4: ClassMembersContainsMethods
public void ClassMembersContainsMethods()
{
// Given
string code = @"
namespace Foo
{
public class Blue
{
void Green()
{
}
void Red()
{
}
}
}
";
IDocument document = GetDocument(code);
IExecutionContext context = GetContext();
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { "Green", "Red" },
GetResult(results, "Blue").Get<IReadOnlyList<IDocument>>("Members").Select(x => x["Name"]));
}
示例5: MultiLineSummary
public void MultiLineSummary()
{
// Given
string code = @"
namespace Foo
{
/// <summary>
/// This is a summary.
/// </summary>
class Green
{
}
/// <summary>
/// This is
/// another summary.
/// </summary>
struct Red
{
}
}
";
IDocument document = GetDocument(code);
IExecutionContext context = GetContext();
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual("\n This is a summary.\n ", GetResult(results, "Green")["Summary"]);
Assert.AreEqual("\n This is\n another summary.\n ", GetResult(results, "Red")["Summary"]);
}
示例6: AutoProperty
public void AutoProperty()
{
// Given
string code = @"
namespace Foo
{
class Green
{
public int Blue { get; set; }
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
.Returns(x => new TestDocument((IEnumerable<KeyValuePair<string, object>>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual(@"public int Blue { get; set; }", GetMember(results, "Green", "Blue")["Syntax"]);
stream.Dispose();
}
示例7: AbstractClass
public void AbstractClass()
{
// Given
string code = @"
namespace Foo
{
abstract class Green
{
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual(@"internal abstract class Green", GetResult(results, "Green")["Syntax"]);
stream.Dispose();
}
示例8: ExceptionElementWithoutCref
public void ExceptionElementWithoutCref()
{
// Given
string code = @"
namespace Foo
{
class Green
{
/// <exception>Throws when null</exception>
void Go()
{
}
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual(string.Empty,
GetMember(results, "Green", "Go").List<ReferenceComment>("Exceptions")[0].Name);
Assert.AreEqual("Throws when null",
GetMember(results, "Green", "Go").List<ReferenceComment>("Exceptions")[0].Html);
stream.Dispose();
}
示例9: ClassMembersContainsMethods
public void ClassMembersContainsMethods()
{
// Given
string code = @"
namespace Foo
{
public class Blue
{
void Green()
{
}
void Red()
{
}
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { "Green", "Red" },
GetResult(results, "Blue").Get<IReadOnlyList<IDocument>>("Members").Select(x => x["Name"]));
stream.Dispose();
}
示例10: SingleLineSummary
public void SingleLineSummary()
{
// Given
string code = @"
namespace Foo
{
/// <summary>This is a summary.</summary>
class Green
{
}
/// <summary>This is another summary.</summary>
struct Red
{
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(Environment.CurrentDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual("This is a summary.", GetResult(results, "Green")["Summary"]);
Assert.AreEqual("This is another summary.", GetResult(results, "Red")["Summary"]);
stream.Dispose();
}
示例11: ContainingTypeIsCorrect
public void ContainingTypeIsCorrect()
{
// Given
string code = @"
namespace Foo
{
public class Blue
{
void Green()
{
}
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(Environment.CurrentDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual("Blue", GetMember(results, "Blue", "Green").Get<IDocument>("ContainingType")["Name"]);
stream.Dispose();
}
示例12: FullNameDoesNotContainFullHierarchy
public void FullNameDoesNotContainFullHierarchy()
{
// Given
string code = @"
namespace Foo
{
}
namespace Foo.Bar
{
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
.Returns(x => new TestDocument((IEnumerable<KeyValuePair<string, object>>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { string.Empty, "Foo", "Bar" }, results.Select(x => x["FullName"]));
stream.Dispose();
}
示例13: BaseTypeIsCorrect
public void BaseTypeIsCorrect()
{
// Given
string code = @"
namespace Foo
{
public class Red
{
}
public class Green : Red
{
}
struct Blue
{
}
interface Yellow
{
}
interface Purple : Yellow
{
}
enum Orange
{
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<KeyValuePair<string, object>>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual("Object", results.Single(x => x["Name"].Equals("Red")).Get<IDocument>("BaseType")["Name"]);
Assert.AreEqual("Red", results.Single(x => x["Name"].Equals("Green")).Get<IDocument>("BaseType")["Name"]);
Assert.AreEqual("ValueType", results.Single(x => x["Name"].Equals("Blue")).Get<IDocument>("BaseType")["Name"]);
Assert.IsNull(results.Single(x => x["Name"].Equals("Yellow")).Get<IDocument>("BaseType"));
Assert.IsNull(results.Single(x => x["Name"].Equals("Purple")).Get<IDocument>("BaseType"));
Assert.AreEqual("Enum", results.Single(x => x["Name"].Equals("Orange")).Get<IDocument>("BaseType")["Name"]);
stream.Dispose();
}
示例14: ReturnsAllTypes
public void ReturnsAllTypes()
{
// Given
string code = @"
namespace Foo
{
public class Blue
{
}
class Green
{
class Red
{
}
}
internal struct Yellow
{
}
enum Orange
{
}
}
";
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(code));
IDocument document = Substitute.For<IDocument>();
document.GetStream().Returns(stream);
IExecutionContext context = Substitute.For<IExecutionContext>();
context.InputFolder.Returns(TestContext.CurrentContext.TestDirectory);
context.GetNewDocument(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<MetadataItem>>())
.Returns(x => new TestDocument((IEnumerable<MetadataItem>)x[2]));
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
CollectionAssert.AreEquivalent(new[] { string.Empty, "Foo", "Blue", "Green", "Red", "Yellow", "Orange" }, results.Select(x => x["Name"]));
stream.Dispose();
}
示例15: ImplicitClassAccessibility
public void ImplicitClassAccessibility()
{
// Given
string code = @"
namespace Foo
{
class Green
{
}
}
";
IDocument document = GetDocument(code);
IExecutionContext context = GetContext();
IModule module = new AnalyzeCSharp();
// When
List<IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list
// Then
Assert.AreEqual(@"internal class Green", GetResult(results, "Green")["Syntax"]);
}