Пример #1
0
        public void Dvd()
        {
            lock (testLock)
            {
                // Copy resource file to the run-time directory
                GetInputFilePath("Actor.xsd", Resources.Actor);

                // Copy resource file to the run-time directory
                string inputFilePath   = GetInputFilePath("Dvd.xsd", Resources.dvd);
                var    generatorParams = GetGeneratorParams(inputFilePath);
                generatorParams.CollectionObjectType = CollectionType.List;
                generatorParams.TargetFramework      = TargetFramework.Net35;
                generatorParams.EnableDataBinding    = true;
                generatorParams.Miscellaneous.EnableSummaryComment = true;
                generatorParams.GenerateDataContracts                   = false;
                generatorParams.GenericBaseClass.Enabled                = false;
                generatorParams.Serialization.GenerateXmlAttributes     = true;
                generatorParams.TrackingChanges.Enabled                 = false;
                generatorParams.TrackingChanges.GenerateTrackingClasses = false;
                generatorParams.Serialization.EnableEncoding            = false;
                generatorParams.Serialization.DefaultEncoder            = DefaultEncoder.UTF8;

                var xsdGen = new GeneratorFacade(generatorParams);
                var result = xsdGen.Generate();

                Assert.IsTrue(result.Success, result.Messages.ToString());

                // Create new dvd collection and save it to file
                var dvd = new DvdCollection();
                dvd.Dvds.Add(new dvd {
                    Title = "Matrix יא?"
                });
                var newitem = new dvd();
                newitem.Actor.Add(new Actor {
                    firstname = "Jamיs א&", nationality = "Us"
                });
                dvd.Dvds.Add(newitem);
                var originalXml = dvd.Serialize();
                var dvdFile     = Path.Combine(OutputFolder, "dvd.xml");
                dvd.SaveToFile(dvdFile);

                // Load data fom file and serialize it again.

                var loadedDvdCollection = DvdCollection.LoadFromFile(dvdFile);
                var finalXml            = loadedDvdCollection.Serialize();

                // Then comprate two xml string
                if (!originalXml.Equals(finalXml))
                {
                    Assert.Fail("Xml value are not equals");
                }
                Exception     exp;
                DvdCollection deserialiseDvd;

                var testEncodings = new [] {
                    Encoding.ASCII, Encoding.UTF8, Encoding.Unicode, Encoding.UTF32
                };
                foreach (var encoding in testEncodings)
                {
                    var encodedFile = Path.Combine(OutputFolder, "dvd" + encoding.EncodingName + ".xml");
                    dvd.SaveToFile(encodedFile, encoding);
                    if (!DvdCollection.LoadFromFile(encodedFile, encoding, out deserialiseDvd, out exp))
                    {
                        Assert.Fail("LoadFromFile failed on {0} encoding", encoding.EncodingName);
                    }
                    else if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix יא?"))
                    {
                        Assert.Fail("LoadFromFile failed on {0} encoding", encoding.EncodingName);
                    }
                }

                var compileResult = CompileCSFile(generatorParams.OutputFilePath);
                Assert.IsTrue(compileResult.Success, compileResult.Messages.ToString());
            }
        }
Пример #2
0
        public void Dvd()
        {
            lock (testLock)
            {
                // Copy resource file to the run-time directory
                GetInputFilePath("Actor.xsd", Resources.Actor);

                // Copy resource file to the run-time directory
                string inputFilePath   = GetInputFilePath("Dvd.xsd", Resources.dvd);
                var    generatorParams = GetGeneratorParams(inputFilePath);
                generatorParams.CollectionObjectType = CollectionType.List;
                generatorParams.TargetFramework      = TargetFramework.Net35;
                generatorParams.EnableDataBinding    = true;
                generatorParams.Miscellaneous.EnableSummaryComment = true;
                generatorParams.GenerateDataContracts                   = false;
                generatorParams.GenericBaseClass.Enabled                = false;
                generatorParams.Serialization.GenerateXmlAttributes     = true;
                generatorParams.TrackingChanges.Enabled                 = false;
                generatorParams.TrackingChanges.GenerateTrackingClasses = false;
                generatorParams.Serialization.EnableEncoding            = false;
                generatorParams.Serialization.DefaultEncoder            = DefaultEncoder.UTF8;
                //generatorParams.PropertyParams.AutomaticProperties = true;

                GenerateAndCompile(generatorParams);

                // Create new dvd collection and save it to file
                var dvd = new DvdCollection();
                dvd.Dvds.Add(new dvd {
                    Title = "Matrix יא?"
                });
                var newitem = new dvd();
                newitem.Actor.Add(new Actor {
                    firstname = "Jamיs א&", nationality = "Us"
                });
                dvd.Dvds.Add(newitem);
                var originalXml        = dvd.Serialize();
                var dataOutputFileName = GetOutputFullFileName("dvd.xml");
                dvd.SaveToFile(dataOutputFileName);

                // Load data fom file and serialize it again.

                var loadedDvdCollection = DvdCollection.LoadFromFile(dataOutputFileName);
                var finalXml            = loadedDvdCollection.Serialize();

                // Then comprate two xml string
                if (!originalXml.Equals(finalXml))
                {
                    Assert.Fail("Xml value are not equals");
                }

                Exception exp;
                foreach (var encoding in encodings)
                {
                    DvdCollection deserialiseDvd;
                    var           dataEncodingOutputFileName = GetOutputFullFileName($"dvd{encoding.EncodingName}.xml");
                    dvd.SaveToFile(dataEncodingOutputFileName, encoding);
                    if (!DvdCollection.LoadFromFile(dataEncodingOutputFileName, encoding, out deserialiseDvd, out exp))
                    {
                        Assert.Fail($"LoadFromFile failed on {encoding.EncodingName} encoding ");
                    }
                    else
                    {
                        string title = /*(encoding == Encoding.ASCII) ? "Matrix ???" : */ "Matrix יא?";
                        if (!deserialiseDvd.Dvds[0].Title.Equals(title))
                        {
                            Assert.Fail($"LoadFromFile failed on {encoding.EncodingName} encoding ");
                        }
                    }
                }
            }
        }