示例#1
0
        public BundleWrapper(ITypedElement bundle)
        {
            EnsureArg.IsNotNull(bundle, nameof(bundle));
            EnsureArg.Is(KnownResourceTypes.Bundle, bundle.InstanceType, StringComparison.Ordinal, nameof(bundle));

            _entries = new Lazy <IReadOnlyList <BundleEntryWrapper> >(() => bundle.Select("entry").Select(x => new BundleEntryWrapper(x)).ToArray());
        }
        public void UpdateCloudBlockBlob(CloudBlockBlob cloudBlockBlob)
        {
            EnsureArg.IsNotNull(cloudBlockBlob, nameof(cloudBlockBlob));
            EnsureArg.Is(Uri.Compare(_cloudBlob.Uri, cloudBlockBlob.Uri, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase), 0);

            _cloudBlob = cloudBlockBlob;
        }
        public void Is_When_same_values_It_should_not_throw()
        {
            var spec = When_value_is_equal_to_limit();

            ShouldNotThrow(
                () => Ensure.That(spec.Value, ParamName).Is(spec.Limit),
                () => EnsureArg.Is(spec.Value, spec.Limit, ParamName));
        }
        public void Is_When_different_values_It_throws_ArgumentException()
        {
            var spec = When_value_is_lt_than_limit();

            AssertAll <ArgumentException>(
                string.Format(ExceptionMessages.Comp_Is_Failed, spec.Value, spec.Limit),
                () => Ensure.That(spec.Value, ParamName).Is(spec.Limit),
                () => EnsureArg.Is(spec.Value, spec.Limit, ParamName));
        }
示例#5
0
        public Role(string name, DataActions allowedDataActions, string scope)
        {
            EnsureArg.IsNotNullOrWhiteSpace(name, nameof(name));
            EnsureArg.Is(scope, "/", nameof(scope)); // until we support data slices

            Name = name;
            AllowedDataActions = allowedDataActions;
            Scope = scope;
        }
        private static decimal GetMinOrMaxSqlDecimalValueForColumn(SqlMetaData columnMetadata, bool min)
        {
            EnsureArg.IsNotNull(columnMetadata, nameof(columnMetadata));
            EnsureArg.Is((int)SqlDbType.Decimal, (int)columnMetadata.SqlDbType, nameof(columnMetadata));

            var val = decimal.Parse($"{new string('9', columnMetadata.Precision - columnMetadata.Scale)}.{new string('9', columnMetadata.Scale)}");

            return(min ? -val : val);
        }
示例#7
0
        public Role(string name, TDataActions allowedDataActions, string scope)
        {
            EnsureArg.IsNotNullOrWhiteSpace(name, nameof(name));
            EnsureArg.Is(scope, "/", nameof(scope));

            Name = name;
            AllowedDataActions      = allowedDataActions;
            AllowedDataActionsUlong = Convert.ToUInt64(allowedDataActions, NumberFormatInfo.InvariantInfo);
            Scope = scope;
        }
        private static decimal GetMinOrMaxSqlDecimalValueForColumn(SqlMetaData columnMetadata, bool min)
        {
            EnsureArg.IsNotNull(columnMetadata, nameof(columnMetadata));
            EnsureArg.Is((int)SqlDbType.Decimal, (int)columnMetadata.SqlDbType, nameof(columnMetadata));
            var separator = CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator;
            var val       = decimal.Parse(
                $"{new string('9', columnMetadata.Precision - columnMetadata.Scale)}{separator}{new string('9', columnMetadata.Scale)}",
                CultureInfo.InvariantCulture);

            return(min ? -val : val);
        }
        public void Is_When_same_values_It_returns_passed_value()
        {
            var spec = When_value_is_equal_to_limit();

            var returnedValue = Ensure.That(spec.Value, ParamName).Is(spec.Limit);

            AssertReturnedAsExpected(returnedValue, spec.Value);

            Action a = () => EnsureArg.Is(spec.Value, spec.Limit, ParamName);

            a.ShouldNotThrow();
        }
