public void WhenGetItemIsCalled_ThenTheReturnedItem_IsCorrect() { //Assign const long id = 1L; ContentType.AddPropity("Test", "string"); var item = Sut.CreateItem(ContentType); item.Id = id; const string propityValue = "NotDefaultValue"; var fi = new FurnaceItemInformation <long>() { Id = id }; var returnJson = new Stub { FurnaceItemInformation = fi, Test = propityValue }.BuildSerialisedString(); var key = RedisBackedFurnaceItems.CreateItemKey(id, ContentType); Client.Hashes[key][SiteConfiguration.DefaultSiteCulture.Name].Returns(returnJson); //Act var result = Sut.GetItem(id, ContentType); //Assert Assert.That(result.Id, Is.EqualTo(id)); Assert.That(result["Test"], Is.EqualTo(propityValue)); Assert.That(result.ContentType.Name == ContentTypeName); }
public void CanGenerateItemChildrenKey() { var type = typeof(Stub); var key = RedisBackedFurnaceItems.CreateItemChildrenKey(Id, type); Assert.That(key, Is.EqualTo(RedisBackedFurnaceItems.ItemChildrenSortedSetKey.FormatWith(type.FullName, Id))); }
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)); }
public void RedisBackedFurnaceItemsTestsSetUp() { Client = Substitute.For<IRedisClient>(); ContentTypes = Substitute.For<IFurnaceContentTypes>(); ContentType = new ContentType { Name = ContentTypeName, Namespace = ContentTypeNamespace }; SiteConfiguration = Substitute.For<IFurnaceSiteConfiguration>(); SiteConfiguration.DefaultSiteCulture.Returns(new CultureInfo("en-AU")); Sut = new RedisBackedFurnaceItems(Client, SiteConfiguration, ContentTypes); }
public void LocalisationTestsSetUp() { Id = 99L; Key = RedisBackedFurnaceItems.CreateItemKey(Id, typeof(Stub)); var fi = new FurnaceItemInformation <long>(); DefultCultureStub = new Stub { Test = "Hello" }; Client.Hashes[Key][SiteConfiguration.DefaultSiteCulture.Name].Returns(DefultCultureStub.BuildSerialisedString()); }
public void RedisBackedFurnaceItemsTestsSetUp() { Client = Substitute.For <IRedisClient>(); ContentTypes = Substitute.For <IFurnaceContentTypes>(); ContentType = new ContentType { Name = ContentTypeName, Namespace = ContentTypeNamespace }; SiteConfiguration = Substitute.For <IFurnaceSiteConfiguration>(); SiteConfiguration.DefaultSiteCulture.Returns(new CultureInfo("en-AU")); Sut = new RedisBackedFurnaceItems(Client, SiteConfiguration, ContentTypes); }
public static void Save(this IItem <long> item, IRedisClient client) { var key = RedisBackedFurnaceItems.CreateItemKey(item.Id, item.ContentType); item.Propities.Add("FurnaceItemInformation", item.FurnaceItemInformation); client.Hashes[key].Add("en-AU", TypeSerializer.SerializeToString(item.Propities)); var setKey = RedisBackedFurnaceItems.CreateItemChildrenKey( item.FurnaceItemInformation.ParentId, item.FurnaceItemInformation.ParentContentTypeFullName); client.SortedSets[setKey].Add(key); }
public void WhenStoreItemIsCalled_ThenClientReceives_CorrectObject() { //Assign const long id = 1L; ContentType.AddPropity("Test", "string"); var item = Sut.CreateItem(ContentType); item.Id = id; //Act Sut.SetItem(id, item); //Assert var key = RedisBackedFurnaceItems.CreateItemKey(id, ContentType); var value = TypeSerializer.SerializeToString(item.Propities); Client.Hashes[key].Received().Add(Arg.Any <string>(), value); }
public void WhenTypedGetItemIsCalled_ThenTheReturnedItem_IsCorrect() { //Assign const long id = 1L; const string propityValue = "NotDefault Value"; var fi = new FurnaceItemInformation <long>(); var returnJon = new Stub { FurnaceItemInformation = fi, Test = propityValue }.BuildSerialisedString(); var key = RedisBackedFurnaceItems.CreateItemKey(id, typeof(Stub)); Client.Hashes[key][Arg.Any <string>()].Returns(returnJon); //Act var result = Sut.GetItem <Stub>(id); //Assert 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); }