当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.Reset方法代码示例

本文整理汇总了C#中Transaction.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Reset方法的具体用法?C# Transaction.Reset怎么用?C# Transaction.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.Reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldSkipSerializingCleanInlineFragmentList

        public void ShouldSkipSerializingCleanInlineFragmentList()
        {
            var c = new Transaction()
            {
                Id = 77,
                Currency = "NZD",
                Receipient = "Weta Workshop",
                Taxes = new FragmentList<Tax> {
                    new Tax { Region = "New Zealand", Percentage = 15}
                }
            };

            c.Reset();
            c.Taxes.Reset();
            c.Taxes[0].Reset();

            var encoded = DataTranslator.ResourceEncode<Transaction>("transaction", c);

            dynamic decoded = JsonConvert.DeserializeObject(encoded);

            IEnumerable<JProperty> props = decoded.transaction.Properties();

            Assert.IsFalse(ContainsField(props, "taxes"));

            Assert.AreEqual("77", decoded.transaction.id.ToString());
        }
开发者ID:orospakr,项目名称:sharpify,代码行数:26,代码来源:JsonDataTranslatorTest.cs

示例2: ShouldSerializeOnlyChangedFields

        public void ShouldSerializeOnlyChangedFields()
        {
            var c = new Transaction()
            {
                Id = 88,
                Currency = "BTC",
                Value = 0.10,
                Receipient = "Sanders Aircraft",
                FinancialStatus = "new",
                Taxes = new FragmentList<Tax>{new Tax() { Name = "GST" }},
                SingleTax = new Tax() {Name = "Inline single flat object" },
                Bank = new HasOneDeserializationPlaceholder<Bank>(999),
                OriginatingInstitution = new HasOneDeserializationPlaceholder<Bank>(1000)
            };

            c.Reset();

            // set FinancialStatus, so it should appear in the JSON
            c.FinancialStatus = "completed";

            // set the originating institution, so it should appear in the JSON
            c.OriginatingInstitution = new HasOneDeserializationPlaceholder<Bank>(1001);

            var encoded = DataTranslator.ResourceEncode<Transaction>("transaction", c);

            // use late-binding to concisely test expected fields
            // in the JSON
            dynamic decoded = JsonConvert.DeserializeObject(encoded);

            IEnumerable<JProperty> props = decoded.transaction.Properties();

            // Id should always go through
            Assert.AreEqual("88", decoded.transaction.id.ToString());

            Assert.IsFalse(ContainsField(props, "currency"));
            Assert.IsFalse(ContainsField(props, "value"));
            Assert.IsFalse(ContainsField(props, "receipient"));
            Assert.IsFalse(ContainsField(props, "bank"));
            Assert.IsFalse(ContainsField(props, "bank_id"));

            Assert.IsFalse(ContainsField(props, "originating_institution"));

            Assert.AreEqual("completed", decoded.transaction.financial_status.ToString(), "changed field should turn up in JSON");

            Assert.AreEqual("1001", decoded.transaction.originating_institution_id.ToString(), "changed has_one should turn up in JSON");

            // the single tax object was never reset, so is still dirty.
            Assert.AreEqual("Inline single flat object", decoded.transaction.single_tax.name.ToString());

            // the inline flat list is also dirty, so it'll come through too.
            Assert.AreEqual("GST", decoded.transaction.taxes[0].name.ToString());
        }
开发者ID:orospakr,项目名称:sharpify,代码行数:52,代码来源:JsonDataTranslatorTest.cs

示例3: ShouldSerializeResourceWithAnInlineHasOne

        public void ShouldSerializeResourceWithAnInlineHasOne()
        {
            var c = new Transaction()
            {
                Id = 88,
                Currency = "BTC",
                Value = 0.10,
                Receipient = "Sanders Aircraft"
            };

            c.Reset();

            var bank = new Bank() { Id = 77, Name = "Commonwealth Shared Risk" };
            c.Bank = new HasOneInline<Bank>(bank);

            var encoded = DataTranslator.ResourceEncode<Transaction>("transaction", c);

            // use late-binding to concisely test expected fields
            // in the JSON
            dynamic decoded = JsonConvert.DeserializeObject(encoded);

            IEnumerable<JProperty> props = decoded.transaction.Properties();

            Assert.AreEqual("88", decoded.transaction.id.ToString());

            // as it should be serialized inline, an as-a-id field should not appear.

            Assert.IsFalse(ContainsField(props, "bank_id"));
            Assert.AreEqual("77", decoded.transaction.bank.id.ToString());
            Assert.AreEqual("Commonwealth Shared Risk", decoded.transaction.bank.name.ToString());
        }
开发者ID:orospakr,项目名称:sharpify,代码行数:31,代码来源:JsonDataTranslatorTest.cs

示例4: ShouldSerializeDirtyInlineFragmentListEvenIfModelIsClean

        public void ShouldSerializeDirtyInlineFragmentListEvenIfModelIsClean()
        {
            var c = new Transaction()
            {
                Id = 77,
                Currency = "NZD",
                Receipient = "Weta Workshop",
                Taxes = new FragmentList<Tax> {
                    new Tax { Region = "New Zealand", Percentage = 15}
                }
            };

            c.Reset();

            var encoded = DataTranslator.ResourceEncode<Transaction>("transaction", c);

            dynamic decoded = JsonConvert.DeserializeObject(encoded);
            Assert.AreEqual("77", decoded.transaction.id.ToString());
            Assert.AreEqual(1, decoded.transaction.taxes.Count);
            Assert.AreEqual("New Zealand", decoded.transaction.taxes[0].region.ToString());
        }
开发者ID:orospakr,项目名称:sharpify,代码行数:21,代码来源:JsonDataTranslatorTest.cs


注:本文中的Transaction.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。