public async Task FileDoesNotContainClass()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = " // Just a comment";

            (IFileSystemAbstraction fs, IVisualStudioAbstraction vsa) = this.GetCSAbstractions(fileContents);

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.cs", 8);

            string expected = null;

            StringAssert.AreEqual(expected, actual);
        }
        public async Task FileContainsModuleButNoProperties()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = "Public Module TestViewModel"
                               + Environment.NewLine + "    Private Property OnlyHiddenProperty As String"
                               + Environment.NewLine + "End Module";

            (IFileSystemAbstraction fs, IVisualStudioAbstractionAndDocumentModelAccess vsa) = this.GetVbAbstractions(fileContents);

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.vb", 8, profile.ProjectType);

            var expected = "<StackPanel>"
                           + Environment.NewLine + "            <!-- No accessible properties when copying as XAML -->"
                           + Environment.NewLine + "        </StackPanel>";

            StringAssert.AreEqual(expected, actual);
        }
        public async Task FileContainsClassButNoProperties()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = "Public Class TestViewModel"
                               + Environment.NewLine + "    Private Property FirstProperty As String"
                               + Environment.NewLine + "    Private Property SecondProperty As String"
                               + Environment.NewLine + "End Class";

            (IFileSystemAbstraction fs, IVisualStudioAbstraction vsa) = this.GetAbstractions(fileContents);

            var sut = new DropHandlerLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.vb", 8);

            var expected = "<StackPanel>"
                           + Environment.NewLine + "            <!-- No accessible properties when copying as XAML -->"
                           + Environment.NewLine + "        </StackPanel>";

            StringAssert.AreEqual(expected, actual);
        }
Пример #4
0
        public async Task FileContainsClassButNoProperties()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = "public class TestViewModel"
                               + Environment.NewLine + "{"
                               + Environment.NewLine + "    private string FirstProperty { get; set; }"
                               + Environment.NewLine + "    private string SecondProperty { get; set; }"
                               + Environment.NewLine + "}";

            (IFileSystemAbstraction fs, IVisualStudioAbstraction vsa) = this.GetCSAbstractions(fileContents);

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.cs", 8, profile.ProjectType);

            var expected = "<StackPanel>"
                           + Environment.NewLine + "            <!-- No accessible properties when copying as XAML -->"
                           + Environment.NewLine + "        </StackPanel>";

            StringAssert.AreEqual(expected, actual);
        }
        public async Task FileContainsClassAndPublicProperties()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = "Public Class TestViewModel"
                               + Environment.NewLine + "    Public Property FirstProperty As String"
                               + Environment.NewLine + "    Public Property SecondProperty As String"
                               + Environment.NewLine + "End Class";

            (IFileSystemAbstraction fs, IVisualStudioAbstractionAndDocumentModelAccess vsa) = this.GetVbAbstractions(fileContents);

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.vb", 8, profile.ProjectType);

            var expected = "<StackPanel>"
                           + Environment.NewLine + "            <TextBlock Text=\"FirstProperty\" />"
                           + Environment.NewLine + "            <TextBlock Text=\"SecondProperty\" />"
                           + Environment.NewLine + "        </StackPanel>";

            StringAssert.AreEqual(expected, actual);
        }
        public async Task FileContainsClassAndPublicPropertiesButNoClassGrouping()
        {
            var profile = this.GetProfileForTesting();

            profile.ClassGrouping = string.Empty;

            var fileContents = "Public Class TestViewModel"
                               + Environment.NewLine + "    Public Property FirstProperty As String"
                               + Environment.NewLine + "    Public Property SecondProperty As String"
                               + Environment.NewLine + "End Class";

            (IFileSystemAbstraction fs, IVisualStudioAbstraction vsa) = this.GetAbstractions(fileContents);

            var sut = new DropHandlerLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.vb", 8);

            var expected = "<TextBlock Text=\"FirstProperty\" />"
                           + Environment.NewLine + "        <TextBlock Text=\"SecondProperty\" />";

            StringAssert.AreEqual(expected, actual);
        }
        public async Task FileContainsClassAndPublicProperties()
        {
            var profile = this.GetProfileForTesting();

            var fileContents = "public class TestViewModel"
                               + Environment.NewLine + "{"
                               + Environment.NewLine + "    public string FirstProperty { get; set; }"
                               + Environment.NewLine + "    public string SecondProperty { get; set; }"
                               + Environment.NewLine + "}";

            (IFileSystemAbstraction fs, IVisualStudioAbstraction vsa) = this.GetCSAbstractions(fileContents);

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            var actual = await sut.ExecuteAsync("C:\\Tests\\SomeFile.cs", 8);

            var expected = "<StackPanel>"
                           + Environment.NewLine + "            <TextBlock Text=\"FirstProperty\" />"
                           + Environment.NewLine + "            <TextBlock Text=\"SecondProperty\" />"
                           + Environment.NewLine + "        </StackPanel>";

            StringAssert.AreEqual(expected, actual);
        }
Пример #8
0
        private async Task CanParseWithoutErrors(string folderPath)
        {
            var profile = RapidXamlToolkit.Tests.TestProfile.CreateEmpty();

            profile.ClassGrouping  = "Grid";
            profile.FallbackOutput = "<TextBlock Text=\"$name$\" />";

            var logger = new RecordingTestLogger();

            // DropHandlerLogic already has everything needed to parse a file so reuse that for testing.
            var dhl = new DropHandlerLogic(
                logger,
                new HybridTestVisualStudioAbstraction(),
                new WindowsFileSystem(),
                profile);

            bool anyFailures = false;

            foreach (var filePath in GetCodeFiles(folderPath))
            {
                string output;

                if (filePath.Contains("\\obj\\") ||
                    filePath.Contains("\\AssemblyInfo.") ||
                    filePath.Contains("GlobalSuppressions.") ||
                    filePath.Contains("_postaction.") ||
                    filePath.Contains("_gpostaction."))
                {
                    continue;
                }

                try
                {
                    Debug.WriteLine($"Attempting to parse '{filePath}'.");

                    output = await dhl.ExecuteAsync(filePath, 0, ProjectType.Any);

                    if (output is null)
                    {
                        this.TestContext.WriteLine($"No output after parsing '{filePath}'");
                        this.TestContext.AddResultFile(filePath);

                        var lastLogMsg = logger.Info.Last();

                        if (!lastLogMsg.StartsWith("Unable to find class definition in file") &&
                            !lastLogMsg.Equals("No properties to provide output for."))
                        {
                            anyFailures = true;
                        }
                    }
                }
                catch (Exception exc)
                {
                    this.TestContext.WriteLine($"Found error while parsing '{filePath}'{Environment.NewLine}{exc.Message}");
                    this.TestContext.AddResultFile(filePath);
                    anyFailures = true;
                }
            }

            Assert.IsFalse(anyFailures);
        }