public void CheckResolveByName_TypeName()
        {
            Type testType = typeof(SkipVersionGenerator);
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument(testType.Name, context);

            Assert.IsNotNull(generator);
            Assert.IsInstanceOfType(generator, testType, "Resolved type does not match: {0}", generator.GetType().Name);
        }
        public void CheckResolveByName_Shortest()
        {
            const String testShortName = "Skip";
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument(testShortName, context);

            Assert.IsNotNull(generator);
            Assert.IsInstanceOfType(generator, typeof(SkipVersionGenerator), "Resolved type does not match: {0}", generator.GetType().Name);
        }
        public void CheckResolveByName_GeneratorShortNameNoArgument()
        {
            const String name = "HumanReadable2SlotTimestamp";
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument(name, context);

            Assert.IsNotNull(generator);
            Assert.IsInstanceOfType(generator, typeof(HumanReadable2SlotTimestampGenerator), "Resolved type does not match: {0}", generator.GetType().Name);
        }
        /// <summary>
        /// Scans included generators and tries to find a match for provided generator name.
        /// </summary>
        /// <param name="nameWithArgument">name as provided by MsBuild, may contain argument separated by colon.</param>
        /// <param name="context">Context to storage generator argument in.</param>
        /// <returns></returns>
        public static IVersionGenerator ResolveWithArgument(String nameWithArgument, VersionGenerationContext context)
        {
            if (context == null) { throw new ArgumentNullException("context"); }
            if (String.IsNullOrEmpty(nameWithArgument)) { return new SkipVersionGenerator(); }
            // argument is separated from name by colon. Name cannot contain special symbols:
            Regex regex = new Regex(@"^(?<namePart>[a-zA-Z\d]+)(:(?<argumentPart>.+))?$");
            var match = regex.Match(nameWithArgument);
            if (match.Success)
            {
                context.VersionGenerationArgument = match.Groups["argumentPart"].Value;
                var namePart = match.Groups["namePart"].Value;
                return ResolveByName(namePart);
            }

            //special case: when input does not match the format, then it is to be considered a format for CustomVersionGenerator:
            context.VersionGenerationArgument = nameWithArgument; //everything is context.
            return new CustomVersionGenerator();
        }
        public void CheckResolvingUsingCustomGeneratorWithArgument()
        {
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument("Custom:My argument with colon : here", context);

            Assert.IsInstanceOfType(generator, typeof(CustomVersionGenerator), "Resolved type does not match: {0}", generator.GetType().Name);
            Assert.AreEqual(context.VersionGenerationArgument, "My argument with colon : here");
        }
        public void CheckResolvingUsingCustomGeneratorArgumentOnly()
        {
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument("My template here {Now:someformat}", context);

            Assert.IsInstanceOfType(generator, typeof(CustomVersionGenerator), "Resolved type does not match: {0}", generator.GetType().Name);
            Assert.AreEqual(context.VersionGenerationArgument, "My template here {Now:someformat}");
        }
        public void CheckResolvingUsingInvalidGeneratorName()
        {
            var context = new VersionGenerationContext();
            var generator = GeneratorResolver.ResolveWithArgument("NosuchgeneratorExists:argument", context);

            //asserting exception
        }
 public void CheckSkipGeneratorGeneratesNothing()
 {
     var context = new VersionGenerationContext();
     String row = AssemblyInfoFileCreator.GenerateAttributeRow<AssemblyFileVersionAttribute>(new SkipVersionGenerator(), context);
     Assert.IsNull(row);
 }