public void GivenKeyAsString_WhenTypedGetItemIsCalled_ThenCorrectItemCanBeConvertedToCorectType() { //Assign const long id = 1L; const string propityValue = "NotDefaultValue"; var fi = new FurnaceItemInformation <long> { Id = id, ContentTypeFullName = ContentType.FullName }; var returnJson = new Stub { FurnaceItemInformation = fi, Test = propityValue }.BuildSerialisedString(); var key = RedisBackedFurnaceItems.CreateItemKey(id, ContentType); Client.Hashes[key][SiteConfiguration.DefaultSiteCulture.Name].Returns(returnJson); ContentTypes.GetContentTypes().Returns(new[] { ContentType }); //Act var result = Sut.GetItem(key).As <Stub>(); //Assert Assert.That(result, Is.TypeOf <Stub>()); Assert.That(result.Test, Is.EqualTo(propityValue)); }
private void AddChild <T>(long parentId, Type parenType, long childId, string test) where T : BaseStub, new() { var type = typeof(T); var contentType = new ContentType { Name = type.Name, Namespace = type.Namespace }; var furnaceItemInformation = new FurnaceItemInformation <long> { Id = childId, ContentTypeFullName = contentType.FullName, ParentId = parentId, ParentContentTypeFullName = parenType.FullName }; var stub = new T { FurnaceItemInformation = furnaceItemInformation, Test = test }; var itemKey = RedisBackedFurnaceItems.CreateItemKey(furnaceItemInformation.Id, type); var setKey = RedisBackedFurnaceItems.CreateItemChildrenKey(parentId, parenType); _childSortedSet.Add(itemKey); Client.Hashes[itemKey][SiteConfiguration.DefaultSiteCulture.Name].Returns(stub.BuildSerialisedString()); Client.SortedSets[setKey].Returns(_childSortedSet); if (_contentTypes.All(x => x.FullName != contentType.FullName)) { _contentTypes.Add(contentType); } ContentTypes.GetContentTypes().Returns(_contentTypes); }