public void Store(string id, object obj) { Guard.NotNullOrEmpty(() => id, id); var item = CacheItem.Create(id, obj); using (var session = documentStore.OpenSession()) { session.Store(item); session.SaveChanges(); } }
public void Remove_should_call_savechanges_on_ravendb() { // Given A.CallTo(() => documentSession.Load <CacheItem>("id")).Returns(CacheItem.Create("id", "value")); // When cacheStore.Remove("id"); // Then A.CallTo(() => documentSession.SaveChanges()).MustHaveHappened(); }
public void Remove_should_remove_the_item_from_ravendb() { // Given A.CallTo(() => documentSession.Load <CacheItem>("id")).Returns(CacheItem.Create("id", "value")); // When cacheStore.Remove("id"); // Then A.CallTo(() => documentSession.Delete(A <CacheItem> .That.Matches(i => i.Id == "id"))).MustHaveHappened(); }
public void TryLoad_should_set_the_loaded_item_in_the_out_parameter() { // Given string item; var cacheItem = CacheItem.Create("id", "value"); A.CallTo(() => documentSession.Load <CacheItem>("id")).Returns(cacheItem); // When cacheStore.TryLoad("id", out item); // Then item.ShouldEqual("value"); }
public void TryLoad_should_return_true_when_item_is_found() { // Given int _; var item = CacheItem.Create("id", 1); A.CallTo(() => documentSession.Load <CacheItem>("id")).Returns(item); // When bool result = cacheStore.TryLoad("id", out _); // Then result.ShouldBeTrue(); }
public async Task <SaveGameMatchDataResponse> Handle(SaveGameMatchDataRequest request, CancellationToken cancellationToken) { if (cancellationToken == CancellationToken.None) { return new SaveGameMatchDataResponse { Result = OperationResult.Failure(new FailureDetail("CancellationToken", "CancellationToken argument cannot be null.")) } } ; var players = await _cacheProvider.GetPlayersListAsync(cancellationToken); if ((players?.Count() ?? 0) == 0 || !players.Any(p => p == request.PlayerId)) { return new SaveGameMatchDataResponse { Result = OperationResult.Failure(PlayerNotFound) } } ; var games = await _cacheProvider.GetGamesListAsync(cancellationToken); if ((games?.Count() ?? 0) == 0 || !games.Any(p => p == request.GameId)) { return new SaveGameMatchDataResponse { Result = OperationResult.Failure(GameNotFound) } } ; var cachedGameMatches = await _cacheProvider.GetGameMatchesAsync(cancellationToken); var gameMatches = cachedGameMatches == null ? new List <CacheItem <GameMatchDataDto> >() : cachedGameMatches.ToList(); gameMatches.Add(CacheItem <GameMatchDataDto> .Create(MapFrom(request))); await _cacheProvider.StoreGameMatchesAsync(gameMatches, null, cancellationToken); return(new SaveGameMatchDataResponse { Result = OperationResult.Successful() }); }