public void IsLt_When_value_is_lt_than_limit_It_should_not_throw()
        {
            var spec = When_value_is_lt_than_limit();

            ShouldNotThrow(
                () => Ensure.That(spec.Value, ParamName).IsLt(spec.Limit),
                () => EnsureArg.IsLt(spec.Value, spec.Limit, ParamName));
        }
        public void IsLt_When_value_is_gt_than_limit_It_throws_ArgumentException()
        {
            var spec = When_value_is_gt_than_limit();

            AssertIsLtScenario(spec.Value, spec.Limit,
                               () => Ensure.That(spec.Value, ParamName).IsLt(spec.Limit),
                               () => EnsureArg.IsLt(spec.Value, spec.Limit, ParamName));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts the rest-service on the provided port.
        /// </summary>
        /// <param name="port">Port that the service should bind onto.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="port"/> is out of bounds.</exception>
        /// <inheritdoc />
        public void Listen(int port)
        {
            EnsureArg.IsGt(port, IPEndPoint.MinPort, nameof(port));
            EnsureArg.IsLt(port, IPEndPoint.MaxPort, nameof(port));

            owinInstance = WebApp.Start(new StartOptions {
                Port = port
            }, Startup);
        }
Ejemplo n.º 4
0
 public static Book Create(string title, int year, int price, string genre)
 {
     EnsureArg.IsLt(title.Length, 100);
     return(new Book
     {
         Title = title,
         Year = year,
         Price = price,
         Genre = genre
     });
 }
        public void IsLt_When_value_is_lt_than_limit_It_returns_passed_values()
        {
            var spec = When_value_is_lt_than_limit();

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

            AssertReturnedAsExpected(returnedValue, spec.Value);

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

            a.ShouldNotThrow();
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> CountBusinessDaysFromARange(string StartDateExclusive, string EndDateExclusive)
        {
            EnsureArg.HasValue(StartDateExclusive);
            EnsureArg.HasValue(EndDateExclusive);

            var start = DateTime.ParseExact(StartDateExclusive, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            var end   = DateTime.ParseExact(EndDateExclusive, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            EnsureArg.IsLt(start, end);

            var count = await calculator.count(start, end);

            return(Ok(count));
        }
        public List <UserLocation> GetCurrentLocationForAllUsersByAreaCoordinates(AreaCoordinates area)
        {
            EnsureArg.IsNotNull(area, nameof(area));
            EnsureArg.IsGt(area.LongitudeMin, -180, nameof(area.LongitudeMin));
            EnsureArg.IsLt(area.LongitudeMin, 180, nameof(area.LongitudeMin));
            EnsureArg.IsGt(area.LongitudeMax, -180, nameof(area.LongitudeMax));
            EnsureArg.IsLt(area.LongitudeMax, 180, nameof(area.LongitudeMax));
            EnsureArg.IsGt(area.LatitudeMin, -180, nameof(area.LatitudeMin));
            EnsureArg.IsLt(area.LatitudeMin, 180, nameof(area.LatitudeMin));
            EnsureArg.IsGt(area.LatitudeMax, -180, nameof(area.LatitudeMax));
            EnsureArg.IsLt(area.LatitudeMax, 180, nameof(area.LatitudeMax));

            return(CurrentLocationOfUsersInArea);
        }
        public bool SetCurrentLocation(UserLocation userLocation)
        {
            EnsureArg.IsGt(userLocation.UserId, 0, nameof(userLocation.UserId));
            EnsureArg.IsGt(userLocation.Longitude, -180, nameof(userLocation.Longitude));
            EnsureArg.IsLt(userLocation.Longitude, 180, nameof(userLocation.Longitude));
            EnsureArg.IsGt(userLocation.Latitude, -90, nameof(userLocation.Latitude));
            EnsureArg.IsLt(userLocation.Latitude, 90, nameof(userLocation.Latitude));
            EnsureArg.IsNotNullOrWhiteSpace(userLocation.Area, nameof(userLocation.Area));

            userLocation.RecordedAt = DateTime.Now;

            // add to store

            return(true);
        }
        public void IsLt_Comparer_arg_is_used()
        {
            // Sp < sa when case sensitive (S < s), but Sp > sa case insensitive (p > a)
            var Sp = "Sp";
            var sa = "sa";
            IComparer <string> ordinal = StringComparer.Ordinal;

            ShouldNotThrow(
                () => Ensure.That(Sp, ParamName).IsLt(sa, ordinal),
                () => EnsureArg.IsLt(Sp, sa, ordinal, ParamName));

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

            ShouldNotThrow(
                () => Ensure.That(sa, ParamName).IsLt(Sp, ignoreCase),
                () => EnsureArg.IsLt(sa, Sp, ignoreCase, ParamName));
        }