public void AddKeyValueRegionShouldAddToCache() { var expectedValue = TestContext.TestName; var key = "Key" + TestContext.TestName; var region = "Region" + TestContext.TestName; var dcf = new DataCacheFactory(); var dc = dcf.GetDefaultCache(); // Clean up previous entries dc.CreateRegion(region); dc.Remove(key, region); var sut = new DataCacheAdd<string> {Key = key, Value = expectedValue, Region = region}; // Put an item in the cache using the activity var itemVersion = WorkflowInvoker.Invoke(sut); // Get it from the cache var value = dc.Get(key, region) as string; // Assert Assert.IsNotNull(itemVersion); Assert.AreEqual(expectedValue, value); }
public void AddKeyValueRegionTagsShouldAddToCache() { const int expectedCount = 1; var expectedValue = TestContext.TestName; var key = "Key" + TestContext.TestName; var region = "Region" + TestContext.TestName; var tags = new List<DataCacheTag> { new DataCacheTag("tag1" + TestContext.TestName), new DataCacheTag("tag2" + TestContext.TestName), new DataCacheTag("tag3" + TestContext.TestName) }; var dcf = new DataCacheFactory(); var dc = dcf.GetDefaultCache(); // Clean up previous entries dc.CreateRegion(region); dc.Remove(key, region); var sut = new DataCacheAdd<string>(); // To use Object Initialization syntax you would do the following // { Key = key, Value = expectedValue, Region = region, Tags = new LambdaValue<IEnumerable<DataCacheTag>>((env) =>tags)}; // Using input arguments var input = new Dictionary<string, object> { {"Key", key}, {"Value", expectedValue}, {"Region", region}, {"Tags", tags}, }; // Put an item in the cache using the activity var itemVersion = WorkflowInvoker.Invoke(sut, input); // Get it from the cache var values = dc.GetObjectsByAllTags(tags, region); // Assert Assert.IsNotNull(itemVersion); Assert.AreEqual(expectedCount, values.Count()); Assert.AreEqual(expectedValue, values.First().Value); }