public void CacheManagerExtensions_SetIfNotExists() { var cm = new Mock <ICacheManager>(); var key = "key"; var value = new CacheTestObject(); var cacheTime = 123U; //object is cached cm.Setup(c => c.Get <CacheTestObject>(It.IsAny <string>())).Returns(null as CacheTestObject); CacheManagerExtensions.SetIfNotExists(cm.Object, key, value, cacheTime); cm.Verify(c => c.Set( It.Is <string>(k => k == key), It.Is <CacheTestObject>(cto => cto == value), It.IsAny <uint>()), Times.Once); //object is not cached cm.Reset(); cm.Setup(c => c.Get <CacheTestObject>(It.IsAny <string>())).Returns(new CacheTestObject()); CacheManagerExtensions.SetIfNotExists(cm.Object, key, value, cacheTime); cm.Verify(c => c.Set(It.IsAny <string>(), It.IsAny <CacheTestObject>(), It.IsAny <uint>()), Times.Never); }
public void CacheManagerExtensions_Set() { var cm = new Mock <ICacheManager>(); var key = "key"; var value = new CacheTestObject(); CacheManagerExtensions.Set(cm.Object, key, value); cm.Verify(c => c.Set( It.Is <string>(k => k == key), It.Is <CacheTestObject>(cto => cto == value), It.Is <uint>(i => i == CacheManagerExtensions.DefaultCacheTime)), Times.Once); }
public bool Equals(CacheTestObject other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other.Key == this.Key && Equals(other.Name, this.Name)); }
public bool Equals(CacheTestObject other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return other.Key == this.Key && Equals(other.Name, this.Name); }