/// <summary> /// Checks if a person with a region can be added and then retrieved from it. /// </summary> public void AddAndGetPersonWithRegion() { LightHouse.Core.Caching.DataCache dataCache = new LightHouse.Core.Caching.DataCache(); String id = Guid.NewGuid().ToString(); Person person = new Person() { ID = id, Reference = "1671", FirstName = new Localization.LocalString("Homer"), LastName = new Localization.LocalString("Simpson"), }; String region = "Family"; String falseRegion = "Acquaintances"; dataCache.Add(person.ID, person, region); person.FirstName = new Localization.LocalString("Bart"); Person cachedPerson = dataCache.Get<Person>(id, region); Person falsePerson = dataCache.Get<Person>(id, falseRegion); Assert.NotNull(cachedPerson); Assert.Null(falsePerson); Assert.Equal(cachedPerson.FirstName.GetContent(), "Bart"); }
/// <summary> /// Checks if a person can be added to the cache and then retrieved from it. /// </summary> public void AddAndGetPerson() { LightHouse.Core.Caching.DataCache dataCache = new LightHouse.Core.Caching.DataCache(); String id = Guid.NewGuid().ToString(); Person person = new Person() { ID = id, Reference = "1671", FirstName = new Localization.LocalString("Homer"), LastName = new Localization.LocalString("Simpson"), }; dataCache.Add(person.ID, person); person.FirstName = new Localization.LocalString("Bart"); Person cachedPerson = dataCache.Get<Person>(id); Assert.Equal(cachedPerson.FirstName.GetContent(), "Bart"); }
/// <summary> /// Checks that an object is removed from a specific region. /// </summary> public void RemoveObjectFromSpecificRegion() { LightHouse.Core.Caching.DataCache dataCache = new LightHouse.Core.Caching.DataCache(); String id = Guid.NewGuid().ToString(); Person person = new Person() { ID = id, Reference = "1671", FirstName = new Localization.LocalString("Homer"), LastName = new Localization.LocalString("Simpson"), }; String dataRegionName = "Family"; Assert.True(dataCache.CreateRegion(dataRegionName)); dataCache.Add(person.ID, person, dataRegionName); Person cachedPerson = dataCache.Get<Person>(person.ID, dataRegionName); Assert.NotNull(cachedPerson); dataCache.Remove(person.ID, dataRegionName); Person removedPerson = dataCache.Get<Person>(person.ID, dataRegionName); Assert.Null(removedPerson); }
/// <summary> /// Checks that an object is removed from a default region. /// </summary> public void RemoveObjectFromDefaultRegion() { LightHouse.Core.Caching.DataCache dataCache = new LightHouse.Core.Caching.DataCache(); String id = Guid.NewGuid().ToString(); Person person = new Person() { ID = id, Reference = "1671", FirstName = new Localization.LocalString("Homer"), LastName = new Localization.LocalString("Simpson"), }; dataCache.Add(person.ID, person); Assert.True(dataCache.Regions.ContainsKey("default"), "default region was not created"); LightHouse.Core.Caching.DataRegion defaultDataRegion = dataCache.Regions["default"]; Person cachedPerson = dataCache.Get<Person>(person.ID); Assert.NotNull(cachedPerson); dataCache.Remove(person.ID); Person removedPerson = dataCache.Get<Person>(person.ID); Assert.Null(removedPerson); }
/// <summary> /// Checks if an object can be retrieved from a region. /// </summary> public void GetObjectFromRegion() { LightHouse.Core.Caching.DataCache dataCache = new LightHouse.Core.Caching.DataCache(); String id = Guid.NewGuid().ToString(); Person person = new Person() { ID = id, Reference = "1671", FirstName = new Localization.LocalString("Homer"), LastName = new Localization.LocalString("Simpson"), }; String dataRegionName = "Family"; dataCache.Add(person.ID, person, dataRegionName); Assert.True(dataCache.Regions.ContainsKey(dataRegionName), "Region was not created"); LightHouse.Core.Caching.DataRegion dataRegion = dataCache.Regions[dataRegionName]; Assert.True((dataRegion.Objects.Count == 1), "Item was not added to region"); Person cachedperson = dataCache.Get<Person>(id, dataRegionName); Assert.NotNull(cachedperson); }