public static void AssertCompilesAndCanExecuteMethod(
            this MockSourceFile file,
            MockSolution solution,
            string methodName = MockSolutionInitializer.DefaultMixinMethodName,
            int returnValue   = MockSolutionInitializer.DefaultMixinMethodReturnValue)
        {
            MockProject project = solution.Projects.FirstOrDefault(p => p.ContainsFile(file));

            Assert.NotNull(project, "Failed to find Project for File [" + file.FileName + "]");

            AssertCompilesAndCanExecuteMethod <int>(
                project,
                "Testing." + file.Classname,
                methodName,
                returnValue);
        }
        public static MockSolution InitializeWithNormalClassFile(this MockSolution s)
        {
            s.Projects.Add(
                new MockProject
            {
                AssemblyReferences =
                    ReferenceHelper.GetDefaultSystemReferences()
                    .ToList(),
                MockSourceFiles =
                {
                    MockSourceFile.CreateDefaultFile()
                }
            });

            return(s);
        }
        public static void AddMockSourceFile(
            this MockSolutionTestBase mockSolutionTest,
            Func <MockSolution, MockProject> projectSelector,
            MockSourceFile mockSourceFile)
        {
            var project = projectSelector(mockSolutionTest._MockSolution);

            project.MockSourceFiles.Add(mockSourceFile);

            //FireOnItemCreated
            mockSolutionTest.EventProxy.FireOnProjectItemAdded(mockSolutionTest,
                                                               new ProjectItemAddedEventArgs
            {
                ClassFullPath   = mockSourceFile.FileName,
                ProjectFullPath = project.FileName
            });
        }
        public static void UpdateMockSourceFileSource
            (this MockSolutionTestBase mockSolutionTest,
            MockSourceFile mockSourceFile,
            string updatedSource)
        {
            mockSourceFile.Source = updatedSource;

            var project = mockSolutionTest._MockSolution.Projects.FirstOrDefault(
                p => p.ContainsFile(mockSourceFile));

            Assert.IsNotNull(project,
                             "Could not find Project that has Source File [{0}", mockSourceFile.FileName);

            mockSolutionTest.EventProxy.FireOnProjectItemSaved(mockSolutionTest,
                                                               new ProjectItemSavedEventArgs
            {
                ClassFullPath   = mockSourceFile.FileName,
                ProjectFullPath = project.FileName
            });
        }
        public static MockSourceFile RemoveFile(this MockSolution solution,
                                                MockSourceFile sourceFile)
        {
            if (null == sourceFile)
            {
                return(null);
            }

            //Load Project
            var project = solution.Projects.FirstOrDefault(p => p.ContainsFile(sourceFile));

            Assert.NotNull(project, "Could not find Project that contains [{0}]", sourceFile.FileName);

            //Remove File from Project
            project.MockSourceFiles =
                project.MockSourceFiles
                .Where(f => !f.FileName.Equals(sourceFile.FileName))
                .ToList();

            return(sourceFile);
        }
        protected bool CanGenerateMixinCodeForSourceFile(MockSourceFile sourceFile, MockProject project = null)
        {
            project = project ?? _MockSolution.Projects[0];

            var result =
                TestSpecificKernel.Get <IVisualStudioCodeGenerator>()
                .GenerateCode(new[]
            {
                new RawSourceFile
                {
                    FileContents    = sourceFile.Source,
                    FileName        = sourceFile.FileName,
                    ProjectFileName = project.FileName
                }
            })
                .ToArray();

            if (!result.Any())
            {
                return(false);
            }

            var text = result.First().GeneratedCodeSyntaxTree.GetText();

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            Console.WriteLine();
            Console.WriteLine("Mixin code behind:");
            Console.WriteLine(text);
            Console.WriteLine();
            Console.WriteLine();

            return(true);
        }
示例#7
0
 public bool ContainsFile(MockSourceFile sourceFile)
 {
     return(MockSourceFiles.Any(f => f.FileName.Equals(sourceFile.FileName)));
 }
        protected bool CanGenerateMixinCodeForSourceFile(MockSourceFile sourceFile, MockProject project = null)
        {
            project = project ?? _MockSolution.Projects[0];

            var result =
                TestSpecificKernel.Get<IVisualStudioCodeGenerator>()
                    .GenerateCode(new[]
                    {
                        new RawSourceFile
                        {
                            FileContents = sourceFile.Source,
                            FileName = sourceFile.FileName,
                            ProjectFileName = project.FileName
                        }
                    })
                    .ToArray();

            if (!result.Any())
                return false;

            var text = result.First().GeneratedCodeSyntaxTree.GetText();

            if (string.IsNullOrEmpty(text))
                return false;

            Console.WriteLine();
            Console.WriteLine("Mixin code behind:");
            Console.WriteLine(text);
            Console.WriteLine();
            Console.WriteLine();

            return true;
        }
 public static void AssertCodeBehindFileWasGenerated(this MockSolutionTestBase mockSolutionTest,
                                                     MockSourceFile targetFile)
 {
     mockSolutionTest.AssertCodeBehindFileWasGenerated(targetFile.FileName);
 }
 public bool ContainsFile(MockSourceFile sourceFile)
 {
     return MockSourceFiles.Any(f => f.FileName.Equals(sourceFile.FileName));
 }