Exemple #1
0
        public virtual string FormatItemAddedMessage(IItemDefinition definition, FormatArguments arguments)
        {
            definition = definition ?? throw new ArgumentNullException(nameof(definition));
            arguments  = arguments ?? throw new ArgumentNullException(nameof(arguments));

            var definitionType = FormatDefinitionType(definition);
            var identifier     = FormatItemAddedIdentifier(definition, arguments.Identifier);
            var oldValue       = FormatOldValue(definition, arguments.OldValue);
            var newValue       = FormatNewValue(definition, arguments.NewValue);

            ValidateMessageMarkers(arguments);

            // The message format is expected to have markers for each of the above values
            var message = arguments.MessageFormat
                          .Replace("{DefinitionType}", definitionType)
                          .Replace("{Identifier}", identifier)
                          .Replace("{OldValue}", oldValue)
                          .Replace("{NewValue}", newValue);

            return(message);
        }
        public static void AddElementChangedResult <T>(this IChangeResultAggregator aggregator,
                                                       SemVerChangeType changeType,
                                                       ItemMatch <T> match,
                                                       IMessageFormatter messageFormatter,
                                                       FormatArguments arguments)
            where T : IItemDefinition
        {
            aggregator       = aggregator ?? throw new ArgumentNullException(nameof(aggregator));
            match            = match ?? throw new ArgumentNullException(nameof(match));
            messageFormatter = messageFormatter ?? throw new ArgumentNullException(nameof(messageFormatter));
            arguments        = arguments ?? throw new ArgumentNullException(nameof(arguments));

            var message = messageFormatter.FormatItemChangedMessage(match, arguments);

            var result = new ComparisonResult(
                changeType,
                match.OldItem, match.NewItem,
                message);

            aggregator.AddResult(result);
        }
Exemple #3
0
        public virtual string FormatItemChangedMessage <T>(ItemMatch <T> match, FormatArguments arguments)
            where T : IItemDefinition
        {
            match     = match ?? throw new ArgumentNullException(nameof(match));
            arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));

            var definitionType = FormatDefinitionType(match);
            var identifier     = FormatIdentifier(match, arguments.Identifier);
            var oldValue       = FormatOldValue(match, arguments.OldValue);
            var newValue       = FormatNewValue(match, arguments.NewValue);

            ValidateMessageMarkers(arguments);

            // The message format is expected to have markers for each of the above values
            var message = arguments.MessageFormat
                          .Replace("{DefinitionType}", definitionType)
                          .Replace("{Identifier}", identifier)
                          .Replace("{OldValue}", oldValue)
                          .Replace("{NewValue}", newValue);

            return(message);
        }
Exemple #4
0
        private static void ValidateMessageMarkers(FormatArguments arguments)
        {
            if (string.IsNullOrWhiteSpace(arguments.Identifier) == false &&
                arguments.MessageFormat.Contains("{Identifier}") == false)
            {
                throw new InvalidOperationException(
                          "The message format arguments provide an identifier but the message format does not include {Identifier}");
            }

            if (string.IsNullOrWhiteSpace(arguments.OldValue) == false &&
                arguments.MessageFormat.Contains("{OldValue}") == false)
            {
                throw new InvalidOperationException(
                          "The message format arguments provide an old value but the message format does not include {OldValue}");
            }

            if (string.IsNullOrWhiteSpace(arguments.NewValue) == false &&
                arguments.MessageFormat.Contains("{NewValue}") == false)
            {
                throw new InvalidOperationException(
                          "The message format arguments provide a new value but the message format does not include {NewValue}");
            }
        }