Exemplo n.º 1
0
        private void When_invoking_external_constructor_with_stream_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(StreamReader).Namespace)
                                      .WithReference(typeof(XmlDocument).Assembly)
                                      .Using(typeof(XmlDocument).Namespace)
                                      .WithReference(typeof(XDocument).Assembly)
                                      .Using(typeof(XDocument).Namespace)
                                      .Using(typeof(Encoding).Namespace)
                                      .InDefaultMethod(@"
                    new StreamReader(new MemoryStream());

                    new StreamWriter(new MemoryStream());

                    new XmlDocument().Load(new MemoryStream());
                    new XmlDocument().Save(new MemoryStream());

                    XmlWriter.Create(new MemoryStream());

                    new XmlTextWriter(new MemoryStream(), Encoding.UTF8);
                    XmlTextWriter.Create(new MemoryStream());

                    new XDocument().Save(new MemoryStream());

                    new XElement(string.Empty).Save(new MemoryStream());

                    new XStreamingElement(string.Empty).Save(new MemoryStream());
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source);
        }
Exemplo n.º 2
0
        private void When_missing_assembly_reference_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var stream = File.Create(string.Empty);
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source);
        }
Exemplo n.º 3
0
        private void When_invoking_non_fakeable_constructor_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var time = new DateTime(2000, 1, 1);
                    var text = new string('X', 100);
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source);
        }
Exemplo n.º 4
0
        private void When_invoking_fakeable_extension_method_it_must_be_reported()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var stream1 = File.[|OpenRead|](string.Empty);

                    FileInfo info = null;
                    var stream2 = info.[|OpenRead|]();
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source,
                                       "Usage of 'System.IO.File.OpenRead' should be replaced by 'TestableFileSystem.Interfaces.FileExtensions.OpenRead'.",
                                       "Usage of 'System.IO.FileInfo.OpenRead' should be replaced by 'TestableFileSystem.Interfaces.FileInfoExtensions.OpenRead'.");
        }
Exemplo n.º 5
0
        private void When_invoking_special_static_member_it_must_be_reported()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var drives1 = Directory.[|GetLogicalDrives|]();
                    var drives2 = Environment.[|GetLogicalDrives|]();
                    var drives3 = DriveInfo.[|GetDrives|]();
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source,
                                       "Usage of 'System.IO.Directory.GetLogicalDrives' should be replaced by 'TestableFileSystem.Interfaces.IDirectory.GetLogicalDrives'.",
                                       "Usage of 'System.Environment.GetLogicalDrives' should be replaced by 'TestableFileSystem.Interfaces.IDirectory.GetLogicalDrives'.",
                                       "Usage of 'System.IO.DriveInfo.GetDrives' should be replaced by 'TestableFileSystem.Interfaces.IDrive.GetDrives'.");
        }
Exemplo n.º 6
0
        private void When_invoking_non_fakeable_instance_member_it_must_be_skipped()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    FileInfo fileInfo = null;
                    fileInfo.GetAccessControl();

                    DirectoryInfo directoryInfo = null;
                    directoryInfo.GetAccessControl();

                    FileSystemWatcher watcher = null;
                    watcher.BeginInit();
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source);
        }
Exemplo n.º 7
0
        private void When_invoking_fakeable_static_member_it_must_be_reported()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var stream = File.[|Create|](string.Empty);
                    var files = Directory.[|GetFiles|](string.Empty);
                    var path1 = Path.[|GetFullPath|](string.Empty);
                    var path2 = Path.[|GetTempPath|]();
                    var fileName = Path.[|GetTempFileName|]();
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source,
                                       "Usage of 'System.IO.File.Create' should be replaced by 'TestableFileSystem.Interfaces.IFile.Create'.",
                                       "Usage of 'System.IO.Directory.GetFiles' should be replaced by 'TestableFileSystem.Interfaces.IDirectory.GetFiles'.",
                                       "Usage of 'System.IO.Path.GetFullPath' should be replaced by 'TestableFileSystem.Interfaces.IPath.GetFullPath'.",
                                       "Usage of 'System.IO.Path.GetTempPath' should be replaced by 'TestableFileSystem.Interfaces.IPath.GetTempPath'.",
                                       "Usage of 'System.IO.Path.GetTempFileName' should be replaced by 'TestableFileSystem.Interfaces.IPath.GetTempFileName'.");
        }
