private static void AssertElements(ComplexTestModel expected, ComplexTestModel actual)
 {
     AssertIdentifiers(expected.TeaserImage.Select(x => x.Id.Value), actual.TeaserImage.Select(x => x.Id.Value));
     Assert.Equal(expected.PostDate, actual.PostDate);
     Assert.Equal(expected.UrlPattern, actual.UrlPattern);
     AssertIdentifiers(expected.RelatedArticles?.Select(x => x.Id.Value), actual.RelatedArticles?.Select(x => x.Id.Value));
     Assert.Equal(expected.BodyCopy, actual.BodyCopy);
     AssertIdentifiers(expected.Personas?.Select(x => x.Id.Value), actual.Personas?.Select(x => x.Id.Value));
     Assert.Equal(expected.Title, actual.Title);
     Assert.Equal(expected.MetaDescription, actual.MetaDescription);
     Assert.Equal(expected.MetaKeywords, actual.MetaKeywords);
     Assert.Equal(expected.Summary, actual.Summary);
 }
Exemplo n.º 2
0
    private static IEnumerable <dynamic> PrepareMockDynamicResponse(ComplexTestModel model)
    {
        var type = typeof(ComplexTestModel);

        var elements = new List <dynamic> {
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.Title))?.GetKontentElementId() },
                value   = model.Title.Value
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.Rating))?.GetKontentElementId() },
                value   = model.Rating.Value
            },
            new
            {
                element          = new { id = type.GetProperty(nameof(ComplexTestModel.SelectedForm))?.GetKontentElementId() },
                value            = model.SelectedForm.Value,
                searchable_value = model.SelectedForm.SearchableValue
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.PostDate))?.GetKontentElementId() },
                value   = model.PostDate.Value
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.UrlPattern))?.GetKontentElementId() },
                value   = model.UrlPattern.Value,
                mode    = model.UrlPattern.Mode
            },
            new
            {
                element    = new { id = type.GetProperty(nameof(ComplexTestModel.BodyCopy))?.GetKontentElementId() },
                value      = model.BodyCopy.Value,
                components = model.BodyCopy.Components
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.RelatedArticles))?.GetKontentElementId() },
                value   = model.RelatedArticles.Value
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.TeaserImage))?.GetKontentElementId() },
                value   = model.TeaserImage.Value
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.Personas))?.GetKontentElementId() },
                value   = model.Personas.Value
            },
            new
            {
                element = new { id = type.GetProperty(nameof(ComplexTestModel.Options))?.GetKontentElementId() },
                value   = model.Options.Value
            },
        };

        var serialized = JsonConvert.SerializeObject(elements, new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore
        });

        return(JsonConvert.DeserializeObject <IEnumerable <dynamic> >(serialized, new JsonSerializerSettings {
            Converters = new JsonConverter[] { new DynamicObjectJsonConverter() }
        }));
    }