示例#1
0
        public void WebExtensionFullyFledgedValidation()
        {
            this.MyTestInitialize(TestContext.GetCurrentMethod());

            // create an Excel file containing a fully fledged WebExtension here:
            string           filePath = this.GetTestFilePath("WebExtensionFullFledgeValidation.xlsx");
            WebExtensionData gen      = new WebExtensionData();

            gen.CreatePackage(filePath);

            {
                Log.BeginGroup(filePath);

                // make sure the file created is valid
                this.VerifyValidator(filePath);

                // Verify that OOXML SDK can write WebExtension section
                this.VerifyWriteRead <WebExtensionPart>(filePath, (wep) => { WalkWep(wep, StringValueFixer, Int32ValueFixer); },
                                                        (wep) => { WalkWep(wep, StringValueChecker, Int32ValueChecker); });

                // Verify that OOXML SDK can write Taskpanes section
                this.VerifyWriteRead <Wetp.Taskpanes>(filePath, (tps) => { Walker_WebExtentionPane(tps, StringValueFixer, DoubleValueFixer, UInt32ValueFixer, BooleanValueFixer); },
                                                      (tps) => { Walker_WebExtentionPane(tps, StringValueChecker, DoubleValueChecker, UInt32ValueChecker, BooleanValueChecker); });
                Log.EndGroup(filePath);
            }
        }
        public void WebExtensionFullyFledgedValidation()
        {
            var seed = 5;

            DoubleValue DoubleValueFixer(DoubleValue iv) => new DoubleValue(seed / 100D);

            DoubleValue DoubleValueChecker(DoubleValue iv)
            {
                Assert.Equal(DoubleValueFixer(0D).Value, iv.Value);

                return(iv);
            }

            BooleanValue BooleanValueFixer(BooleanValue iv) => 0 == seed % 2;

            BooleanValue BooleanValueChecker(BooleanValue iv)
            {
                Assert.Equal(0 == seed % 2, iv.Value);

                return(iv);
            }

            Int32Value Int32ValueFixer(Int32Value iv)
            {
                int modulo = seed + 13;

                return(iv + (modulo - iv % modulo));
            }

            Int32Value Int32ValueChecker(Int32Value iv)
            {
                Assert.Equal(0, iv % (13 + seed));

                return(iv);
            }

            StringValue StringValueFixer(StringValue sv) => $"{sv}_{seed}";

            StringValue StringValueChecker(StringValue sv)
            {
                Assert.EndsWith($"_{seed}", sv.Value);

                return(sv);
            }

            UInt32Value UInt32ValueFixer(UInt32Value iv) => new UInt32Value((uint)seed);

            UInt32Value UInt32ValueChecker(UInt32Value iv)
            {
                Assert.Equal((uint)seed, iv.Value);

                return(iv);
            }

            using (var stream = new MemoryStream())
            {
                WebExtensionData.CreatePackage(stream);

                // make sure the file created is valid
                VerifyValidator(stream);

                // Verify that OOXML SDK can write WebExtension section
                VerifyWriteRead <WebExtensionPart>(stream,
                                                   wep =>
                {
                    WalkWep(wep, StringValueFixer, Int32ValueFixer);
                },
                                                   wep =>
                {
                    WalkWep(wep, StringValueChecker, Int32ValueChecker);
                });

                // Verify that OOXML SDK can write Taskpanes section
                VerifyWriteRead <Wetp.Taskpanes>(stream,
                                                 tps =>
                {
                    Walker_WebExtentionPane(tps, StringValueFixer, DoubleValueFixer, UInt32ValueFixer, BooleanValueFixer);
                },
                                                 tps =>
                {
                    Walker_WebExtentionPane(tps, StringValueChecker, DoubleValueChecker, UInt32ValueChecker, BooleanValueChecker);
                });
            }
        }