public void Deserialize_DeserializesNewItem() { using (var db = new Db()) { var deserializer = CreateTestDeserializer(db); var item = new FakeItem( id: Guid.NewGuid(), parentId: ItemIDs.ContentRoot.Guid, templateId: _testTemplateId.Guid, versions: new[] { new FakeItemVersion(1, "en", new FakeFieldValue("Hello", fieldId: _testVersionedFieldId.Guid)) }); var deserialized = deserializer.Deserialize(item); Assert.NotNull(deserialized); var fromDb = db.GetItem(new ID(item.Id)); Assert.NotNull(fromDb); Assert.Equal("Hello", fromDb[_testVersionedFieldId]); Assert.Equal(item.ParentId, fromDb.ParentID.Guid); Assert.Equal(item.TemplateId, fromDb.TemplateID.Guid); } }
public void Includes_ExcludesSerializedItemByPath() { var predicate = CreateTestPredicate(CreateTestConfiguration()); var item = new FakeItem(path:ExcludedPath); var includes = predicate.Includes(item); Assert.False(includes.IsIncluded, "Exclude serialized item by path failed."); }
public void Includes_ExcludesSerializedItemByDatabase() { var predicate = CreateTestPredicate(CreateTestConfiguration()); var item = new FakeItem(path: IncludedPath, databaseName: ExcludedDatabase); var includes = predicate.Includes(item); Assert.False(includes.IsIncluded, "Exclude serialized item by database failed."); }
public void ShouldRebasePathOfChildren() { var root = new FakeItem(children: new[] { new FakeItem() }, id:Guid.NewGuid()); var rebase = new PathRebasingItemData(root, "/sitecore/new", Guid.NewGuid()); rebase.GetChildren().First().Path.Should().Be("/sitecore/new/test item/test item"); rebase.GetChildren().First().ParentId.Should().Be(root.Id); }
public void IsConsistent_ReturnsTrue_WhenEmpty() { var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>(); var testChecker = new DuplicateIdConsistencyChecker(testLogger); var testItem = new FakeItem(ID.NewID.Guid); Assert.True(testChecker.IsConsistent(testItem)); }
public void ShouldRebasePath() { var root = new FakeItem(); var pid = Guid.NewGuid(); var rebase = new PathRebasingItemData(root, "/sitecore/new", pid); rebase.Path.Should().Be("/sitecore/new/test item"); rebase.ParentId.Should().Be(pid); }
public void Save_ShouldDeserializeItem() { var deserializer = Substitute.For<IDeserializer>(); var dataStore = new SitecoreDataStore(deserializer); var item = new FakeItem(); dataStore.Save(item); deserializer.Received().Deserialize(item); }
public void LoadTree_SkipsRootWhenExcluded() { var serializedRootItem = new FakeItem(); var predicate = CreateExclusiveTestPredicate(); var logger = Substitute.For<ISerializationLoaderLogger>(); var loader = CreateTestLoader(predicate: predicate, logger: logger); TestLoadTree(loader, serializedRootItem); logger.Received().SkippedItemPresentInSerializationProvider(serializedRootItem, Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()); }
public void ShouldThrowIfTreeRetryFails() { var retryer = new DeserializeFailureRetryer(); var item = new FakeItem(); var exception = new Exception(); retryer.AddTreeRetry(item, exception); Action<IItemData> callback = delegate (IItemData x) { throw new Exception(); }; Assert.Throws<DeserializationAggregateException>(() => retryer.RetryAll(Substitute.For<ISourceDataStore>(), callback, callback)); }
public void ShouldExcludeChildrenExcludedByPredicate() { var child = new FakeItem(); var parent = new FakeItem(children: new[] { child }); var predicate = Substitute.For<IPredicate>(); predicate.Includes(child).Returns(new PredicateResult(false)); Assert.NotEmpty(parent.GetChildren()); var filtered = new PredicateFilteredItemData(parent, predicate); Assert.Empty(filtered.GetChildren()); }
public void LoadTree_LoadsRootWhenIncluded() { var serializedRootItem = new FakeItem(); var evaluator = Substitute.For<IEvaluator>(); var sourceData = Substitute.For<ISourceDataStore>(); sourceData.GetByPathAndId(serializedRootItem.Path, serializedRootItem.Id, serializedRootItem.DatabaseName).Returns((IItemData)null); var loader = CreateTestLoader(evaluator: evaluator, sourceDataStore: sourceData); TestLoadTree(loader, serializedRootItem); evaluator.Received().EvaluateNewSerializedItem(serializedRootItem); }
public void ShouldRetrieveTreeRetry() { var retryer = new DeserializeFailureRetryer(); var item = new FakeItem(); var exception = new Exception(); retryer.AddTreeRetry(item, exception); var callback = Substitute.For<Action<IItemData>>(); retryer.RetryAll(Substitute.For<ISourceDataStore>(), callback, callback); callback.Received()(item); }
public void LoadTree_LoadsChildOfRootWhenIncluded() { var dataStore = Substitute.For<ITargetDataStore>(); var root = new FakeItem(); var child = new FakeItem(parentId: root.Id, id: Guid.NewGuid()); dataStore.GetChildren(root).Returns(new[] { child }); var evaluator = Substitute.For<IEvaluator>(); var loader = CreateTestLoader(evaluator: evaluator, targetDataStore: dataStore); TestLoadTree(loader, root); evaluator.Received().EvaluateUpdate(Arg.Any<IItemData>(), child); }
public void IsConsistent_ReturnsFalse_WhenDuplicated() { var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>(); var testChecker = new DuplicateIdConsistencyChecker(testLogger); var duplicatedId = ID.NewID.Guid; var testItem1 = new FakeItem(duplicatedId); var testItem2 = new FakeItem(duplicatedId); testChecker.AddProcessedItem(testItem1); Assert.False(testChecker.IsConsistent(testItem2)); }
public void LoadTree_SkipsChildOfRootWhenExcluded() { var dataStore = Substitute.For<ITargetDataStore>(); var root = new FakeItem(); var child = new FakeItem(parentId:root.Id, id:Guid.NewGuid()); dataStore.GetChildren(root).Returns(new[] {child}); var predicate = CreateExclusiveTestPredicate(new[] { root }); var logger = Substitute.For<ISerializationLoaderLogger>(); var loader = CreateTestLoader(predicate: predicate, logger:logger, targetDataStore: dataStore); TestLoadTree(loader, root); logger.Received().SkippedItemPresentInSerializationProvider(Arg.Is<IItemData>(data => data.Id == child.Id), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()); }
public void IsConsistent_ReturnsTrue_WhenDuplicatedIdsAreInDifferentDatabases() { var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>(); var testChecker = new DuplicateIdConsistencyChecker(testLogger); var duplicatedId = ID.NewID.Guid; var testItem1 = new FakeItem(duplicatedId, "master"); var testItem2 = new FakeItem(duplicatedId, "core"); testChecker.AddProcessedItem(testItem1); Assert.True(testChecker.IsConsistent(testItem2)); }
public void IsConsistent_LogsError_WhenDuplicated() { var testLogger = Substitute.For<IDuplicateIdConsistencyCheckerLogger>(); var testChecker = new DuplicateIdConsistencyChecker(testLogger); var duplicatedId = ID.NewID.Guid; var testItem1 = new FakeItem(duplicatedId); var testItem2 = new FakeItem(duplicatedId); testChecker.AddProcessedItem(testItem1); testChecker.IsConsistent(testItem2); testLogger.Received().DuplicateFound(Arg.Any<DuplicateIdConsistencyChecker.DuplicateIdEntry>(), testItem2); }
public void GetRootItems_ReturnsExpectedRootValues() { var sourceItem1 = new FakeItem(); var sourceItem2 = new FakeItem(); var sourceDataProvider = Substitute.For<IDataStore>(); sourceDataProvider.GetByPath("master", "/sitecore/layout/Simulators").Returns(new[] { sourceItem1 }); sourceDataProvider.GetByPath("core", "/sitecore/content").Returns(new[] { sourceItem2 }); var predicate = new SerializationPresetPredicate(CreateTestConfiguration()); var roots = predicate.GetRootPaths(); Assert.True(roots.Length == 3, "Expected three root paths from test config"); Assert.Equal(roots[0].DatabaseName, "master"); Assert.Equal(roots[0].Path, "/sitecore/layout/Simulators"); Assert.Equal(roots[1].DatabaseName, "core"); Assert.Equal(roots[1].Path, "/sitecore/content"); }
public void GetChildren_ReturnsEmptyEnumerable_IfItemDoesNotExist(Db db) { var dataStore = CreateTestDataStore(); var parent = new FakeItem(Guid.NewGuid(), name: "LOL"); dataStore.GetChildren(parent).Should().NotBeNull().And.BeEmpty(); }
public void YamlFormatter_WritesItem_WithFieldFormatter_AsExpected() { var xmlConfigNode = @"<serializationFormatter> <fieldFormatter type=""Rainbow.Formatting.FieldFormatters.MultilistFormatter, Rainbow"" /> </serializationFormatter>"; var configDoc = new XmlDocument(); configDoc.LoadXml(xmlConfigNode); var formatter = new YamlSerializationFormatter(configDoc.DocumentElement, null); var item = new FakeItem( id: new Guid("a4f985d9-98b3-4b52-aaaf-4344f6e747c6"), parentId: new Guid("001dd393-96c5-490b-924a-b0f25cd9efd8"), templateId: new Guid("007a464d-5b09-4d0e-8481-cb6a604a5948"), path: "/sitecore/content/test", sharedFields: new[] { new FakeFieldValue("{35633C96-8494-4C05-A62A-954E2B401A4D}|{1486633B-3A5D-40D6-99D5-920FDFA63617}", "Multilist", new Guid("549fa670-79ab-4810-9450-aba0c06a2b87"), "Multilist Field") }, name: "test"); var expectedYml = @"--- ID: a4f985d9-98b3-4b52-aaaf-4344f6e747c6 Parent: 001dd393-96c5-490b-924a-b0f25cd9efd8 Template: 007a464d-5b09-4d0e-8481-cb6a604a5948 Path: /sitecore/content/test DB: master SharedFields: - ID: 549fa670-79ab-4810-9450-aba0c06a2b87 Hint: Multilist Field Type: Multilist Value: | {35633C96-8494-4C05-A62A-954E2B401A4D} {1486633B-3A5D-40D6-99D5-920FDFA63617} "; using (var ms = new MemoryStream()) { formatter.WriteSerializedItem(item, ms); ms.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(ms)) { var yml = reader.ReadToEnd(); Assert.Equal(expectedYml, yml); } } }
public void YamlFormatter_WritesItem_AsExpected() { var formatter = new YamlSerializationFormatter(null, null); var item = new FakeItem( id: new Guid("a4f985d9-98b3-4b52-aaaf-4344f6e747c6"), parentId: new Guid("001dd393-96c5-490b-924a-b0f25cd9efd8"), templateId: new Guid("007a464d-5b09-4d0e-8481-cb6a604a5948"), path: "/sitecore/content/test", sharedFields: new[] { new FakeFieldValue("SHARED", string.Empty, new Guid("549fa670-79ab-4810-9450-aba0c06a2b87"), "Text Shared") }, name: "test", branchId: new Guid("25bed78c-4957-4165-998a-ca1b52f67497"), versions: new[] { new FakeItemVersion(1, "en", new FakeFieldValue("20140918T062658:635466184182719253", string.Empty, new Guid("25bed78c-4957-4165-998a-ca1b52f67497"), "__Created")), }, unversionedFields: new[] { new ProxyItemLanguage(new CultureInfo("en")) { Fields = new[] { new FakeFieldValue("unversioned", string.Empty, new Guid("ffffd78c-4957-4165-998a-ca1b52f67497"), "Unversioned") } } }); var expectedYml = @"--- ID: a4f985d9-98b3-4b52-aaaf-4344f6e747c6 Parent: 001dd393-96c5-490b-924a-b0f25cd9efd8 Template: 007a464d-5b09-4d0e-8481-cb6a604a5948 Path: /sitecore/content/test DB: master BranchID: 25bed78c-4957-4165-998a-ca1b52f67497 SharedFields: - ID: 549fa670-79ab-4810-9450-aba0c06a2b87 Hint: Text Shared Value: SHARED Languages: - Language: en Fields: - ID: ffffd78c-4957-4165-998a-ca1b52f67497 Hint: Unversioned Value: unversioned Versions: - Version: 1 Fields: - ID: 25bed78c-4957-4165-998a-ca1b52f67497 Hint: __Created Value: 20140918T062658:635466184182719253 "; using (var ms = new MemoryStream()) { formatter.WriteSerializedItem(item, ms); ms.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(ms)) { var yml = reader.ReadToEnd(); Assert.Equal(expectedYml, yml); } } }
public void Includes_IncludesSerializedItemByDatabase() { var predicate = CreateTestPredicate(CreateTestConfiguration()); // ReSharper disable once RedundantArgumentDefaultValue var item = new FakeItem(path:IncludedPath, databaseName: IncludedDatabase); var includes = predicate.Includes(item); Assert.True(includes.IsIncluded, "Include serialized item by database failed."); }
public void ShouldReturnExpectedValue() { var fake = new FakeItem(); Assert.Equal("master:/sitecore/content/test item (" + fake.Id + ")", fake.GetDisplayIdentifier()); }
public void Includes_IncludesSerializedItemByPath_WhenCaseDoesNotMatch() { var predicate = CreateTestPredicate(CreateTestConfiguration()); var item = new FakeItem(path: IncludedPath.ToUpperInvariant()); var includes = predicate.Includes(item); Assert.True(includes.IsIncluded, "Include serialized item by path failed."); }
public void Remove_ReturnsFalse_WhenItemDoesNotExist(Db db) { var dataStore = CreateTestDataStore(); var item = new FakeItem(Guid.NewGuid(), name: "lol"); dataStore.Remove(item).Should().BeFalse(); }
public void Includes_ExcludesSerializedItemByPath_WhenChildrenOfRootAreExcluded() { var predicate = CreateTestPredicate(CreateTestConfiguration()); var item = new FakeItem(path: "/test/child"); var includes = predicate.Includes(item); Assert.False(includes.IsIncluded, "Exclude serialized item by all children failed."); }
public void Includes_IncludesSerializedItemByPath_WhenChildrenOfRootAreExcluded_AndPathIsRootItem() { var predicate = CreateTestPredicate(CreateTestConfiguration()); var item = new FakeItem(path: "/test"); var includes = predicate.Includes(item); Assert.True(includes.IsIncluded, "Included parent serialized item when all children excluded failed."); }