public void WhenISpecifyAnEndTime(StartOrEnd startOrEnd)
 {
     switch (startOrEnd)
     {
         case StartOrEnd.Start:
             _sicknessEpisodeEventCreationContext.SpecifyStartTime();
             break;
         case StartOrEnd.End:
             _sicknessEpisodeEventCreationContext.SpecifyEndTime();
             break;
     }
 }
 public void ThenItShouldReflectMyDesiredEndTime(StartOrEnd startOrEnd)
 {
     switch (startOrEnd)
     {
         case StartOrEnd.Start:
             _sicknessEpisodeEventCreationContext.AssertCorrectStartDateTime();
             break;
         case StartOrEnd.End:
             _sicknessEpisodeEventCreationContext.AssertCorrectEndDateTime();
             break;
     }
 }
        public void ThenItShouldReflectMyDesiredEndTime(StartOrEnd startOrEnd)
        {
            switch (startOrEnd)
            {
            case StartOrEnd.Start:
                _sicknessEpisodeEventCreationContext.AssertCorrectStartDateTime();
                break;

            case StartOrEnd.End:
                _sicknessEpisodeEventCreationContext.AssertCorrectEndDateTime();
                break;
            }
        }
        public void WhenISpecifyAnEndTime(StartOrEnd startOrEnd)
        {
            switch (startOrEnd)
            {
            case StartOrEnd.Start:
                _sicknessEpisodeEventCreationContext.SpecifyStartTime();
                break;

            case StartOrEnd.End:
                _sicknessEpisodeEventCreationContext.SpecifyEndTime();
                break;
            }
        }
Exemple #5
0
        private static bool StartsWithOrEndsWithIFast(this string str, string value, StartOrEnd startOrEnd)
        {
            if (str.IsEmpty() || str.Length < value.Length)
            {
                return(false);
            }

            // Note: ASCII chars are 0-127. Uppercase is 65-90; lowercase is 97-122.
            // Therefore, if a char is in one of these ranges, one can convert between cases by simply adding or
            // subtracting 32.

            bool start   = startOrEnd == StartOrEnd.Start;
            int  siStart = start ? 0 : str.Length - value.Length;
            int  siEnd   = start ? value.Length : str.Length;

            for (int si = siStart, vi = 0; si < siEnd; si++, vi++)
            {
                // If we find a non-ASCII character, give up and run the slow check on the whole string. We do
                // this because one .NET char doesn't necessarily equal one Unicode char. Multiple .NET chars
                // might be needed. So we grit our teeth and take the perf hit of letting .NET handle it.
                // This is tuned for ASCII being the more common case, so we can save an advance check for non-
                // ASCII chars, at the expense of being slightly (probably insignificantly) slower if there are
                // in fact non-ASCII chars in value.
                if (value[vi] > 127)
                {
                    return(start
                        ? str.StartsWith(value, OrdinalIgnoreCase)
                        : str.EndsWith(value, OrdinalIgnoreCase));
                }

                if (!str[si].EqualsIAscii(value[vi]))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #6
0
        private static bool StartsWithOrEndsWithFast(this string str, string value,
                                                     CaseComparison caseComparison, StartOrEnd startOrEnd)
        {
            if (string.IsNullOrEmpty(str) || str.Length < value.Length)
            {
                return(false);
            }

            // Note: ASCII chars are 0-127. Uppercase is 65-90; lowercase is 97-122.
            // Therefore, if a char is in one of these ranges, one can convert between cases by simply adding or
            // subtracting 32.

            var start   = startOrEnd == StartOrEnd.Start;
            var siStart = start ? 0 : str.Length - value.Length;
            var siEnd   = start ? value.Length : str.Length;

            for (int si = siStart, vi = 0; si < siEnd; si++, vi++)
            {
                // If we find a non-ASCII character, give up and run the slow check on the whole string. We do
                // this because one .NET char doesn't necessarily equal one Unicode char. Multiple .NET chars
                // might be needed. So we grit our teeth and take the perf hit of letting .NET handle it.
                // This is tuned for ASCII being the more common case, so we can save an advance check for non-
                // ASCII chars, at the expense of being slightly (probably insignificantly) slower if there are
                // in fact non-ASCII chars in value.
                if (value[vi] > 127)
                {
                    switch (caseComparison)
                    {
                    case CaseComparison.CaseSensitive:
                        return(start
                                ? str.StartsWith(value, Ordinal)
                                : str.EndsWith(value, Ordinal));

                    case CaseComparison.CaseInsensitive:
                        return(start
                                ? str.StartsWith(value, OrdinalIgnoreCase)
                                : str.EndsWith(value, OrdinalIgnoreCase));

                    case CaseComparison.GivenOrUpper:
                        return(start
                                ? str.StartsWith(value, Ordinal) ||
                               str.StartsWith(value.ToUpperInvariant(), Ordinal)
                                : str.EndsWith(value, Ordinal) ||
                               str.EndsWith(value.ToUpperInvariant(), Ordinal));

                    case CaseComparison.GivenOrLower:
                        return(start
                                ? str.StartsWith(value, Ordinal) ||
                               str.StartsWith(value.ToLowerInvariant(), Ordinal)
                                : str.EndsWith(value, Ordinal) ||
                               str.EndsWith(value.ToLowerInvariant(), Ordinal));
                    }
                }

                if (str[si] >= 65 && str[si] <= 90 && value[vi] >= 97 && value[vi] <= 122)
                {
                    if (caseComparison == CaseComparison.GivenOrLower || str[si] != value[vi] - 32)
                    {
                        return(false);
                    }
                }
                else if (value[vi] >= 65 && value[vi] <= 90 && str[si] >= 97 && str[si] <= 122)
                {
                    if (caseComparison == CaseComparison.GivenOrUpper || str[si] != value[vi] + 32)
                    {
                        return(false);
                    }
                }
                else if (str[si] != value[vi])
                {
                    return(false);
                }
            }

            return(true);
        }