Exemplo n.º 8
0
        private void When_invoking_fakeable_constructor_it_must_be_reported()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(File).Namespace)
                                      .InDefaultMethod(@"
                    var fileInfo = new [|FileInfo|](string.Empty);
                    var directoryInfo = new [|DirectoryInfo|](string.Empty);
                    var driveInfo = new [|DriveInfo|](string.Empty);
                    var stream = new [|FileStream|](string.Empty, FileMode.Create);
                    var watcher = new [|FileSystemWatcher|](string.Empty);
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source,
                                       "Construction of 'System.IO.FileInfo' should be replaced by 'TestableFileSystem.Interfaces.IFileSystem.ConstructFileInfo'.",
                                       "Construction of 'System.IO.DirectoryInfo' should be replaced by 'TestableFileSystem.Interfaces.IFileSystem.ConstructDirectoryInfo'.",
                                       "Construction of 'System.IO.DriveInfo' should be replaced by 'TestableFileSystem.Interfaces.IFileSystem.ConstructDriveInfo'.",
                                       "Construction of 'System.IO.FileStream' should be replaced by 'TestableFileSystem.Interfaces.IFile.Open'.",
                                       "Construction of 'System.IO.FileSystemWatcher' should be replaced by 'TestableFileSystem.Interfaces.IFileSystem.ConstructFileSystemWatcher'.");
        }
Exemplo n.º 9
0
        private void When_invoking_external_constructor_with_path_it_must_be_reported()
        {
            // Arrange
            ParsedSourceCode source = new BlockSourceCodeBuilder()
                                      .WithReference(typeof(IFileSystem).Assembly)
                                      .Using(typeof(StreamReader).Namespace)
                                      .WithReference(typeof(XmlDocument).Assembly)
                                      .Using(typeof(XmlDocument).Namespace)
                                      .WithReference(typeof(XDocument).Assembly)
                                      .Using(typeof(XDocument).Namespace)
                                      .Using(typeof(Encoding).Namespace)
                                      .InDefaultMethod(@"
                    new [|StreamReader|](string.Empty);
                    new [|StreamReader|](string.Empty, false);
                    new [|StreamReader|](string.Empty, Encoding.UTF8);
                    new [|StreamReader|](string.Empty, Encoding.UTF8, false);
                    new [|StreamReader|](string.Empty, Encoding.UTF8, false, 1024);

                    new [|StreamWriter|](string.Empty);
                    new [|StreamWriter|](string.Empty, true);
                    new [|StreamWriter|](string.Empty, true, Encoding.UTF8);
                    new [|StreamWriter|](string.Empty, true, Encoding.UTF8, 1024);

                    new XmlDocument().[|Load|](string.Empty);
                    new XmlDocument().[|Save|](string.Empty);

                    XmlWriter.[|Create|](string.Empty);
                    XmlWriter.[|Create|](string.Empty, new XmlWriterSettings());

                    new [|XmlTextWriter|](string.Empty, Encoding.UTF8);
                    XmlTextWriter.[|Create|](string.Empty);
                    XmlTextWriter.[|Create|](string.Empty, new XmlWriterSettings());

                    new XDocument().[|Save|](string.Empty);
                    new XDocument().[|Save|](string.Empty, SaveOptions.None);

                    new XElement(string.Empty).[|Save|](string.Empty);
                    new XElement(string.Empty).[|Save|](string.Empty, SaveOptions.None);

                    new XStreamingElement(string.Empty).[|Save|](string.Empty);
                    new XStreamingElement(string.Empty).[|Save|](string.Empty, SaveOptions.None);
                ")
                                      .Build();

            // Act and assert
            VerifyFileSystemDiagnostic(source,
                                       "Constructor of 'System.IO.StreamReader' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamReader' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamReader' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamReader' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamReader' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamWriter' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamWriter' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamWriter' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.IO.StreamWriter' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlDocument.Load' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlDocument.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlWriter.Create' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlWriter.Create' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Constructor of 'System.Xml.XmlTextWriter' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlWriter.Create' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.XmlWriter.Create' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XDocument.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XDocument.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XElement.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XElement.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XStreamingElement.Save' should be passed a 'System.IO.Stream' instead of a file path.",
                                       "Member 'System.Xml.Linq.XStreamingElement.Save' should be passed a 'System.IO.Stream' instead of a file path.");
        }