public async Task AddBackingFieldWhenNameCollision()
        {
            var testCode = @"
namespace RoslynSandbox
{
    public class Foo
    {
        private int value;

        public int Value { get; set; }
    }
}";
            var sln      = CodeFactory.CreateSolution(testCode);
            var editor   = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var property = editor.OriginalRoot.SyntaxTree.FindPropertyDeclaration("Value");
            var field    = editor.AddBackingField(property, usesUnderscoreNames: false, cancellationToken: CancellationToken.None);

            Assert.AreEqual("privateint value_;", field.ToFullString());
            var expected = @"
namespace RoslynSandbox
{
    public class Foo
    {
        private int value;
        private int value_;

        public int Value { get; set; }
    }
}";

            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #2
0
        public SiteMapNode(System.Web.SiteMapProvider provider, CodeFactory.Web.Core.IPublishable<Guid> node)
            : base(provider, node.ID.ToString(), node.RelativeLink, node.Title, node.Description)
        {
            _node = node;

            this.Roles = !_node.ID.Equals(Guid.Empty) && _node.Roles.Count > 0 ? _node.Roles : new List<string>(new string[] { "*" });
        }
            public void CreateSolutionFromClassLibrary1()
            {
                Assert.AreEqual(true, ProjectFile.TryFind("ClassLibrary1.csproj", out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new FieldNameMustNotBeginWithUnderscore(), },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual("ClassLibrary1", solution.Projects.Single().Name);
                var expected = new[]
                {
                    "AllowCompilationErrors.cs",
                    "AssemblyInfo.cs",
                    "ClassLibrary1Class1.cs",
                };
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
Пример #4
0
            public void SingleClassNoErrorAnalyzer()
            {
                var code     = @"
namespace RoslynSandbox
{
    class Foo
    {
    }
}";
                var analyzer = new NoErrorAnalyzer();

                AnalyzerAssert.Valid <NoErrorAnalyzer>(code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), code);
                AnalyzerAssert.Valid(analyzer, code);
                AnalyzerAssert.Valid(analyzer, code, CodeFactory.DefaultCompilationOptions(analyzer, AnalyzerAssert.SuppressedDiagnostics), AnalyzerAssert.MetadataReferences);
                AnalyzerAssert.Valid(analyzer, new[] { code }, CodeFactory.DefaultCompilationOptions(analyzer, AnalyzerAssert.SuppressedDiagnostics), AnalyzerAssert.MetadataReferences);

                var descriptor = NoErrorAnalyzer.Descriptor;

                AnalyzerAssert.Valid <NoErrorAnalyzer>(descriptor, code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), descriptor, code);
                AnalyzerAssert.Valid(analyzer, descriptor, code);

                AnalyzerAssert.Valid <NoErrorAnalyzer>(new[] { descriptor }, code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), new[] { descriptor }, code);
                AnalyzerAssert.Valid(analyzer, new[] { descriptor }, code);
            }