示例#10
0
        public void IsEqualTo_When_same_value_by_specific_compare_It_should_not_throw()
        {
            const string value    = "The value";
            const string expected = "the value";

            ShouldNotThrow(
                () => Ensure.String.IsEqualTo(value, expected, StringComparison.OrdinalIgnoreCase, ParamName),
                () => EnsureArg.IsEqualTo(value, expected, StringComparison.OrdinalIgnoreCase, ParamName),
                () => Ensure.That(value, ParamName).IsEqualTo(expected, StringComparison.OrdinalIgnoreCase),
                () => Ensure.String.Is(value, expected, StringComparison.OrdinalIgnoreCase, ParamName),
                () => EnsureArg.Is(value, expected, StringComparison.OrdinalIgnoreCase, ParamName),
                () => Ensure.That(value, ParamName).Is(expected, StringComparison.OrdinalIgnoreCase));
        }
示例#11
0
        public void IsEqualTo_When_same_value_It_should_not_throw()
        {
            const string value    = "The value";
            const string expected = value;

            ShouldNotThrow(
                () => Ensure.String.IsEqualTo(value, expected, ParamName),
                () => EnsureArg.IsEqualTo(value, expected, ParamName),
                () => Ensure.That(value, ParamName).IsEqualTo(expected),
                () => Ensure.String.Is(value, expected, ParamName),
                () => EnsureArg.Is(value, expected, ParamName),
                () => Ensure.That(value, ParamName).Is(expected));
        }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchModifier"/> class.
        /// </summary>
        /// <param name="searchModifierCode"><see cref="SearchModifierCode"/></param>
        /// <param name="resourceType">Resource type used to constrain abstract modifier code (e.g. <see cref="SearchModifierCode.Type"/>)</param>
        public SearchModifier(SearchModifierCode searchModifierCode, string resourceType = null)
        {
            if (searchModifierCode == SearchModifierCode.Type)
            {
                EnsureArg.IsNotEmptyOrWhiteSpace(resourceType, nameof(resourceType));
            }
            else
            {
                EnsureArg.Is(resourceType, null, nameof(resourceType));
            }

            SearchModifierCode = searchModifierCode;
            ResourceType       = resourceType;
        }
示例#13
0
        public SearchParameterWrapper(ITypedElement searchParameter)
        {
            EnsureArg.IsNotNull(searchParameter, nameof(searchParameter));
            EnsureArg.Is(KnownResourceTypes.SearchParameter, searchParameter.InstanceType, StringComparison.Ordinal, nameof(searchParameter));

            _name        = new Lazy <string>(() => searchParameter.Scalar("name")?.ToString());
            _description = new Lazy <string>(() => searchParameter.Scalar("description")?.ToString());
            _url         = new Lazy <string>(() => searchParameter.Scalar("url")?.ToString());
            _expression  = new Lazy <string>(() => searchParameter.Scalar("expression")?.ToString());
            _type        = new Lazy <string>(() => searchParameter.Scalar("type")?.ToString());

            _base      = new Lazy <IReadOnlyList <string> >(() => searchParameter.Select("base")?.AsStringValues().ToArray());
            _component = new Lazy <IReadOnlyList <ITypedElement> >(() => searchParameter.Select("component")?.ToArray());
            _target    = new Lazy <IReadOnlyList <string> >(() => searchParameter.Select("target")?.AsStringValues().ToArray());
        }
        public void Is_Comparer_arg_is_used()
        {
            // sa < Sb < sc when case sensitive, but not when case insensitive
            var sa = "sa";
            var Sa = "Sa";
            IComparer <string> ordinal = StringComparer.Ordinal;

            ShouldThrow <ArgumentException>(
                string.Format(ExceptionMessages.Comp_Is_Failed, sa, Sa),
                () => Ensure.That(sa, ParamName).Is(Sa, ordinal),
                () => EnsureArg.Is(sa, Sa, ordinal, ParamName));

            // Validate with comparer (order is reversed)
            IComparer <string> ignoreCase = StringComparer.OrdinalIgnoreCase;

            ShouldNotThrow(
                () => Ensure.That(sa, ParamName).Is(Sa, ignoreCase),
                () => EnsureArg.Is(sa, Sa, ignoreCase, ParamName));
        }