public void GivenACacheModel_WhenItsSerializedAndDeserializedWithAnySerializer_TheResultsAreTheSame() { var jsonSerializer = new JsonContentNestedDataSerializer(); var msgPackSerializer = new MsgPackContentNestedDataSerializer(Mock.Of <IPropertyCacheCompression>()); var now = DateTime.Now; var cacheModel = new ContentCacheDataModel { PropertyData = new Dictionary <string, PropertyData[]> { ["propertyOne"] = new[] { new PropertyData { Culture = "en-US", Segment = "test", Value = "hello world" } }, ["propertyTwo"] = new[] { new PropertyData { Culture = "en-US", Segment = "test", Value = "Lorem ipsum" } } }, CultureData = new Dictionary <string, CultureVariation> { ["en-US"] = new CultureVariation { Date = now, IsDraft = false, Name = "Home", UrlSegment = "home" } }, UrlSegment = "home" }; var content = Mock.Of <IReadOnlyContentBase>(x => x.ContentTypeId == 1); var json = jsonSerializer.Serialize(content, cacheModel, false).StringData; var msgPack = msgPackSerializer.Serialize(content, cacheModel, false).ByteData; Console.WriteLine(json); Console.WriteLine(msgPackSerializer.ToJson(msgPack)); var jsonContent = jsonSerializer.Deserialize(content, json, null, false); var msgPackContent = msgPackSerializer.Deserialize(content, null, msgPack, false); CollectionAssert.AreEqual(jsonContent.CultureData.Keys, msgPackContent.CultureData.Keys); CollectionAssert.AreEqual(jsonContent.PropertyData.Keys, msgPackContent.PropertyData.Keys); CollectionAssert.AreEqual(jsonContent.CultureData.Values, msgPackContent.CultureData.Values, new CultureVariationComparer()); CollectionAssert.AreEqual(jsonContent.PropertyData.Values, msgPackContent.PropertyData.Values, new PropertyDataComparer()); Assert.AreEqual(jsonContent.UrlSegment, msgPackContent.UrlSegment); }
public void GivenACacheModel_WhenItsSerializedAndDeserializedWithAnySerializer_TheResultsAreTheSame() { var jsonSerializer = new JsonContentNestedDataSerializer(); var msgPackSerializer = new MsgPackContentNestedDataSerializer(Mock.Of <IPropertyCacheCompression>()); var now = DateTime.Now; var cacheModel = new ContentCacheDataModel { PropertyData = new Dictionary <string, PropertyData[]> { ["propertyOne"] = new[] { new PropertyData { Culture = "en-US", Segment = "test", Value = "hello world" } }, ["propertyTwo"] = new[] { new PropertyData { Culture = "en-US", Segment = "test", Value = "Lorem ipsum" }, }, }, CultureData = new Dictionary <string, CultureVariation> {