예제 #1
0
        /// <inheritdoc />
        public TestData Normalize()
        {
            string          normalizedId            = ModelNormalizationUtils.NormalizeTestComponentId(Id);
            string          normalizedName          = ModelNormalizationUtils.NormalizeTestComponentName(Name);
            string          normalizedFullName      = ModelNormalizationUtils.NormalizeTestComponentName(fullName);
            CodeLocation    normalizedCodeLocation  = CodeLocation.Normalize();
            CodeReference   normalizedCodeReference = CodeReference.Normalize();
            PropertyBag     normalizedMetadata      = ModelNormalizationUtils.NormalizeMetadata(Metadata);
            List <TestData> normalizedChildren      = NormalizationUtils.NormalizeCollection <List <TestData>, TestData>(
                children, () => new List <TestData>(), child => child.Normalize(), ReferenceEquals);
            List <TestParameterData> normalizedParameters = NormalizationUtils.NormalizeCollection <List <TestParameterData>, TestParameterData>(
                parameters, () => new List <TestParameterData>(), parameter => parameter.Normalize(), ReferenceEquals);

            if (ReferenceEquals(Id, normalizedId) &&
                ReferenceEquals(Name, normalizedName) &&
                ReferenceEquals(fullName, normalizedFullName) &&
                CodeLocation == normalizedCodeLocation &&
                CodeReference == normalizedCodeReference &&
                ReferenceEquals(Metadata, normalizedMetadata) &&
                ReferenceEquals(children, normalizedChildren) &&
                ReferenceEquals(parameters, normalizedParameters))
            {
                return(this);
            }

            return(new TestData(normalizedId, normalizedName, normalizedFullName, normalizedChildren, normalizedParameters)
            {
                CodeElement = CodeElement,
                CodeLocation = normalizedCodeLocation,
                CodeReference = normalizedCodeReference,
                Metadata = normalizedMetadata,
                isTestCase = isTestCase
            });
        }
예제 #2
0
 private static IList <string> NormalizeMetadataValueList(IList <string> metadataValues)
 {
     return(NormalizationUtils.NormalizeCollection <IList <string>, string>(
                metadataValues,
                () => new List <string>(metadataValues.Count),
                NormalizeMetadataValue,
                ReferenceEquals));
 }
예제 #3
0
 /// <summary>
 /// Normalizes a metadata collection.
 /// </summary>
 /// <param name="metadata">The metadata collection, or null if none.</param>
 /// <returns>The normalized metadata collection, or null if none.  May be the same instance if <paramref name="metadata"/>
 /// was already normalized.</returns>
 public static PropertyBag NormalizeMetadata(PropertyBag metadata)
 {
     return(NormalizationUtils.NormalizeCollection <PropertyBag, KeyValuePair <string, IList <string> > >(
                metadata,
                () => new PropertyBag(),
                NormalizeMetadataKeyValueList,
                (x, y) => ReferenceEquals(x.Key, y.Key) && ReferenceEquals(x.Value, y.Value)));
 }
예제 #4
0
        public void NormalizeCollection_WhenCompareIsNull_Throws()
        {
            List <string> collection = null;

            Gallio.Common.Func <IList <string> > collectionFactory = () => new List <string>();
            Gallio.Common.Func <string, string>  normalize         = x => x + "*";
            EqualityComparison <string>          compare           = null;

            Assert.Throws <ArgumentNullException>(() => NormalizationUtils.NormalizeCollection <IList <string>, string>(
                                                      collection, collectionFactory, normalize, compare));
        }
예제 #5
0
        public void NormalizeCollection_WhenAllNormalizedValuesAreUnchanged_ReturnsTheSameCollection()
        {
            IList <string> collection = new[] { "abc", "def", "ghi" };

            Gallio.Common.Func <IList <string> > collectionFactory = () => new List <string>();
            Gallio.Common.Func <string, string>  normalize         = x => x;
            EqualityComparison <string>          compare           = ReferenceEquals;

            IList <string> normalizedCollection = NormalizationUtils.NormalizeCollection <IList <string>, string>(
                collection, collectionFactory, normalize, compare);

            Assert.AreSame(collection, normalizedCollection);
        }
예제 #6
0
        public void NormalizeCollection_WhenCollectionIsNull_ReturnsNull()
        {
            List <string> collection = null;

            Gallio.Common.Func <IList <string> > collectionFactory = () => new List <string>();
            Gallio.Common.Func <string, string>  normalize         = x => x + "*";
            EqualityComparison <string>          compare           = ReferenceEquals;

            IList <string> normalizedCollection = NormalizationUtils.NormalizeCollection <IList <string>, string>(
                collection, collectionFactory, normalize, compare);

            Assert.IsNull(normalizedCollection);
        }
예제 #7
0
        public void NormalizeCollection_WhenAllNormalizedValuesAreChanged_ReturnsANewCollectionOfNormalizedValues()
        {
            IList <string> collection = new[] { "abc", "def", "ghi" };

            Gallio.Common.Func <IList <string> > collectionFactory = () => new List <string>();
            Gallio.Common.Func <string, string>  normalize         = x => x + "*";
            EqualityComparison <string>          compare           = ReferenceEquals;

            IList <string> normalizedCollection = NormalizationUtils.NormalizeCollection <IList <string>, string>(
                collection, collectionFactory, normalize, compare);

            Assert.AreNotSame(collection, normalizedCollection);
            Assert.AreElementsEqual(new[] { "abc*", "def*", "ghi*" }, normalizedCollection);
        }
예제 #8
0
        /// <inheritdoc />
        public ExceptionData Normalize()
        {
            string         normalizedType       = NormalizationUtils.NormalizeName(type);
            string         normalizedMessage    = NormalizationUtils.NormalizeXmlText(message);
            StackTraceData normalizedStackTrace = stackTrace.Normalize();
            PropertySet    normalizedProperties = NormalizationUtils.NormalizeCollection <PropertySet, KeyValuePair <string, string> >(properties,
                                                                                                                                       () => new PropertySet(),
                                                                                                                                       x => new KeyValuePair <string, string>(NormalizationUtils.NormalizeName(x.Key),
                                                                                                                                                                              NormalizationUtils.NormalizeXmlText(x.Value)),
                                                                                                                                       (x, y) => x.Key == y.Key && x.Value == y.Value);
            ExceptionData normalizedInnerException = innerException != null?innerException.Normalize() : null;

            if (ReferenceEquals(type, normalizedType) &&
                ReferenceEquals(message, normalizedMessage) &&
                ReferenceEquals(stackTrace, normalizedStackTrace) &&
                ReferenceEquals(properties, normalizedProperties) &&
                ReferenceEquals(innerException, normalizedInnerException))
            {
                return(this);
            }

            return(new ExceptionData(normalizedType, normalizedMessage, normalizedStackTrace, normalizedProperties, normalizedInnerException));
        }