Ejemplo n.º 1
0
        public void TestServiceModelBuilderCreateServiceModel(string name, IServiceModelFactory serviceModelFactory, IConventions conventions, IServiceModel expectedServiceModel)
        {
            this.Output.WriteLine("Test Name: {0}", name);
            this.Output.WriteLine(String.Empty);

            // Arrange
            var serializerSettings = new JsonSerializerSettings
            {
                Converters = new[]
                {
                    (JsonConverter) new StringEnumConverter()
                },
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Include
            };

            var expectedJson = expectedServiceModel.ToJson(serializerSettings);

            this.Output.WriteLine("Expected ServiceModel");
            this.Output.WriteLine(expectedJson);

            // Act
            var actualServiceModel = serviceModelFactory.Create(conventions);

            this.Output.WriteLine(String.Empty);

            var actualJson = actualServiceModel.ToJson(serializerSettings);

            this.Output.WriteLine("Actual ServiceModel");
            this.Output.WriteLine(actualJson);

            // Assert
            ServiceModelAssert.Equal(expectedServiceModel, actualServiceModel);
        }
Ejemplo n.º 2
0
        public void TestServiceModelParse(string name, IServiceModel expected)
        {
            this.Output.WriteLine("Test Name: {0}", name);
            this.Output.WriteLine(String.Empty);

            // Arrange
            var serializerSettings = new JsonSerializerSettings
            {
                Converters = new JsonConverter[]
                {
                    new StringEnumConverter(),

                    // Metadata Converters
                    new AttributeInfoConverter(),
                    new AttributesInfoConverter(),
                    new ComplexTypeConverter(),
                    new HypermediaInfoConverter(),
                    new LinkInfoConverter(),
                    new LinksInfoConverter(),
                    new MetaInfoConverter(),
                    new RelationshipInfoConverter(),
                    new RelationshipsInfoConverter(),
                    new ResourceIdentityInfoConverter(),
                    new ResourceTypeConverter(),
                    new ServiceModelConverter(),
                    new PropertyInfoConverter()         // needs to be last in the order to avoid casting exceptions
                },
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };
            var json = expected.ToJson(serializerSettings);

            // Act
            this.Output.WriteLine(json);
            var actual = JsonObject.Parse <IServiceModel>(json, serializerSettings);

            // Assert
            ServiceModelAssert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void TestServiceModelToJson(string name, IServiceModel expected)
        {
            this.Output.WriteLine("Test Name: {0}", name);
            this.Output.WriteLine(String.Empty);

            // Arrange
            var serializerSettings = new JsonSerializerSettings
            {
                Converters = new[]
                {
                    (JsonConverter) new StringEnumConverter()
                },
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            // Act
            var actual = expected.ToJson(serializerSettings);

            this.Output.WriteLine(actual);

            // Assert
            Assert.NotNull(actual);
        }