Esempio n. 1
0
                public void ShouldExcludeBlankLinesAndReturnLineCount()
                {
                    //Arrange
                    var       filePath      = "test";
                    const int expected      = 6;
                    var       linesFromFile = new List <string>()
                    {
                        "Line1",
                        string.Empty,
                        "Line3",
                        "Line4",
                        "Line5",
                        "Line6",
                        "Line7"
                    };
                    var sut = new LineCounterTestBuilder()
                              .FileDoesExist(filePath)
                              .WithAllLinesFromFile(filePath, linesFromFile)
                              .Build();
                    //Act
                    var result = sut.CountLinesOfCode(filePath);

                    //Assert
                    Assert.That(result, Is.EqualTo(expected));
                }
Esempio n. 2
0
                    public void ShouldIncludeLinesThatContainValidText_AndASingleLineComment()
                    {
                        //Arrange
                        var       filePath      = "test";
                        const int expected      = 7;
                        var       linesFromFile = new List <string>()
                        {
                            "Line1",
                            "Some text // Some comment",
                            "Line3",
                            "Some other text //Some other comment",
                            "Line5",
                            "Line6",
                            "Line7"
                        };
                        var sut = new LineCounterTestBuilder()
                                  .FileDoesExist(filePath)
                                  .WithAllLinesFromFile(filePath, linesFromFile)
                                  .Build();
                        //Act
                        var result = sut.CountLinesOfCode(filePath);

                        //Assert
                        Assert.That(result, Is.EqualTo(expected));
                    }
Esempio n. 3
0
                    public void ShouldExcludeLineThatIsOnlyABlockComment()
                    {
                        //Arrange
                        var       filePath      = "test";
                        const int expected      = 6;
                        var       linesFromFile = new List <string>()
                        {
                            "Line1",
                            "/* First line of comment*/",
                            "Line3",
                            "Line4",
                            "Line5",
                            "Line6",
                            "Line7"
                        };
                        var sut = new LineCounterTestBuilder()
                                  .FileDoesExist(filePath)
                                  .WithAllLinesFromFile(filePath, linesFromFile)
                                  .Build();
                        //Act
                        var result = sut.CountLinesOfCode(filePath);

                        //Assert
                        Assert.That(result, Is.EqualTo(expected));
                    }
Esempio n. 4
0
                    public void ShouldExcludeLinesThatContainEmptySpace_AndIsAtEndOfCodeBlockComment()
                    {
                        //Arrange
                        var       filePath      = "test";
                        const int expected      = 4;
                        var       linesFromFile = new List <string>()
                        {
                            "Line1",
                            "/* First line of comment",
                            "Second line of comment",
                            "Last line of comment */ ",
                            "Line5",
                            "Line6",
                            "Line7"
                        };
                        var sut = new LineCounterTestBuilder()
                                  .FileDoesExist(filePath)
                                  .WithAllLinesFromFile(filePath, linesFromFile)
                                  .Build();
                        //Act
                        var result = sut.CountLinesOfCode(filePath);

                        //Assert
                        Assert.That(result, Is.EqualTo(expected));
                    }
Esempio n. 5
0
                    public void ShouldIncludeAllLinesThatHaveValidTextBeforeStartOfBlockComment()
                    {
                        //Arrange
                        var       filePath      = "test";
                        const int expected      = 4;
                        var       linesFromFile = new List <string>()
                        {
                            "Line1",
                            "Some text /* First line of comment",
                            "Second line of comment",
                            "Last line of comment */",
                            "Some text again /* Some valid comment",
                            "Second line of valid comment",
                            "Last line of valid comment */",
                            "Line7"
                        };
                        var sut = new LineCounterTestBuilder()
                                  .FileDoesExist(filePath)
                                  .WithAllLinesFromFile(filePath, linesFromFile)
                                  .Build();
                        //Act
                        var result = sut.CountLinesOfCode(filePath);

                        //Assert
                        Assert.That(result, Is.EqualTo(expected));
                    }
Esempio n. 6
0
                public void GivenFilePathIsEmpty_ShouldThrowException(string filePath)
                {
                    //Arrange
                    var sut = new LineCounterTestBuilder().Build();

                    //Act & //Assert
                    Assert.Throws <InvalidOperationException>(() => sut.CountLinesOfCode(filePath),
                                                              "Cannot read from an empty file");
                }
Esempio n. 7
0
                public void GivenFileDoesNotExist_ShouldThrowException()
                {
                    //Arrange
                    var filePath = "test";
                    var sut      = new LineCounterTestBuilder()
                                   .FileDoesNotExist(filePath)
                                   .Build();

                    //Act & //Assert
                    Assert.Throws <FileNotFoundException>(() => sut.CountLinesOfCode(filePath), "File not found.");
                }
Esempio n. 8
0
                public void GivenFileIsEmpty_ShouldReturnZero()
                {
                    //Arrange
                    var       filePath = "test";
                    const int expected = 0;
                    var       sut      = new LineCounterTestBuilder()
                                         .FileDoesExist(filePath)
                                         .Build();
                    //Act
                    var result = sut.CountLinesOfCode(filePath);

                    //Assert
                    Assert.That(result, Is.EqualTo(expected));
                }