public void ShouldNotRetrieveIdIfMappingDoesNotExist() { // Arrange GuidToIdCache.ClearAll(); var key = Guid.NewGuid(); var content = MockContent(1001, key); // Act var result = GuidToIdCache.TryGetId(content.Key, out int id); // Assert result.Should().BeFalse(); id.Should().Be(0); }
public void ShouldRetrieveIdIfMappingExists() { // Arrange GuidToIdCache.ClearAll(); var key = Guid.NewGuid(); var content = MockContent(1001, key); GuidToIdCache.TryAdd(content); // Act var result = GuidToIdCache.TryGetId(content.Key, out int id); // Assert result.Should().BeTrue(); id.Should().Be(1001); }
public void ShouldAddKeyValuePairIfDoesNotAlreadyExist() { // Arrange GuidToIdCache.ClearAll(); var key = Guid.NewGuid(); var content = MockContent(1001, key); GuidToIdCache.TryAdd(content); // Act var result = GuidToIdCache.TryGetId(content.Key, out int id); // Assert result.Should().BeTrue(); id.Should().Be(1001); }
public void ShouldRemoveKeyValuePairAndNotRetrieveGuid() { // Arrange GuidToIdCache.ClearAll(); var key = Guid.NewGuid(); var content = MockContent(1001, key); GuidToIdCache.TryAdd(content); // Act GuidToIdCache.TryRemove(content); var result = GuidToIdCache.TryGetGuid(content.Id, out Guid guid); // Assert result.Should().BeFalse(); guid.Should().Be(Guid.Empty); }
/// <summary> /// Gets a content item from the cache. /// </summary> /// <param name="helper">The instance of <see cref="UmbracoHelper"/> to add extension method.</param> /// <param name="guid">The key of the content item.</param> /// <param name="usingUdiToIdCache">Flag indicating intention to use Udi to Id cache</param> /// <returns>The content, or null of the content item is not in the cache.</returns> public static IPublishedContent TypedContent(this UmbracoHelper helper, Guid guid, bool usingUdiToIdCache) { return(usingUdiToIdCache && GuidToIdCache.TryGetId(guid, out int id) ? helper.TypedContent(id) : helper.TypedContent(guid)); }
/// <summary> /// Gets a content item from the cache. /// </summary> /// <param name="helper">The instance of <see cref="UmbracoHelper"/> to add extension method.</param> /// <param name="udi">The <see cref="Udi"/> of the content item.</param> /// <param name="usingUdiToIdCache">Flag indicating intention to use Udi to Id cache</param> /// <returns>The content, or null of the content item is not in the cache.</returns> public static IPublishedContent TypedContent(this UmbracoHelper helper, Udi udi, bool usingUdiToIdCache) { return(usingUdiToIdCache && udi is GuidUdi guidUdi && GuidToIdCache.TryGetId(guidUdi.Guid, out int id) ? helper.TypedContent(id) : helper.TypedContent(udi)); }