Пример #5
0
        public static async Task AddEventFieldDeclarationSyntax()
        {
            var code   = @"
namespace N
{
    public abstract class C
    {
        public int Filed1 = 1;
        private int filed1;

        public C()
        {
        }

        private C(int i)
        {
        }

        public int P1 { get; set; }

        public void M1()
        {
        }
    }
}";
            var sln    = CodeFactory.CreateSolution(code);
            var editor = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var eventDeclaration = (EventFieldDeclarationSyntax)editor.Generator.EventDeclaration("SomeEvent", SyntaxFactory.ParseTypeName("System.EventHandler"), Accessibility.Public);
            var containingType   = editor.OriginalRoot.SyntaxTree.FindClassDeclaration("C");

            _ = editor.AddEvent(containingType, eventDeclaration);
            var expected = @"
namespace N
{
    public abstract class C
    {
        public int Filed1 = 1;
        private int filed1;

        public C()
        {
        }

        private C(int i)
        {
        }

        public event System.EventHandler SomeEvent;

        public int P1 { get; set; }

        public void M1()
        {
        }
    }
}";

            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
            public void CreateSolutionFromProjectFile()
            {
                Assert.AreEqual(true, ProjectFile.TryFind(ExecutingAssemblyDll, out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new FieldNameMustNotBeginWithUnderscore(), },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual(Path.GetFileNameWithoutExtension(ExecutingAssemblyDll.FullName), solution.Projects.Single().Name);
                var expected = projectFile.Directory
                               .EnumerateFiles("*.cs", SearchOption.AllDirectories)
                               .Where(f => !f.DirectoryName.Contains("bin"))
                               .Where(f => !f.DirectoryName.Contains("obj"))
                               .Select(f => f.Name)
                               .OrderBy(x => x)
                               .ToArray();
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
            public void CreateSolutionFromWpfApp1()
            {
                Assert.AreEqual(true, ProjectFile.TryFind("WpfApp1.csproj", out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new FieldNameMustNotBeginWithUnderscore(), },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual("WpfApp1", solution.Projects.Single().Name);
                var expected = new[]
                {
                    "App.xaml.cs",
                    "AssemblyInfo.cs",
                    "Class1.cs",
                    "MainWindow.xaml.cs",
                    "Resources.Designer.cs",
                    "Settings.Designer.cs",
                    "UserControl1.xaml.cs",
                };
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
Пример #8
0
            public void BinarySolution()
            {
                var binaryReferencedCode = @"
namespace BinaryReferencedAssembly
{
    public class Base
    {
        private int _fieldName;
    }
}";
                var code     = @"
namespace RoslynSandbox
{
    using System.Reflection;

    public class C : BinaryReferencedAssembly.Base
    {
        private int f;
    }
}";
                var analyzer = new FieldNameMustNotBeginWithUnderscore();
                var solution = CodeFactory.CreateSolution(
                    code,
                    CodeFactory.DefaultCompilationOptions(new[] { analyzer }),
                    AnalyzerAssert.MetadataReferences.Append(Asserts.MetadataReferences.CreateBinary(binaryReferencedCode)));

                AnalyzerAssert.Valid(analyzer, solution);
            }
Пример #9
0
        private async void ExportFont(object sender, RoutedEventArgs e)
        {
            FileSavePicker picker = new FileSavePicker()
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                SuggestedFileName      = this.FontName,
                DefaultFileExtension   = ".h"
            };

            picker.FileTypeChoices.Add("H", new List <string>()
            {
                ".h"
            });

            StorageFile file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                this.CurrentFile.Items = this.Items.ToArray();
                CodeFactory codeFactory = new CodeFactory(this.CurrentFile);
                string      code        = await codeFactory.CreateSourceCode(this.FontName);

                await FileIO.WriteTextAsync(file, code);
            }
        }
        public void ProhibitsRetrievalOfArrayWithinMemberChain()
        {
            var source        = @"
class Test {
  private static readonly C c = new C();

  public void Run() {
    var v = Test.c.Value.Value.Values;
  }
}

class A {
  public readonly int[] Values;
}

class B {
  public readonly A Value;
}

class C {
  public readonly B Value;
}";
            var semanticModel = DocumentFactory.Create().CreateSemanticModel(source);
            var method        = semanticModel.SyntaxTree.GetRoot().DescendantNodes()
                                .OfType <MethodDeclarationSyntax>()
                                .Single();


            CodeFactory.Create(method.Body, semanticModel);
        }
Пример #11
0
        public static async Task WithProtectedMember(string before, string after)
        {
            var code   = @"
namespace N
{
    class C
    {
        protected int f;
    }
}".AssertReplace("protected int f;", before);
            var sln    = CodeFactory.CreateSolution(code);
            var editor = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var expected = @"
namespace N
{
    sealed class C
    {
        private int f;
    }
}".AssertReplace("private int f;", after);

            _ = editor.Seal(editor.OriginalRoot.Find <ClassDeclarationSyntax>("class C"));
            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
            public void TryFindSolutionFileInParentDirectory()
            {
                var directory = ExecutingAssemblyDll.Directory;

                Assert.AreEqual(true, CodeFactory.TryFindFileInParentDirectory(directory, "Gu.Roslyn.Asserts.sln", out var projectFile));
                Assert.AreEqual("Gu.Roslyn.Asserts.sln", projectFile.Name);
            }
Пример #13
0
        public static async Task TypeInSameNamespaceWhenEmptyNamespace()
        {
            var classCode = @"
namespace N
{
    class C1 { }
}
";
            var code      = @"
namespace N
{
}";
            var sln       = CodeFactory.CreateSolution(new[] { classCode, code });
            var document  = sln.Projects.First().Documents.Last();
            var editor    = await DocumentEditor.CreateAsync(document).ConfigureAwait(false);

            var expected = @"
namespace N
{
}";
            var type     = editor.SemanticModel.Compilation.GetTypeByMetadataName("N.C1");

            _ = editor.AddUsing(type);
            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #14
0
        public static async Task SystemWhenEmptyOutside()
        {
            var code = @"
namespace N
{
}";

            var otherCode = @"
using System;

namespace N
{
}";
            var sln       = CodeFactory.CreateSolution(new[] { code, otherCode });
            var editor    = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var expected       = @"using System;

namespace N
{
}";
            var usingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName("System"));

            _ = editor.AddUsing(usingDirective);
            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #15
0
        public static async Task TypeInNestedDeepNamespace()
        {
            var classCode = @"
namespace A.B.C.Extensions
{
    class C { }
}
";
            var code      = @"
namespace A.B.C
{
}";
            var sln       = CodeFactory.CreateSolution(new[] { classCode, code });
            var document  = sln.Projects.First().Documents.First();
            var editor    = await DocumentEditor.CreateAsync(document).ConfigureAwait(false);

            var expected = @"
namespace A.B.C
{
    using A.B.C.Extensions;
}";
            var type     = editor.SemanticModel.Compilation.GetTypeByMetadataName("A.B.C.Extensions.C");

            _ = editor.AddUsing(type);
            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #16
0
            public static void ProjectFromDisk()
            {
                var after              = @"// ReSharper disable All
namespace ClassLibrary1
{
    public class ClassLibrary1Class1
    {
        private int value;

        public ClassLibrary1Class1(int value)
        {
            this.value = value;
        }
    }
}
";
                var csproj             = ProjectFile.Find("ClassLibrary1.csproj");
                var analyzer           = new FieldNameMustNotBeginWithUnderscore();
                var expectedDiagnostic = ExpectedDiagnostic.Create(
                    FieldNameMustNotBeginWithUnderscore.DiagnosticId,
                    "Field '_value' must not begin with an underscore",
                    Path.Combine(csproj.DirectoryName, "ClassLibrary1Class1.cs"),
                    5,
                    20);
                var solution = CodeFactory.CreateSolution(
                    csproj,
                    analyzer,
                    expectedDiagnostic,
                    metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(int).Assembly.Location) });

                RoslynAssert.CodeFix(analyzer, new DoNotUseUnderscoreFix(), expectedDiagnostic, solution, after);
            }
Пример #17
0
        public static async Task AfterPropertyWhenLastMember()
        {
            var code   = @"
namespace N
{
    public class C
    {
        public int P { get; }
    }
}";
            var sln    = CodeFactory.CreateSolution(code);
            var editor = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var containingType = editor.OriginalRoot.SyntaxTree.FindClassDeclaration("C");
            var property       = (PropertyDeclarationSyntax)SyntaxFactory.ParseMemberDeclaration("public int NewProperty => 1;");

            var expected = @"
namespace N
{
    public class C
    {
        public int P { get; }

        public int NewProperty => 1;
    }
}";

            _ = editor.AddProperty(containingType, property);
            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #18
0
            public void CreateSolutionWithDependenciesFromQualified()
            {
                var code1 = @"
namespace Project1
{
    public class Foo1
    {
        private readonly int _value;
    }
}";

                var code2 = @"
namespace Project2
{
    public class Foo2
    {
        private readonly Project1.Foo1 _value;
    }
}";
                var sln   = CodeFactory.CreateSolution(new[] { code1, code2 }, new[] { new FieldNameMustNotBeginWithUnderscore() });

                CollectionAssert.AreEqual(new[] { "Project1", "Project2" }, sln.Projects.Select(x => x.Name));
                CollectionAssert.AreEqual(new[] { "Foo1.cs", "Foo2.cs" }, sln.Projects.Select(x => x.Documents.Single().Name));
                var project1 = sln.Projects.Single(x => x.Name == "Project1");

                CollectionAssert.IsEmpty(project1.AllProjectReferences);
                var project2 = sln.Projects.Single(x => x.Name == "Project2");

                CollectionAssert.AreEqual(new[] { project1.Id }, project2.AllProjectReferences.Select(x => x.ProjectId));
            }
Пример #19
0
            public void CreateSolutionWithOneProject()
            {
                var code1 = @"
namespace RoslynSandbox.Core
{
    public class Foo1
    {
        private readonly int _value;
    }
}";

                var code2 = @"
namespace RoslynSandbox.Bar
{
    public class Foo2 : RoslynSandbox.Core.Foo1
    {
    }
}";

                foreach (var sources in new[] { new[] { code1, code2 }, new[] { code2, code1 } })
                {
                    var sln     = CodeFactory.CreateSolutionWithOneProject(sources, new[] { new FieldNameMustNotBeginWithUnderscore() });
                    var project = sln.Projects.Single();
                    Assert.AreEqual("RoslynSandbox", project.AssemblyName);
                    CollectionAssert.AreEquivalent(new[] { "Foo1.cs", "Foo2.cs" }, project.Documents.Select(x => x.Name));
                }
            }
Пример #20
0
            public void CreateSolutionWhenNestedNamespaces()
            {
                var resourcesCode = @"
namespace RoslynSandbox.Properties
{
    public class Resources
    {
    }
}";

                var testCode = @"
namespace RoslynSandbox
{
    using RoslynSandbox.Properties;

    public class Foo
    {
    }
}";

                foreach (var sources in new[] { new[] { resourcesCode, testCode }, new[] { resourcesCode, testCode } })
                {
                    var sln     = CodeFactory.CreateSolution(sources);
                    var project = sln.Projects.Single();
                    Assert.AreEqual("RoslynSandbox", project.AssemblyName);
                    CollectionAssert.AreEquivalent(new[] { "Resources.cs", "Foo.cs" }, project.Documents.Select(x => x.Name));
                }
            }
Пример #21
0
        public void AnalyzeWhenAllInformationIsProvidedByAttributeWhenDataClassIsInSeparateAssembly()
        {
            var testCode = TestUtility.WrapClassInNamespaceAndAddUsing(@"
        public class Tests
        {
            [Test]
            [TestCaseSource(typeof(TestData), nameof(TestData.TestCaseDataProvider))]
            public void Test1(int a, int b, int c)
            {
                Assert.That(a + b, Is.EqualTo(c));
            }
        }");

            var testDataCode = TestUtility.WrapClassInNamespaceAndAddUsing(@"
        public static class TestData
        {
            public static IEnumerable TestCaseDataProvider()
            {
                yield return new object[] { 1, 2, 3 };
                yield return new object[] { 2, 3, 5 };
            }
        }", "using System.Collections;");

            var solution = CodeFactory.CreateSolution(new[] { testCode, testDataCode });

            RoslynAssert.Valid(analyzer, solution);
        }
Пример #22
0
            public void CreateSolutionWithInheritQualified()
            {
                var code1 = @"
namespace RoslynSandbox.Core
{
    public class Foo1
    {
        private readonly int _value;
    }
}";

                var code2 = @"
namespace RoslynSandbox.Client
{
    public class Foo2 : RoslynSandbox.Core.Foo1
    {
    }
}";

                foreach (var sources in new[] { new[] { code1, code2 }, new[] { code2, code1 } })
                {
                    var sln = CodeFactory.CreateSolution(sources, new[] { new FieldNameMustNotBeginWithUnderscore() });
                    CollectionAssert.AreEquivalent(new[] { "RoslynSandbox.Core", "RoslynSandbox.Client" }, sln.Projects.Select(x => x.Name));
                    CollectionAssert.AreEquivalent(new[] { "Foo1.cs", "Foo2.cs" }, sln.Projects.Select(x => x.Documents.Single().Name));
                    var project1 = sln.Projects.Single(x => x.Name == "RoslynSandbox.Core");
                    CollectionAssert.IsEmpty(project1.AllProjectReferences);
                    var project2 = sln.Projects.Single(x => x.Name == "RoslynSandbox.Client");
                    CollectionAssert.AreEqual(new[] { project1.Id }, project2.AllProjectReferences.Select(x => x.ProjectId));
                }
            }
        /// <summary>
        /// Gets generated data object code for the selected server object.
        /// </summary>
        /// <returns>A code string.</returns>
        public string GetCurrentServerObjectDataObject(string languageOption)
        {
            var codeFactory = new CodeFactory(languageOption);
            var tableView   = GetCurrentTableView();

            return(codeFactory.GetDataObjectCode(tableView));
        }
Пример #24
0
        public static void ConstructorCycle(DiagnosticAnalyzer analyzer)
        {
            var code     = @"
namespace N
{
    using System;

    public sealed class C : IDisposable
    {
        private IDisposable disposable;

        public C(int i, IDisposable disposable)
            : this(disposable, i)
        {
            this.disposable = disposable;
        }

        public C(IDisposable disposable, int i)
            : this(i, disposable)
        {
            this.disposable = disposable;
        }

        public void Dispose()
        {
        }
    }
}";
            var solution = CodeFactory.CreateSolution(code, CodeFactory.DefaultCompilationOptions(analyzer), MetadataReferences.FromAttributes());

            RoslynAssert.NoDiagnostics(Analyze.GetDiagnostics(analyzer, solution));
        }
Пример #25
0
            public void SevenPointThreeFeature()
            {
                var code     = @"
namespace RoslynSandbox
{
    class Foo<T>
        where T : struct, System.Enum
    {
    }
}";
                var analyzer = new NoErrorAnalyzer();

                AnalyzerAssert.Valid <NoErrorAnalyzer>(code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), code);
                AnalyzerAssert.Valid(analyzer, code);
                AnalyzerAssert.Valid(analyzer, code, CodeFactory.DefaultCompilationOptions(analyzer, AnalyzerAssert.SuppressedDiagnostics), AnalyzerAssert.MetadataReferences);
                AnalyzerAssert.Valid(analyzer, new[] { code }, CodeFactory.DefaultCompilationOptions(analyzer, AnalyzerAssert.SuppressedDiagnostics), AnalyzerAssert.MetadataReferences);

                var descriptor = NoErrorAnalyzer.Descriptor;

                AnalyzerAssert.Valid <NoErrorAnalyzer>(descriptor, code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), descriptor, code);
                AnalyzerAssert.Valid(analyzer, descriptor, code);

                AnalyzerAssert.Valid <NoErrorAnalyzer>(new[] { descriptor }, code);
                AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), new[] { descriptor }, code);
                AnalyzerAssert.Valid(analyzer, new[] { descriptor }, code);
            }
        public void AllowsLongChainOfReadOnlyFields()
        {
            var source        = @"
class Test {
  private static readonly C c = new C();

  public void Run() {
    var v = Test.c.Value.Value.Value;
  }
}

class A {
  public readonly int Value;
}

class B {
  public readonly A Value;
}

class C {
  public readonly B Value;
}";
            var semanticModel = DocumentFactory.Create().CreateSemanticModel(source);
            var method        = semanticModel.SyntaxTree.GetRoot().DescendantNodes()
                                .OfType <MethodDeclarationSyntax>()
                                .Single();


            var code     = CodeFactory.Create(method.Body, semanticModel);
            var expected = @"
DECL v
v = \literal";

            Assert.AreEqual(expected.Trim(), CodeStringifier.Generate(code));
        }
Пример #27
0
        public static async Task AddEventWhenUsing()
        {
            var code   = @"
namespace N
{
    using System;

    class C
    {
    }
}";
            var sln    = CodeFactory.CreateSolution(code);
            var editor = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var eventDeclaration = (EventFieldDeclarationSyntax)editor.Generator.EventDeclaration("E", SyntaxFactory.ParseTypeName("System.EventHandler"), Accessibility.Public)
                                   .WithSimplifiedNames();
            var containingType = editor.OriginalRoot.SyntaxTree.FindClassDeclaration("C");

            _ = editor.AddEvent(containingType, eventDeclaration);
            var expected = @"
namespace N
{
    using System;

    class C
    {
        public event EventHandler E;
    }
}";

            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #28
0
        public static async Task TypicalClass()
        {
            var code   = @"
namespace N
{
    public abstract class C
    {
        public int F1 = 1;
        private int f2;

        public C()
        {
        }

        private C(int i)
        {
        }

        public int P1 { get; set; }

        public void M1()
        {
        }
    }
}";
            var sln    = CodeFactory.CreateSolution(code);
            var editor = await DocumentEditor.CreateAsync(sln.Projects.First().Documents.First()).ConfigureAwait(false);

            var declaration    = (PropertyDeclarationSyntax)SyntaxFactory.ParseMemberDeclaration("public int NewProperty { get; set; }");
            var containingType = editor.OriginalRoot.SyntaxTree.FindClassDeclaration("C");

            _ = editor.AddProperty(containingType, declaration);
            var expected = @"
namespace N
{
    public abstract class C
    {
        public int F1 = 1;
        private int f2;

        public C()
        {
        }

        private C(int i)
        {
        }

        public int P1 { get; set; }

        public int NewProperty { get; set; }

        public void M1()
        {
        }
    }
}";

            CodeAssert.AreEqual(expected, editor.GetChangedDocument());
        }
Пример #29
0
        public static async Task FiguresOutFromOtherClass(string expression, CodeStyleResult expected)
        {
            var sln = CodeFactory.CreateSolution(new[]
            {
                @"
namespace N
{
    class C1
    {
        private int f;

        C1()
        {
            this.f = 1;
        }
    }
}".AssertReplace("this.f = 1", expression),
                @"
namespace N
{
    class C2
    {
    }
}",
            });

            foreach (var document in sln.Projects.Single().Documents)
            {
                Assert.AreEqual(expected, await document.QualifyFieldAccessAsync(CancellationToken.None).ConfigureAwait(false));
            }
        }
Пример #30
0
            public void CreateSolutionFromSources()
            {
                var code1 = @"
namespace Project1
{
    class Foo1
    {
        private readonly int _value;
    }
}";

                var code2 = @"
namespace Project2
{
    class Foo2
    {
        private readonly int _value;
    }
}";
                var sln   = CodeFactory.CreateSolution(new[] { code1, code2 });

                CollectionAssert.AreEqual(new[] { "Project1", "Project2" }, sln.Projects.Select(x => x.Name));
                Assert.AreEqual(new[] { "Foo1.cs", "Foo2.cs" }, sln.Projects.Select(x => x.Documents.Single().Name));

                sln = CodeFactory.CreateSolution(new[] { code2, code1 });
                CollectionAssert.AreEqual(new[] { "Project1", "Project2" }, sln.Projects.Select(x => x.Name));
                Assert.AreEqual(new[] { "Foo1.cs", "Foo2.cs" }, sln.Projects.Select(x => x.Documents.Single().Name));
            }
            public void CreateSolutionWithTwoAnalyzersReportingSameDiagnostic()
            {
                Assert.AreEqual(true, CodeFactory.TryFindProjectFile("ClassLibrary1.csproj", out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new DummyAnalyzer(ID1234.Descriptor), new DummyAnalyzer(ID1234.Descriptor) },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual("ClassLibrary1", solution.Projects.Single().Name);
                var expected = new[]
                {
                    "AllowCompilationErrors.cs",
                    "AssemblyInfo.cs",
                    "ClassLibrary1Class1.cs",
                };
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
Пример #32
0
 public EntityCatalog(CodeFactory.Config config, CodeFactory.Entity entity)
 {
     this.config = config;
     this.entity = entity;
 }
Пример #33
0
 public KeysPatch(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #34
0
 public DataLoad(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #35
0
 public DatabaseAdmin(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #36
0
 public Main(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #37
0
 public SQLiteDatabase(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #38
0
 public CreateDatabaseAzure(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #39
0
 public DropDatabase(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #40
0
 public Client(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #41
0
 protected override void Act()
 {
     Sut = new CodeFactory(SpaceRemover);
 }
Пример #42
0
 public SyncConfig(CodeFactory.Config config, String connectionString)
 {
     this.config = config;
     this.connection = new System.Data.SqlClient.SqlConnectionStringBuilder();
     this.connection.ConnectionString = connectionString;
 }
Пример #43
0
 public Filters(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #44
0
 public NonAzureKeysPatch(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #45
0
 public DefaultCSS(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #46
0
 public SyncPatch2(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #47
0
    private void UpdatePage(CodeFactory.ContentManager.Page page)
    {
        if (page == null)
            return;

        if (page.IsNew)
            page.Author = User.Identity.Name;
        page.Title = TitleTextBox.Text;
        page.Slug = Utils.RemoveIllegalCharacters(SlugTextBox.Text);
        page.Description = DescriptionTextBox.Text;
        // page.IsDefault
        page.IsVisible = IsVisibleCheckBox.Checked;
        page.Keywords = KeywordsTextBox.Text;
        page.Layout = LayoutList.SelectedValue;
        // page.Roles
        // page.Section

        // Al final, para evitar que se guarde sin cambios.
        if (!page.IsNew && page.IsChanged)
            page.LastUpdatedBy = User.Identity.Name;
    }
Пример #48
0
 public ClientConstants(CodeFactory.Config config)
 {
     this.config = config;
 }
Пример #49
0
    private void BindPage(CodeFactory.ContentManager.Page page)
    {
        if (page == null)
            return;

        TitleTextBox.Text = page.Title;
        SlugTextBox.Text = page.Slug;
        DescriptionTextBox.Text = page.Description;
        KeywordsTextBox.Text = page.Keywords;
        IsVisibleCheckBox.Checked = page.IsVisible;

        int layoutIndex = LayoutList.Items.IndexOf(LayoutList.Items.FindByValue(page.Layout));

        if (layoutIndex >= 0)
            LayoutList.SelectedIndex = layoutIndex;
    }
Пример #50
0
 void IWiki.RemoveFile(CodeFactory.Web.Storage.UploadedFile item)
 {
     throw new NotImplementedException();
 }
Пример #51
0
 public ClientMetadata(CodeFactory.Config config)
 {
     this.config = config;
 }