Example #1
0
        public void Test_ReplaceNewGuid_GuidGenerater(string input, string expected)
        {
            var replaceWithGuid = new ReplaceWithNewGuid(this.guidGenerator.NewGuid);
            var output          = replaceWithGuid.ReplaceNewGuid(input);

            Console.WriteLine("input   : " + input);
            Console.WriteLine("output  : " + output);
            Console.WriteLine("expected: " + expected);
            Assert.That(output, Is.EqualTo(expected));
        }
        /// <summary>
        /// utility function for ReplaceSameGuidToSameGuid
        /// </summary>
        /// <param name="count">loop count</param>
        /// <param name="repeat">repeat count</param>
        /// <param name="testMethod">test method</param>
        /// <param name="newSrcGuid">delegate for creating new source GUIDs</param>
        public void TestGuidByRandomInvalidFormat(int count, int repeat, TestMethod testMethod, ReplaceWithNewGuid.NewGuid newSrcGuid)
        {
            var builderInput = new StringBuilder();

            Array values = Enum.GetValues(typeof(InvalidFormat));
            var   random = new Random();

            // GUID generator for dest data
            var dstGuidGenerator = new GuidGenerater();

            // create source data
            for (int i = 0; i < count; i++)
            {
                // choose enum 'Format' randomly
                var format = (InvalidFormat)values.GetValue(random.Next(values.Length));

                var separator = string.Format("------ {0} ------", i);
#if PRINTF_DEBUG
                Console.WriteLine(i.ToString() + ": " + format.ToString());
#endif // PRINTF_DEBUG

                var srcGuid = newSrcGuid();
                var dstGuid = dstGuidGenerator.NewGuid();

                InvalidFormatGuid formatGuid = delegate(StringBuilder builder, Guid guid, InvalidFormat destFormat)
                {
                    builder.Append(separator);
                    builder.Append(Environment.NewLine);
                    builder.Append(FormatGuidString(guid, destFormat));
                    builder.Append(Environment.NewLine);
                    builder.Append(Environment.NewLine);
                };

                for (int j = 0; j < repeat; j++)
                {
                    // create input data
                    formatGuid(builderInput, srcGuid, format);
                }
            }

            var input = builderInput.ToString();

            var replaceWithGuid = new ReplaceWithNewGuid(this.guidGenerator.NewGuid);
            var output          = CallMethodOfReplaceWithNewGuid(replaceWithGuid, testMethod, input);

#if PRINTF_DEBUG
            Console.WriteLine("input: ");
            Console.WriteLine(input);

            Console.WriteLine("output: ");
            Console.WriteLine(output);
#endif // PRINTF_DEBUG

            Assert.That(output, Is.EqualTo(input));
        }
Example #3
0
        /// <summary>
        /// Main function
        /// </summary>
        /// <param name="args">arguments to the program</param>
        /// <see href = "https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator(v=vs.110).aspx">MatchEvaluator Delegate</see>
        static void Main(string[] args)
        {
            string input1  = @"[Guid(""f86ed29d-8060-485f-acf2-93716ca463b8"")]";
            string input2  = @"[Guid(""f86ed29d-8060-485f-acf2-93716ca463b8"")]";
            string input3  = @"""f86ed29d-8060-485f-acf2-93716ca463b8""";
            string input4  = @"{f86ed29d-8060-485f-acf2-93716ca463b8}";
            string input5  = @"{f86ed29d8060485facf293716ca463b8}";
            string input6  = @"f86ed29d8060485facf293716ca463b8";
            string input7  = @"F86ED29D8060485FACF293716CA463B8";
            string input8  = @"{0xf86ed29d, 0x8060, 0x485f,{0xac,0xf2,0x93,0x71,0x6c,0xa4,0x63,0xb8}}";
            string input9  = @"{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}";
            string input10 = @"{0x00,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}";
            string input11 = @"IMPLEMENT_OLECREATE(<<class>>, <<external_name>>, 0x00000000,0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);";
            string input12 = @"DEFINE_GUID(<<name>>, 0x00000000,0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);";

            string[] array = new string[]
            {
                input1,
                input2,
                input3,
                input4,
                input5,
                input6,
                input7,
                input8,
                input9,
                input10,
                input11,
                input12,
            };
            string input = string.Join(Environment.NewLine, array);

            Console.WriteLine("Original");
            Console.WriteLine(input);
            Console.WriteLine("");

            var replaceWithNewGuid = new ReplaceWithNewGuid();

            // Replace matched characters using the delegate method.
            var output = replaceWithNewGuid.ReplaceNewGuid(input);

            Console.WriteLine("New All");
            Console.WriteLine(output);
            //testReg.Dump();
            Console.WriteLine("");

            // Replace matched characters using the delegate method.
            var output2 = replaceWithNewGuid.ReplaceSameGuidToSameGuid(input);

            Console.WriteLine("New for different ones");
            Console.WriteLine(output2);
            //testReg.Dump();
            Console.WriteLine("");
        }
Example #4
0
        public void TestRepeat_ReplaceSameGuidToSameGuid_GuidGenerater(int count)
        {
            // check data size
            Assert.That(Inputs.Length, Is.GreaterThan(0));
            Assert.That(Results.Length, Is.GreaterThan(0));
            Assert.That(Inputs.Length, Is.EqualTo(Results.Length));

            var builderInput  = new StringBuilder();
            var builderResult = new StringBuilder();
            var random        = new Random();

            for (int i = 0; i < count; i++)
            {
                int index     = random.Next(0, Inputs.Length - 1);
                var separator = string.Format("------ {0} ------", i);
                builderInput.Append(separator);
                builderInput.Append(Environment.NewLine);
                builderInput.Append(Inputs[index]);
                builderInput.Append(Environment.NewLine);
                builderInput.Append(Environment.NewLine);

                builderResult.Append(separator);
                builderResult.Append(Environment.NewLine);
                builderResult.Append(Results[index]);
                builderResult.Append(Environment.NewLine);
                builderResult.Append(Environment.NewLine);
            }

            var input    = builderInput.ToString();
            var expected = builderResult.ToString();

            var replaceWithGuid = new ReplaceWithNewGuid(this.guidGenerator.NewGuid);
            var output          = replaceWithGuid.ReplaceSameGuidToSameGuid(input);

#if PRINTF_DEBUG
            Console.WriteLine("input: ");
            Console.WriteLine(input);

            Console.WriteLine("output: ");
            Console.WriteLine(output);

            Console.WriteLine("expected: ");
            Console.WriteLine(expected);
#endif // PRINTF_DEBUG

            Assert.That(output, Is.EqualTo(expected));
        }
        /// <summary>
        /// call a method of ReplaceWithNewGuid
        /// </summary>
        /// <param name="replaceWithGuid">instance of ReplaceWithNewGuid</param>
        /// <param name="testMethod">invoke method</param>
        /// <param name="input">input data</param>
        /// <returns>result of ReplaceWithNewGuid</returns>
        private string CallMethodOfReplaceWithNewGuid(ReplaceWithNewGuid replaceWithGuid, TestMethod testMethod, string input)
        {
            var output = string.Empty;

            switch (testMethod)
            {
            case TestMethod.ReplaceNewGuid:
                output = replaceWithGuid.ReplaceNewGuid(input);
                break;

            case TestMethod.ReplaceSameGuidToSameGuid:
                output = replaceWithGuid.ReplaceSameGuidToSameGuid(input);
                break;

            default:
                throw new ArgumentException(testMethod.ToString());
            }
            return(output);
        }