< Summary

Class:ReactiveUI.Validation.Collections.ValidationText
Assembly:ReactiveUI.Validation
File(s):D:\a\1\s\src\ReactiveUI.Validation\Collections\ValidationText.cs
Covered lines:15
Uncovered lines:6
Coverable lines:21
Total lines:101
Line coverage:71.4% (15 of 21)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
.ctor(...)-83.33%75%
get_Count()-100%100%
get_Item(...)-100%100%
GetEnumerator()-100%100%
System.Collections.IEnumerable.GetEnumerator()-0%100%
Add(...)-0%100%
Clear()-0%100%
ToSingleLine(...)-100%100%

File(s)

D:\a\1\s\src\ReactiveUI.Validation\Collections\ValidationText.cs

#LineLine coverage
 1// Copyright (c) 2020 .NET Foundation and Contributors. All rights reserved.
 2// Licensed to the .NET Foundation under one or more agreements.
 3// The .NET Foundation licenses this file to you under the MIT license.
 4// See the LICENSE file in the project root for full license information.
 5
 6using System.Collections;
 7using System.Collections.Generic;
 8
 9namespace ReactiveUI.Validation.Collections
 10{
 11    /// <summary>
 12    /// Container for validation text.
 13    /// </summary>
 14    public class ValidationText : IEnumerable<string>
 15    {
 40416        private readonly List<string> _texts = new List<string>();
 17
 18        /// <summary>
 19        /// Initializes a new instance of the <see cref="ValidationText"/> class.
 20        /// </summary>
 6621        public ValidationText()
 22        {
 6623        }
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="ValidationText"/> class.
 27        /// </summary>
 28        /// <param name="text">Text to be added in the collection.</param>
 12429        public ValidationText(string text)
 30        {
 12431            _texts.Add(text);
 12432        }
 33
 34        /// <summary>
 35        /// Initializes a new instance of the <see cref="ValidationText"/> class.
 36        /// </summary>
 37        /// <param name="validationTexts"><see cref="ValidationText"/> collection to be added into the text collection.<
 21438        public ValidationText(IEnumerable<ValidationText> validationTexts)
 39        {
 21440            if (validationTexts is null)
 41            {
 042                throw new System.ArgumentNullException(nameof(validationTexts));
 43            }
 44
 66845            foreach (var text in validationTexts)
 46            {
 12047                _texts.AddRange(text._texts);
 48            }
 21449        }
 50
 51        /// <summary>
 52        /// Gets returns the number of elements in the collection.
 53        /// </summary>
 1254        public int Count => _texts.Count;
 55
 56        /// <summary>
 57        /// Indexer.
 58        /// </summary>
 59        /// <param name="index">Position.</param>
 660        public string this[int index] => _texts[index];
 61
 62        /// <inheritdoc/>
 63        public IEnumerator<string> GetEnumerator()
 64        {
 1865            return _texts.GetEnumerator();
 66        }
 67
 68        /// <inheritdoc/>
 69        IEnumerator IEnumerable.GetEnumerator()
 70        {
 071            return GetEnumerator();
 72        }
 73
 74        /// <summary>
 75        /// Adds a text to the collection.
 76        /// </summary>
 77        /// <param name="text">Text to be added in the collection.</param>
 78        public void Add(string text)
 79        {
 080            _texts.Add(text);
 081        }
 82
 83        /// <summary>
 84        /// Clear all texts.
 85        /// </summary>
 86        public void Clear()
 87        {
 088            _texts.Clear();
 089        }
 90
 91        /// <summary>
 92        /// Convert representation to a single line using a specified separator.
 93        /// </summary>
 94        /// <param name="separator">String separator.</param>
 95        /// <returns>Returns all the text collection separated by the separator.</returns>
 96        public string ToSingleLine(string? separator = ",")
 97        {
 7898            return string.Join(separator, _texts);
 99        }
 100    }
 101}