public void CreateKeyExtractor() { var keyExtractor = _convetion.CreateKeyExtractor(typeof(Person)); var person = new Person { Id = 2, Name = "person" }; var key = keyExtractor(person); Assert.AreEqual(person.Id.ToString(), key); }
public void CreatePartialKey() { _config = new CacheConfiguration(new MemoryCache("KeyCreatorTests"), new MalformedConvention()); _keyCreator = new KeyCreator(_config); var person = new Person { Id = 1, Name = "Maria" }; var createdKey = _keyCreator.CreateKey(person); }
public void CreateKey() { _config = new CacheConfiguration(new MemoryCache("KeyCreatorTests")); _keyCreator = new KeyCreator(_config); var person = new Person { Id = 2, Name = "person" }; var key = CreateKey(person, person.Id.ToString()); var createdKey = _keyCreator.CreateKey(person); Assert.AreEqual(key, createdKey); }
public void LoadObject_When_TheDelegateReturnNull() { var project = CreateProject(); project.Documents = null; var newPerson = new Person(); newPerson.Id = 1; newPerson.Name = "new Person"; _objectInspector.LoadObject(project, value => { if (value is Order) return null; if (value is Person) return newPerson; return value; }); Assert.AreSame(project.Order.Person, newPerson); }
public void RemoveItem() { var person = new Person { Id = 1, Name = "jamir" }; var keyCreator = new KeyCreator(_config); var key = keyCreator.CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(10)); _cache.Remove<Person>(p => p.Id == person.Id); Assert.IsFalse(_internalCache.Contains(key)); }
public void GetItem_WithChangedCachedProperties() { var order = new Order(); order.Id = 1; order.Person = new Person { Id = 2, Name = "jamir" }; _cache.Add(order, TimeSpan.FromMinutes(10)); _cache.Remove<Person>(p => p.Id == 2); var newPerson = new Person { Id = 2, Name = "Marcos" }; _cache.Add(newPerson, TimeSpan.FromMinutes(10)); var cachedOrder = _cache.Get<Order>(p => p.Id == 1); Assert.AreSame(newPerson, cachedOrder.Person); }
public void GetItem() { var person = new Person { Id = 1, Name = "person" }; var key = new KeyCreator(_config).CreateKey(person); _internalCache.Add(key, person, DateTime.Now + TimeSpan.FromMinutes(1)); var retrivedPerson = _cache.Get<Person>(p => p.Id == person.Id); Assert.AreSame(person, retrivedPerson); }
public void GetGraph_WithNonConventionalObjectIterruption() { var task = CreateTask(); _cache.Add(task, TimeSpan.FromMinutes(10)); _cache.Remove<Person>(p => p.Id == task.Document.Uploader.Id); var uploader2 = new Person { Id = 1, Name = "uploader 2" }; _cache.Add(uploader2, TimeSpan.FromMinutes(10)); var retrivedTask = _cache.Get<Task>(p => p.Id == task.Id); Assert.AreEqual(uploader2, task.Document.Uploader); }
public void GetGraph_WithListOfNonConventionalObjectIterruption() { var projetc = CreateProject(); _cache.Add(projetc, TimeSpan.FromMinutes(10)); _cache.Remove<Person>(p => p.Id == projetc.Documents[1].Uploader.Id); var uploader2 = new Person { Id = 2, Name = "uploader 2.1" }; _cache.Add(uploader2, TimeSpan.FromMinutes(10)); var retrivedProject = _cache.Get<Project>(p => p.Id == projetc.Id); Assert.AreEqual(uploader2, projetc.Documents[1].Uploader); }
public void Contains_WhenContains() { var person = new Person(); person.Id = 1; person.Name = "jamir"; _internalCache.Add("Peron", person, DateTime.Now + TimeSpan.FromMinutes(10)); var contains = _cache.Contains<Person>(p => p.Id == person.Id); Assert.IsTrue(contains); }
public void AddItem_WithExpiration() { var person = new Person { Id = 1, Name = "person" }; _cache.Add(person, DateTime.Now + TimeSpan.FromMinutes(10)); var retrivedPerson = _internalCache.First().Value; Assert.AreSame(person, retrivedPerson); }