public bool ValidateReservation(ModelStateDictionary modelState, ReservationsInputModel inputReservation) { bool isValid = true; // Check whether the To date is before the From date if (inputReservation.To <= inputReservation.From) { modelState.AddModelError("Date", FROM_DATE_BEFORE_TO_DATE_ERROR); isValid = false; } // Check for overlapping reservation days for all available rooms // Offset the start date so we can account for checkouts on the same From date // var offsetStartDate = inputReservation.From.AddDays(1); var dates = SetHelpers.BuildDateSet(inputReservation.From, inputReservation.To); var allDates = this.datesManager.GetOverlappedDates(inputReservation); foreach (var date in dates) { if (allDates.ContainsKey(date) && allDates[date] >= ROOMS_COUNT) { modelState.AddModelError("Date", OVERLAPPING_RESERVATION_DATES); isValid = false; break; } } return(isValid); }
public ActivitySetAssertions(IList <Activity> messageSet) { if (messageSet == null || !messageSet.Any()) { throw new ActivityAssertionFailedException("No activity received from bot"); } _messageSet = messageSet; _setHelpers = new SetHelpers <Activity, ActivityAssertionFailedException>(); }
public CardActionSetAssertions(IList <CardAction> cardActions) { if (cardActions == null) { throw new ArgumentNullException(nameof(cardActions)); } CardActions = cardActions.Where(x => x != null).ToList(); _setHelpers = new SetHelpers <CardAction, CardActionAssertionFailedException>(); }
public IHeroCardAssertions TextMatching(string regex, string groupMatchRegex, out IList <string> matchedGroups) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (groupMatchRegex == null) { throw new ArgumentNullException(nameof(groupMatchRegex)); } SetHelpers <HeroCard, HeroCardAssertionFailedException> .TestWithGroups act = (HeroCard card, out IList <string> matches) => card.That().TextMatching(regex, groupMatchRegex, out matches); matchedGroups = _setHelpers.TestSetForMatchAndReturnGroups(HeroCards, act, CreateEx(nameof(HeroCard.Text), regex)); return(this); }
public IFactAssertions ValueMatching(string regex, string groupMatchRegex, out IList <string> matchedGroups) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (groupMatchRegex == null) { throw new ArgumentNullException(nameof(groupMatchRegex)); } SetHelpers <Fact, FactAssertionFailedException> .TestWithGroups act = (Fact fact, out IList <string> matches) => fact.That().ValueMatching(regex, groupMatchRegex, out matches); matchedGroups = _setHelper.TestSetForMatchAndReturnGroups(Facts, act, CreateEx(nameof(Fact.Key), regex)); return(this); }
public IActivityAssertions IdMatching(string regex, string groupMatchRegex, out IList <string> matchedGroups) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (groupMatchRegex == null) { throw new ArgumentNullException(nameof(groupMatchRegex)); } SetHelpers <Activity, ActivityAssertionFailedException> .TestWithGroups act = (Activity item, out IList <string> matches) => item.Should().IdMatching(regex, groupMatchRegex, out matches); matchedGroups = _setHelpers.TestSetForMatchAndReturnGroups(_messageSet, act, CreateEx(nameof(Activity.Id), regex)); return(this); }
void linearizeInternal(CausalSetSystemBlock causalSystemBlock, IList <uint> linearization, bool recusive) { causalSystemBlock.updateEntryIndices(); // we calculate this always new because we don't care about performance for now IList <uint> indicesOfEntryNodes = causalSystemBlockAccessor.getEntryIndicesAsList(causalSystemBlock); IList <uint> openNodeIndices = ListHelpers.copy(indicesOfEntryNodes); ISet <uint> nodeIndicesInLinearization = new HashSet <uint>(); // set, bool values hae no meaning while (!openNodeIndices.isEmpty()) { uint currentCandidateNodeIndex; {// choose random element from openNodeIndices and remove uint candidateIndexOfOpenNodeIndices = (uint)random.Next(openNodeIndices.Count); currentCandidateNodeIndex = openNodeIndices[(int)candidateIndexOfOpenNodeIndices]; openNodeIndices.RemoveAt((int)candidateIndexOfOpenNodeIndices); } Ensure.ensureHard(!nodeIndicesInLinearization.Contains(currentCandidateNodeIndex)); nodeIndicesInLinearization.Add(currentCandidateNodeIndex); // if we can and should recurse down if (recusive && causalSystemBlock.nodes[(int)currentCandidateNodeIndex].content != null) { CausalSetSystemBlock childrenBlock = causalSystemBlock.nodes[(int)currentCandidateNodeIndex].content; linearizeInternal(childrenBlock, linearization, recusive); } else { // the global index must be valid linearization.Add(causalSystemBlock.nodes[(int)currentCandidateNodeIndex].globalIndex.Value); } ISet <uint> nextIndicesOfCurrentCandidate = SetHelpers.subtract(causalSystemBlockAccessor.getNextIndicesOfNodeAsSet(causalSystemBlock, currentCandidateNodeIndex), nodeIndicesInLinearization); openNodeIndices = SetHelpers.union(SetHelpers.toSet(openNodeIndices), nextIndicesOfCurrentCandidate).ToList(); } }
public CardImageSetAssertions() { _setHelpers = new SetHelpers <CardImage, CardImageAssertionFailedException>(); }
public ISet <uint> getNextIndicesOfNodeAsSet(CausalSetSystemBlock causalSystemBlock, uint nodeIdx) { uint[] nodeIndicesAsList = causalSystemBlock.nodes[(int)nodeIdx].next.Select(n => causalSystemBlock.indirectionArray[(int)n.value]).ToArray(); return(SetHelpers.toSet(nodeIndicesAsList)); }
public virtual bool TryGetFullKeysByPartialKey(IEnumerable <T> subKeys, IEnumerable <int> positions, out IEnumerable <K> fullKeys) { if (subKeys == null) { throw new ArgumentNullException("subKeys"); } if (positions == null) { throw new ArgumentNullException("positions"); } if (!subKeys.Any()) { fullKeys = default(ISet <K>); return(false); } IList <T> subKeyList = subKeys as IList <T> ?? subKeys.ToList(); IList <int> positionList = positions as IList <int> ?? positions.ToList(); IList <ISet <K> > sets = new List <ISet <K> >(); IList <IEnumerable <ISet <K> > > colSets = new List <IEnumerable <ISet <K> > >(); BitArray positionSet = positions.ToBitArray(); int minSize = int.MaxValue; IEnumerable minSubResult = null; for (int i = 0; i < subKeyList.Count; i++) { if ((i < positionList.Count) && (positionList[i] >= 0)) { if (!partMap.TryGetValue(subKeyList[i], positionList[i], out ISet <K> value, positionSet)) { fullKeys = default(ISet <K>); return(false); } if (value.Count < minSize) { minSize = value.Count; minSubResult = value; } sets.Add(value); } else { int count = partMap.TryGetAllValues(subKeyList[i], out IEnumerable <ISet <K> > value, positionSet); if (count == 0) { fullKeys = default(ISet <K>); return(false); } if (count < minSize) { minSize = count; minSubResult = value; } colSets.Add(value); } } HashSet <K> resultSet = ToSet <K>(minSubResult); if ((sets.Count + colSets.Count) == 1) { fullKeys = resultSet; return(true); } //prefer sets to colSets! if (sets.Count > 0) { foreach (var set in sets) { if (!ReferenceEquals(set, minSubResult)) // check by reference! { resultSet.IntersectWith(set); if (resultSet.Count == 0) { fullKeys = default(ISet <K>); return(false); } } } } if (colSets.Count > 0) { foreach (var colSet in colSets) { if (!ReferenceEquals(colSet, minSubResult)) // check by reference! { if (!SetHelpers.IntersectWith(resultSet, colSet, out var newResultSet)) // check by reference! { fullKeys = default(ISet <K>); return(false); } else { resultSet = newResultSet; } } } } if (resultSet.Count == 0) { fullKeys = default(ISet <K>); return(false); } fullKeys = resultSet; return(true); }
private SigninCardSetAssertions() { _setHelpers = new SetHelpers <SigninCard, SigninCardAssertionFailedException>(); }
public IReceiptItemAssertions SubtitleMatching(string regex, string groupMatchRegex, out IList <string> matchedGroups) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (groupMatchRegex == null) { throw new ArgumentNullException(nameof(groupMatchRegex)); } SetHelpers <ReceiptItem, ReceiptItemAssertionFailedException> .TestWithGroups act = (ReceiptItem item, out IList <string> matches) => item.That().SubtitleMatching(regex, groupMatchRegex, out matches); matchedGroups = _setHelpers.TestSetForMatchAndReturnGroups(ReceiptItems, act, CreateEx(nameof(ReceiptItem.Subtitle), regex)); return(this); }
private ThumbnailCardSetAssertions() { _setHelpers = new SetHelpers <ThumbnailCard, ThumbnailCardAssertionFailedException>(); }
private ReceiptCardSetAssertions() { _setHelpers = new SetHelpers <ReceiptCard, ReceiptCardAssertionFailedException>(); }
private FactSetAssertions() { _setHelper = new SetHelpers <Fact, FactAssertionFailedException>(); }
private ReceiptItemSetAssertions() { _setHelpers = new SetHelpers <ReceiptItem, ReceiptItemAssertionFailedException>(); }
public ICardActionAssertions ImageMatching(string regex, string groupMatchingRegex, out IList <string> groupMatches) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (groupMatchingRegex == null) { throw new ArgumentNullException(nameof(groupMatchingRegex)); } SetHelpers <CardAction, CardActionAssertionFailedException> .TestWithGroups act = (CardAction item, out IList <string> matches) => item.That().ImageMatching(regex, groupMatchingRegex, out matches); groupMatches = _setHelpers.TestSetForMatchAndReturnGroups(CardActions, act, CreateEx(nameof(CardAction.Title), regex)); return(this); }
private HeroCardSetAssertions() { _setHelpers = new SetHelpers <HeroCard, HeroCardAssertionFailedException>(); }