Beispiel #1
0
        public void DryRunTrueTest()
        {
            const string expectedFile =
                @"using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                DryRun        = true,
                LicenseString = "My License"
            };

            // This should erase everything if dry run doesn't work.
            settings.OldHeaderRegexPatterns.Add(".*");

            // Should be a successful run with the intent of the output to
            // change everything, but nothing should actually change.
            ModifyHeaderResult result = this.testFrame.DoModifyHeaderTest(expectedFile, expectedFile, settings);

            result.WasSuccess(true, true);
        }
Beispiel #2
0
        public void MissingHeaderWithNewLicenseSpecifiedTest()
        {
            const string originalFile =
                @"using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";

            const string licenseString =
                @"//
// Copyright Seth Hendrick 2020.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

";

            string expectedFile =

                @"//
// Copyright Seth Hendrick 2020.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";

            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                LicenseString = licenseString
            };

            // Nothing should happen, even if specified.  There are no old licenses hanging around.
            settings.OldHeaderRegexPatterns.Add(Regex.Escape(licenseString));

            ModifyHeaderResult result = this.testFrame.DoModifyHeaderTest(originalFile, expectedFile, settings);

            result.WasSuccess(true, false);
        }
Beispiel #3
0
        public void RemoveHeaderTest()
        {
            const string originalFile =
                @"//
// Copyright Seth Hendrick 2020.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            const string expectedFile =
                @"using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            const string regex =
                @"//
// Copyright Seth Hendrick 2020\.
// Distributed under the MIT License\.
// \(See accompanying file LICENSE in the root of the repository\)\.
//

";

            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                LicenseString = null
            };

            settings.OldHeaderRegexPatterns.Add(regex);


            ModifyHeaderResult result = this.testFrame.DoModifyHeaderTest(originalFile, expectedFile, settings);

            // No to adding a header, yes to replacing a header with nothing.
            result.WasSuccess(false, true);
        }
Beispiel #4
0
        public void MissingHeaderWithNoNewLicenseSpecifiedTest()
        {
            const string originalFile =
                @"using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                // Expect no changes if this isn't specified.
                LicenseString = null
            };

            ModifyHeaderResult result = this.testFrame.DoModifyHeaderTest(originalFile, originalFile, settings);

            result.WasSuccess(false, false);
        }
        public void DateReplacementTest()
        {
            const string originalFile =
                @"//
// Copyright Seth Hendrick 2019.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            const string expectedFile =
                @"//
// Copyright Seth Hendrick 2019-2020.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

using System;
using System.Collections.Generic;
using System.Text;

namespace Cake.LicenseHeaderUpdater.Tests.IntegrationTests
{
    class Class1
    {
    }
}
";
            const string newLicense =

                @"//
// Copyright Seth Hendrick 2019-2020.
// Distributed under the MIT License.
// (See accompanying file LICENSE in the root of the repository).
//

";

            const string oldLicenseRegex =
                @"//
// Copyright Seth Hendrick \d+\.
// Distributed under the MIT License\.
// \(See accompanying file LICENSE in the root of the repository\)\.
//

";
            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                LicenseString = newLicense
            };

            settings.OldHeaderRegexPatterns.Add(oldLicenseRegex);

            ModifyHeaderResult result = this.testFrame.DoModifyHeaderTest(originalFile, expectedFile, settings);

            result.WasSuccess(true, true);
        }