예제 #1
0
        /// <summary>
        /// Generates all schema classes for the specified service
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public CodeNamespace GenerateSchemaClasses(IService service)
        {
            service.ThrowIfNull("service");

            logger.Debug("Starting to generate schemas for {1} in namespace {0}", schemaNamespace, service.Name);
            LogDecorators();
            var codeNamespace = new CodeNamespace(schemaNamespace);

            codeNamespace.Imports.Add(new CodeNamespaceImport("System"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Collections"));
            codeNamespace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
            SchemaGenerator generator = new SchemaGenerator(decorators);

            // Generate implementation details
            IDictionary <JsonSchema, SchemaImplementationDetails> implementationDetails =
                implementationDetailsGenerator.GenerateDetails(service);

            // Generate schemas
            foreach (var schemaPair in service.Schemas)
            {
                logger.Debug("Generating Schema {0}", schemaPair.Key);

                // Create schema
                codeNamespace.Types.Add(
                    generator.CreateClass(schemaPair.Value, implementationDetails, service.Schemas.Keys));
            }
            return(codeNamespace);
        }
예제 #2
0
        public void CreateClassParameterCheck()
        {
            var empty     = new List <ISchemaDecorator>(0);
            var schemaGen = new SchemaGenerator(empty);

            Assert.Throws(
                typeof(ArgumentNullException), () => schemaGen.CreateClass(null, null, Enumerable.Empty <string>()));
        }
예제 #3
0
        public void CreateClassSingle()
        {
            var        empty     = new List <ISchemaDecorator>(0);
            var        schemaGen = new SchemaGenerator(empty);
            MockSchema schema    = new MockSchema
            {
                Id            = "mockSchemaObject",
                Name          = "mockSchemaObject",
                SchemaDetails = MockSchema.CreateSimpleSchema("mockSchemaObject")
            };
            var typeDeclaration = schemaGen.CreateClass(
                schema, new Dictionary <JsonSchema, SchemaImplementationDetails>(), Enumerable.Empty <string>());

            Assert.IsNotNull(typeDeclaration);
            Assert.AreEqual("MockSchemaObject", typeDeclaration.Name);
            Assert.IsEmpty(typeDeclaration.Members);
        }
예제 #4
0
        public void CreateClassWithSingleDecorator()
        {
            var oneDecorator = new List <ISchemaDecorator>(1)
            {
                new CountingDecorator()
            };
            var        schemaGen = new SchemaGenerator(oneDecorator);
            MockSchema schema    = new MockSchema
            {
                Id            = "mockSchemaObject",
                Name          = "mockSchemaObject",
                SchemaDetails = MockSchema.CreateSimpleSchema("mockSchemaObject")
            };

            schemaGen.CreateClass(
                schema, new Dictionary <JsonSchema, SchemaImplementationDetails>(), Enumerable.Empty <string>());
            Assert.AreEqual(1, ((CountingDecorator)oneDecorator[0]).Count);
        }
예제 #5
0
        public void CreateClassWithMultipleDecorators()
        {
            var once       = new CountingDecorator();
            var threeTimes = new CountingDecorator();
            var decorators = new List <ISchemaDecorator>(4)
            {
                once, threeTimes, threeTimes, threeTimes
            };
            var        schemaGen = new SchemaGenerator(decorators);
            MockSchema schema    = new MockSchema
            {
                Id            = "mockSchemaObject",
                Name          = "mockSchemaObject",
                SchemaDetails = MockSchema.CreateSimpleSchema("mockSchemaObject")
            };

            schemaGen.CreateClass(
                schema, new Dictionary <JsonSchema, SchemaImplementationDetails>(), Enumerable.Empty <string>());
            Assert.AreEqual(1, ((CountingDecorator)decorators[0]).Count);
            Assert.AreEqual(3, ((CountingDecorator)decorators[1]).Count);
            Assert.AreEqual(3, ((CountingDecorator)decorators[2]).Count);
            Assert.AreEqual(3, ((CountingDecorator)decorators[3]).Count);
        }