This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Money? fiver = 5m.Gbp(); | |
| MonetaryQuantity anotherFiver = (MonetaryQuantity)5m.Gbp(); | |
| Assert.That(EqualityComparer<Money?>.Default.Equals(fiver, anotherFiver), Is.True); | |
| Assert.That(Nullable.Equals(fiver, anotherFiver), Is.True); | |
| Assert.That(fiver.Equals(anotherFiver), Is.True); // fail!!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // "proper" | |
| foreach (var item in collection) | |
| { | |
| doSomething(item); | |
| } | |
| // compact | |
| foreach (var item in collection) doSomething(item); | |
| // more compact | |
| collection.ForEach(item => doSomething(item)); | |
| // can't make it shorter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MonetaryQuantity | |
| { | |
| [Obsolete("serialization only")] | |
| private MonetaryQuantity() { } | |
| public MonetaryQuantity(Money money) | |
| { | |
| Currency = money.CurrencyCode.AlphabeticCode(); | |
| Amount = money.Amount; | |
| } | |
| public string Currency { get; private set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assert.That(somePropertJson, Is.EqualTo("{'prop'='value'}").AsJson()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assert.That(someProperJson, Must.Be.Json("{'prop'='value'}")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assert.That(someProperJson, new JsonEqualConstraint("{'prop'='value'}")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string json = "{'str' : 'value', 'number': 42}".Jsonify(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var json = new JsonString("{'str' : 'value', 'number': 42}"); | |
| // use as a string | |
| string nonCompact = json; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var order = new Order | |
| { | |
| // .. | |
| }; | |
| var json = order.ToJson(); | |
| var expected = "{ 'Customer' : 'John', 'OrderDetails' : # }"; | |
| expected = expected.Replace("#", "[{ 'Product' : 'Pen', 'Quantity' : 1 }, { 'Product' : 'Ruler', 'Quantity' : 2 }]"); | |
| expected = expected.Replace("'", "\""); | |
| Assert.AreEqual(expected, json); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assert.That(someProperJson, new JsonEqualConstraint("{'prop'='value'}")); |