public async Task AddAsync_DocumentDirectInsertMode_RecordIsNotJsonBlob() { // Arrange var ddCache = CreateCache <SimpleObject>(CosmosCache.InsertMode.Document); var value = SimpleObject.Create(); await ddCache.AddAsync(new CacheItem <SimpleObject>(CacheKey, value, TimeSpan.MaxValue)); // Assert var result = await ddCache.DocumentClient.ReadDocumentAsync(ddCache.CreateDocumentURI(CacheKey)); Assert.NotNull(result); Assert.Equal(value.Foo, result.Resource.GetPropertyValue <string>(nameof(SimpleObject.Foo))); }
public void Get_SimpleObject_ReturnedObjectIsIdentical(CosmosCache.InsertMode mode) { // Arrange var cache = CreateCache <SimpleObject>(mode); var value = SimpleObject.Create(); cache.Set(new CacheItem <SimpleObject>(CacheKey, value, TimeSpan.FromSeconds(5))); // Act var result = cache.Get(CacheKey); // Assert Assert.False(object.ReferenceEquals(result, value)); Assert.Equal(result, value); }
public async Task GetResultAsync_SimpleObject_ReturnedObjectIsIdentical() { // Arrange var cache = cacheFactory.CreateDefault <SimpleObject>(); var value = SimpleObject.Create(); await cache.SetAsync(new CacheItem <SimpleObject>(CacheKey, value, TimeSpan.FromSeconds(5))); // Act var result = await cache.GetResultAsync(CacheKey); // Assert Assert.NotNull(result.Value); Assert.True(result.HasValue); Assert.False(object.ReferenceEquals(result.Value, value)); Assert.Equal(result.Value, value); }
public async Task AddAsync_WithPartitionKeySet_CanReadAndWriteWithPartitionKey() { // Arrange var cacheFactory = new CosmosCacheFactory(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey, LocalClusterCosmosDb.DbName, new CosmosCacheFactorySettings() { InsertMode = CosmosCache.InsertMode.Document, UseKeyAsPartitionKey = true }); var partCache = cacheFactory.Create <SimpleObject>($"partition-{typeof(SimpleObject).Name}"); var value = SimpleObject.Create(); await partCache.AddAsync(new CacheItem <SimpleObject>(CacheKey, value, TimeSpan.MaxValue)); // Assert var result = await partCache.GetAsync(CacheKey); Assert.NotNull(result); }
public void Set_MultipeTasks_NoExceptions() { // Arrange const int numberOfItems = 100; var items = Enumerable.Range(0, numberOfItems).Select(i => SimpleObject.Create()).ToArray(); var cache = cacheFactory.CreateDefault <SimpleObject>(); // Act var stopwatch = System.Diagnostics.Stopwatch.StartNew(); var loopResult = Parallel.For(0, 20, i => { var index = i % numberOfItems; var item = items[index]; cache.Set(new CacheItem <SimpleObject>("item-" + index, item, TimeSpan.FromSeconds(5))); }); stopwatch.Stop(); // Assert _output.WriteLine($"Duration: {stopwatch.Elapsed}"); Assert.True(loopResult.IsCompleted); }