public void AddLayoutValue_WithFieldInCache_UpdatesEntry()
        {
            // Arrange
            var newValue = "This is the new layout value";
            var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings()) {Enabled = true};
            cache.Clear();
            var field = MasterFakesFactory.CreateFakeLayoutField();
            cache.AddLayoutValue(field.Item, field.Value);
            var initalCount = cache.InnerCache.Count;

            // Act
            cache.AddLayoutValue(field.Item, newValue);
            var result = cache.GetLayoutValue(field.Item);

            // Assert
            Assert.Equal(newValue, result);
            Assert.Equal(initalCount, cache.InnerCache.Count);
        }
        public void GetLayoutValue_WithEmptyCache_ReturnsNull()
        {
            // Arrange
            var item = MasterFakesFactory.CreateFakeItem();
            var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings()) {Enabled = true};
            cache.Clear();

            // Act
            var result = cache.GetLayoutValue(item);

            // Assert
            Assert.Null(result);
        }
        public void ProcessItemUpdate_WithEntriesInDifferentDatabases_OnlyRemovesEntryForMatchingDatabase()
        {
            // Arrange
            var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings(new[] {"master"})) {Enabled = true};
            cache.Clear();
            var id = new ID();
            var masterField = MasterFakesFactory.CreateFakeLayoutField(id);
            Field webField;
            using (var webDb = new Db("web"))
            {
                var webFakesFactory = new FakesFactory(webDb);
                webField = webFakesFactory.CreateFakeLayoutField(id);
            }

            cache.AddLayoutValue(masterField.Item, masterField.Value);
            cache.AddLayoutValue(webField.Item, webField.Value);

            // Act
            cache.ProcessItemUpdate(masterField.Item);

            // Assert
            Assert.Null(cache.GetLayoutValue(masterField.Item));
            Assert.Equal(1, cache.InnerCache.Count);
        }
        public void GetLayoutValue_AfterAddLayoutValue_ReturnsAddedValue()
        {
            // Arrange
            var value = "Here be ye olde layout value.";
            var item = MasterFakesFactory.CreateFakeItem(null, null, value);
            var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings()) {Enabled = true};
            cache.Clear();

            // Act
            cache.AddLayoutValue(item, value);
            var result = cache.GetLayoutValue(item);

            // Assert
            Assert.Equal(value, result);
        }