Ejemplo n.º 1
0
        public void GenerateCodeThatCreateProtobufModel()
        {
            var generator = new ProtobufContractGenerator(@"..\..\Resources\ProtobufMapping.xml");

            // BEGINNING OF GENERATED CODE:
            // This code is generated by running the GenerateCodeThatCreateProtobufModel() method in ProtobufContractGeneratorTest
            // (but you have to manually copy it)

            Debug.WriteLine(@"// BEGINNING OF GENERATED CODE");
            Debug.WriteLine(@"// This code is generated by running the GenerateCodeThatCreateProtobufModel() method in ProtobufContractGeneratorTest");
            Debug.WriteLine(@"// (but you have to manually copy it here)");

            generator.GenerateContractCode("AgGateway.ADAPT.ApplicationDataModel.dll");

            // These are manually added.  They are used for reference layer protobuf
            Debug.WriteLine(@"model[typeof(RasterData<EnumeratedRepresentation, EnumerationMember>)].Add(463, ""Representation"");");
            Debug.WriteLine(@"model[typeof(RasterData<StringRepresentation, string>)].Add(464, ""Representation"");");
            Debug.WriteLine(@"model[typeof(RasterData<NumericRepresentation, NumericValue>)].Add(465, ""Representation"");");

            Debug.WriteLine(@"model[typeof(SerializableRasterData<string>)].Add(466, ""values"");");
            Debug.WriteLine(@"model[typeof(SerializableRasterData<EnumerationMember>)].Add(467, ""values"");");
            Debug.WriteLine(@"model[typeof(SerializableRasterData<NumericValue>)].Add(468, ""values"");");
            Debug.WriteLine(@"model[typeof(SerializableRasterData<string>)].Add(469, ""Representation"");");
            Debug.WriteLine(@"model[typeof(SerializableRasterData<EnumerationMember>)].Add(470, ""Representation"");");
            Debug.WriteLine(@"model[typeof(SerializableRasterData<NumericValue>)].Add(471, ""Representation"");");

            Debug.WriteLine(@"model[typeof(SerializableReferenceLayer)].Add(472, ""ReferenceLayer"");");
            Debug.WriteLine(@"model[typeof(SerializableReferenceLayer)].Add(473, ""StringValues"");");
            Debug.WriteLine(@"model[typeof(SerializableReferenceLayer)].Add(474, ""EnumerationMemberValues"");");
            Debug.WriteLine(@"model[typeof(SerializableReferenceLayer)].Add(475, ""NumericValueValues"");");

            Debug.WriteLine(@"// END OF GENERATED CODE:");
            Debug.WriteLine(@"//");
            Debug.WriteLine(@"//");
        }
Ejemplo n.º 2
0
        public void GivenBadXmlFileWhenGenerateThenModelIsNull()
        {
            var generator = new ProtobufContractGenerator(@"..\..\ProtobufTestFiles\HelloThere.xml");
            var model     = generator.GenerateContractCode("TestUtilities.dll");

            Assert.IsNull(model);
        }
Ejemplo n.º 3
0
        public void GivenBadAssemblyWhenGenerateThenModelIsNull()
        {
            var generator = new ProtobufContractGenerator(_tempXmlFileCorrect);
            var model     = generator.GenerateContractCode("ThisDoesntExist.dll");

            Assert.IsNull(model);
        }
Ejemplo n.º 4
0
        public void WhenExportThenFileIsWritten()
        {
            var generator = new ProtobufContractGenerator(_tempXmlFileCorrect);
            var model     = generator.GenerateContractCode("TestUtilities.dll");

            var filename = Path.Combine(_tempDirectory, "test.proto");

            var testClassA = new TestClassA {
                AString1 = "ABC", AString2 = "XYZ"
            };

            Write(filename, testClassA, model);

            File.Exists(filename);
        }
Ejemplo n.º 5
0
        public void WhenImportWithCorrectContractThenWorks()
        {
            var generator = new ProtobufContractGenerator(_tempXmlFileCorrect);
            var model     = generator.GenerateContractCode("TestUtilities.dll");

            var testClassA = new TestClassA {
                AString1 = "ABC", AString2 = "XYZ", AInt = 3
            };

            string filename = _tempProtoFile;

            var readTestClassA = Read <TestClassA>(filename, model);

            Assert.AreEqual(testClassA.AString1, readTestClassA.AString1);
            Assert.AreEqual(testClassA.AString2, readTestClassA.AString2);
        }
Ejemplo n.º 6
0
        public void WhenExportAndImportTestClassesThenWorks()
        {
            var generator = new ProtobufContractGenerator(_tempXmlFileCorrect);
            var model     = generator.GenerateContractCode("TestUtilities.dll");

            var filename = Path.Combine(_tempDirectory, "test.proto");

            var testClassA = new TestClassA {
                AString1 = "ABC", AString2 = "XYZ"
            };

            Write(filename, testClassA, model);

            var readTestClassA = Read <TestClassA>(filename, model);

            Assert.AreEqual(testClassA.AString1, readTestClassA.AString1);
            Assert.AreEqual(testClassA.AString2, readTestClassA.AString2);
        }