public void Persist(IEnumerable <StoreInfo> storesEnumerableParam) { var allStores = (storesEnumerableParam ?? new StoreInfo[] {}).ToArray(); var storesToPersist = allStores .Where(_ => !_persistenceCalculator.WasPersistedRecently(_.StoreNumber)) .ToArray(); var numbersToPersist = storesToPersist.Select(_ => _.StoreNumber).ToArray(); Logger.LogInfo("Saving Stores", "totalCount", allStores.Length, "count", numbersToPersist.Length); if (numbersToPersist.Length == 0) { return; } var numbersToUpdate = (_dataService.ContainsStore(numbersToPersist)).ToArray(); var numbersToCreate = numbersToPersist.Except(numbersToUpdate).ToArray(); var storesToUpdate = storesToPersist.Where(_ => numbersToUpdate.Contains(_.StoreNumber)).ToArray(); var storesToCreate = storesToPersist.Where(_ => numbersToCreate.Contains(_.StoreNumber)).ToArray(); Logger.LogDebug("Creating Stores", "count", storesToCreate.Length); _dataService.CreateNew(storesToCreate); Logger.LogDebug("Updating Stores", "count", storesToUpdate.Length); _dataService.Update(storesToUpdate); foreach (var storeNumber in numbersToPersist) { _persistenceCalculator.PreventFuturePersistence(storeNumber); } }
public void PreventsAStoreFromFuturePersistence() { _calculator.PreventFuturePersistence("11111-0"); _cacheWithExpiration.Received(1).Add("11111-0", 3000u); }