Summary

Class:WireMock.Validation.Check
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Validation\Check.cs
Covered lines:15
Uncovered lines:56
Coverable lines:71
Total lines:142
Line coverage:21.1%
Branch coverage:15%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
Condition(...)2266.6766.67
NotNull(...)2257.1466.67
NotNull(...)2200
NotEmpty(...)2262.566.67
NotEmpty(...)4800
NullButNotEmpty(...)3200
HasNoNulls(...)3200
ValidEntityType(...)2200

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Validation\Check.cs

#LineLine coverage
 1// Copyright (c) .NET Foundation. All rights reserved.
 2// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Linq;
 8using System.Reflection;
 9using JetBrains.Annotations;
 10
 11// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
 12namespace WireMock.Validation
 13{
 14    // [ExcludeFromCodeCoverage]
 15    [DebuggerStepThrough]
 16    internal static class Check
 17    {
 18        [ContractAnnotation("value:null => halt")]
 19        public static T Condition<T>([NoEnumeration] T value, [NotNull] Predicate<T> condition, [InvokerParameterName] [
 120        {
 121            NotNull(condition, nameof(condition));
 122            NotNull(value, nameof(value));
 23
 124             if (!condition(value))
 025            {
 026                NotEmpty(parameterName, nameof(parameterName));
 27
 028                throw new ArgumentOutOfRangeException(parameterName);
 29            }
 30
 131            return value;
 132        }
 33
 34        [ContractAnnotation("value:null => halt")]
 35        public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
 49936        {
 49937             if (ReferenceEquals(value, null))
 038            {
 039                NotEmpty(parameterName, nameof(parameterName));
 40
 041                throw new ArgumentNullException(parameterName);
 42            }
 43
 49944            return value;
 49945        }
 46
 47        [ContractAnnotation("value:null => halt")]
 48        public static T NotNull<T>(
 49            [NoEnumeration] T value,
 50            [InvokerParameterName] [NotNull] string parameterName,
 51            [NotNull] string propertyName)
 052        {
 053             if (ReferenceEquals(value, null))
 054            {
 055                NotEmpty(parameterName, nameof(parameterName));
 056                NotEmpty(propertyName, nameof(propertyName));
 57
 058                throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
 59            }
 60
 061            return value;
 062        }
 63
 64        [ContractAnnotation("value:null => halt")]
 65        public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 6266        {
 6267            NotNull(value, parameterName);
 68
 6269             if (value.Count == 0)
 070            {
 071                NotEmpty(parameterName, nameof(parameterName));
 72
 073                throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
 74            }
 75
 6276            return value;
 6277        }
 78
 79        [ContractAnnotation("value:null => halt")]
 80        public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 081        {
 082            Exception e = null;
 083             if (ReferenceEquals(value, null))
 084            {
 085                e = new ArgumentNullException(parameterName);
 086            }
 087             else if (value.Trim().Length == 0)
 088            {
 089                e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 090            }
 91
 092             if (e != null)
 093            {
 094                NotEmpty(parameterName, nameof(parameterName));
 95
 096                throw e;
 97            }
 98
 099            return value;
 0100        }
 101
 102        public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
 0103        {
 0104             if (!ReferenceEquals(value, null)
 0105                && (value.Length == 0))
 0106            {
 0107                NotEmpty(parameterName, nameof(parameterName));
 108
 0109                throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
 110            }
 111
 0112            return value;
 0113        }
 114
 115        public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
 116            where T : class
 0117        {
 0118            NotNull(value, parameterName);
 119
 0120             if (value.Any(e => e == null))
 0121            {
 0122                NotEmpty(parameterName, nameof(parameterName));
 123
 0124                throw new ArgumentException(parameterName);
 125            }
 126
 0127            return value;
 0128        }
 129
 130        public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName)
 0131        {
 0132             if (!value.GetTypeInfo().IsClass)
 0133            {
 0134                NotEmpty(parameterName, nameof(parameterName));
 135
 0136                throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
 137            }
 138
 0139            return value;
 0140        }
 141    }
 142}