本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}