public void Serialize_Null_ReturnsEmptyString() { var serializer = new PageTypeComponentSerializer(); string actual = serializer.Serialize(null); string expected = string.Empty; Assert.That(actual, Is.EqualTo(expected)); }
public void Deserialize_ComponentWithNullValues_DoesNotThrowException() { var nodeFactory = new PageTypeContentComponentFactory(); var node = nodeFactory.Create <ContentComponentTest>(); var serialiser = new PageTypeComponentSerializer(); string nodeXml = serialiser.Serialize(node); var deserializer = new PageTypeComponentDeserializer(); Assert.That(() => deserializer.Deserialize <ContentComponentTest>(nodeXml), Throws.Nothing); }
private static PageMetadata CreatePageMetadataComponent() { var nodeFactory = new PageTypeContentComponentFactory(); var node = nodeFactory.Create <PageMetadata>(); node.SetValue(nameof(PageMetadata.DocumentPageTitle), "Fake page title"); node.SetValue(nameof(PageMetadata.DocumentPageDescription), "Fake page description"); var serialiser = new PageTypeComponentSerializer(); node.PageMetadataOpenGraph = serialiser.Serialize(CreateOpenGraphMetadataComponent()); return(node); }
public void Deserialize_ComponentOfType_RetainsSerializedValues() { var serializer = new PageTypeComponentSerializer(); PageMetadata expected = TestData.PageMetadataComponent; string componentXml = serializer.Serialize(expected); var deserializer = new PageTypeComponentDeserializer(); PageMetadata actual = deserializer.Deserialize <PageMetadata>(componentXml); Assert.Multiple(() => { Assert.That(actual.DocumentPageTitle, Is.EqualTo(expected.DocumentPageTitle)); Assert.That(actual.DocumentPageDescription, Is.EqualTo(expected.DocumentPageDescription)); }); }
public void Deserialize_NestedComponentOfType_RetainsSerializedValues() { var serializer = new PageTypeComponentSerializer(); PageMetadata metadata = TestData.PageMetadataComponent; OpenGraphMetadata expected = metadata.OpenGraph; string componentXml = serializer.Serialize(metadata); var deserializer = new PageTypeComponentDeserializer(); OpenGraphMetadata actual = deserializer.Deserialize <PageMetadata>(componentXml).OpenGraph; Assert.Multiple(() => { Assert.That(actual.OpenGraphMetadataTitle, Is.EqualTo(expected.OpenGraphMetadataTitle)); Assert.That(actual.OpenGraphMetadataDescription, Is.EqualTo(expected.OpenGraphMetadataDescription)); }); }
public void Serialize_Component_ReturnsValidXml() { var serializer = new PageTypeComponentSerializer(); PageMetadata component = TestData.PageMetadataComponent; string componentXml = serializer.Serialize(component); try { var actual = new XmlDocument(); actual.LoadXml(componentXml); Assert.Pass(); } catch (XmlException e) { Assert.Fail(e.Message); } }
public void Deserialize_NestedComponent_RetainsSerializedValues() { var serializer = new PageTypeComponentSerializer(); PageMetadata metadata = TestData.PageMetadataComponent; OpenGraphMetadata expected = metadata.OpenGraph; string componentXml = serializer.Serialize(metadata); var deserializer = new PageTypeComponentDeserializer(); TreeNode actual = deserializer.Deserialize(PageMetadata.CLASS_NAME, componentXml) .GetPageTypeComponent(OpenGraphMetadata.CLASS_NAME, nameof(PageMetadata.PageMetadataOpenGraph)); Assert.Multiple(() => { Assert.That(actual.GetStringValue(nameof(OpenGraphMetadata.OpenGraphMetadataTitle), string.Empty), Is.EqualTo(expected.OpenGraphMetadataTitle)); Assert.That(actual.GetStringValue(nameof(OpenGraphMetadata.OpenGraphMetadataDescription), string.Empty), Is.EqualTo(expected.OpenGraphMetadataDescription)); }); }
public void GetContentComponent_ComponentField_ReturnsComponent() { var serializer = new PageTypeComponentSerializer(); var expected = TestData.PageMetadataComponent; var page = TreeNode.New <Page>().With(node => { node.DocumentName = "Fake page"; node.PageMetadata = serializer.Serialize(expected); }); // `page.Metadata` uses the extension method we are testing PageMetadata actual = page.Metadata; Assert.Multiple(() => { Assert.That(actual.DocumentPageTitle, Is.EqualTo(expected.DocumentPageTitle)); Assert.That(actual.DocumentPageDescription, Is.EqualTo(expected.DocumentPageDescription)); Assert.That(actual.OpenGraph.OpenGraphMetadataTitle, Is.EqualTo(expected.OpenGraph.OpenGraphMetadataTitle)); Assert.That(actual.OpenGraph.OpenGraphMetadataDescription, Is.EqualTo(expected.OpenGraph.OpenGraphMetadataDescription)); }); }