本文整理汇总了C#中Money.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Money.Equals方法的具体用法?C# Money.Equals怎么用?C# Money.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Money
的用法示例。
在下文中一共展示了Money.Equals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeEquatableWithNull
public void ShouldBeEquatableWithNull()
{
var money = new Money(42, "AUD");
var actual = money.Equals(null);
actual.ShouldBe(false);
}
示例2: op_Equals_objectDiffers
public void op_Equals_objectDiffers()
{
var euro = new Currency("€", 2);
var obj = new Money(euro, 1.23m);
var comparand = new Money(euro, 4.56m);
Assert.False(obj.Equals(comparand));
}
示例3: op_Equals_object
public void op_Equals_object()
{
var euro = new Currency("€", 2);
var obj = new Money(euro, 1.23m);
var comparand = new Money(euro, 1.23m);
Assert.True(obj.Equals(comparand));
}
示例4: MoneyWithSameCurrency_ShouldBeEquatable
public void MoneyWithSameCurrency_ShouldBeEquatable(
decimal amount1,
decimal amount2,
bool expected)
{
const string currency = "AUD";
var money1 = new Money(amount1, currency);
var money2 = new Money(amount2, currency);
var actual = money1.Equals(money2);
actual.ShouldBe(expected);
}
示例5: EqualsTest
public void EqualsTest()
{
Currency currency = new Currency("USD", "USD");
Money target = new Money(100, currency);
Money other = null;
bool actual;
actual = target.Equals(other);
Assert.AreEqual<bool>(false, actual);
target = new Money(100, currency);
other = new Money(100, currency);
actual = target.Equals(other);
Assert.AreEqual<bool>(true, actual);
target = new Money(100, currency);
other = new Money(0, currency);
actual = target.Equals(other);
Assert.AreEqual<bool>(false, actual);
target = new Money(100, currency);
other = new Money(100, new Currency("GBP", "GBP"));
try
{
actual = target.Equals(other);
Assert.Fail("Expected InvalidOperationException");
}
catch (InvalidOperationException) { }
}
示例6: WhenEquatingTwoDifferentCurrencies_ShouldReturnFalse
public void WhenEquatingTwoDifferentCurrencies_ShouldReturnFalse(
decimal amount1,
string currency1,
decimal amount2,
string currency2,
bool expected)
{
var money1 = new Money(amount1, currency1);
var money2 = new Money(amount2, currency2);
var actual = money1.Equals(money2);
actual.ShouldBe(expected);
}
示例7: Money_With_Another_Value_Should_Not_Be_Equal
public void Money_With_Another_Value_Should_Not_Be_Equal()
{
var money1 = new Money(50);
var money2 = new Money(50.01M);
var money3 = new Money(-50);
Assert.NotEqual(money1, money2);
Assert.NotEqual(money1, money3);
Assert.False(money1 == money2);
Assert.True(money1 != money2);
Assert.False(money1.Equals(money2));
}
示例8: Money_With_The_Same_Value_Should_Be_Equal
public void Money_With_The_Same_Value_Should_Be_Equal()
{
var money1 = new Money(50);
var money2 = new Money(50);
Assert.Equal(money1, money2);
Assert.True(money1 == money2);
Assert.False(money1 != money2);
Assert.True(money1.Equals(money2));
}
示例9: EqualsMoney
public void EqualsMoney()
{
Money money1 = new Money((decimal)10.05, CurrencyFixture.NewZealandDollar);
Money money2 = new Money((decimal)10.05, CurrencyFixture.NewZealandDollar);
Money money3 = new Money((decimal)10.05, CurrencyFixture.NewZealandDollar);
Assert.IsTrue(money1.Equals(money1));
Assert.IsTrue(money1.Equals(money2));
Assert.IsTrue(money2.Equals(money1));
Assert.IsTrue(money1.Equals(money2) && money2.Equals(money3));
Assert.IsFalse(money1.Equals(null));
}
示例10: EqualsMethodReturnsFalseWhenMoneyHasDifferentCurrencies
public void EqualsMethodReturnsFalseWhenMoneyHasDifferentCurrencies()
{
Money aud = new Money(12.5m, CurrencyFixture.AustralianDollar);
Money nzd = new Money(12.5m, CurrencyFixture.NewZealandDollar);
aud.Equals(nzd).Should().Be(false);
}