# Ordering ## Order properties alphabetically Serialized properties can optionally be ordering alphabetically, ie ignoring the order they are defined when using reflection. ```cs public static class ModuleInitializer { [ModuleInitializer] public static void Init() => VerifierSettings.SortPropertiesAlphabetically(); } ``` snippet source | anchor ## Dictionary order Dictionaries are ordering by key. To disable use: ```cs [Fact] public Task DontOrderDictionaries() { var dictionary = new Dictionary { { "Entry_1", "1234" }, { "Entry_3", "1234" }, { "Entry_2", "5678" } }; return Verify(dictionary) .DontSortDictionaries(); } ``` snippet source | anchor ```cs [Fact] public Task DontOrderDictionaries() { var dictionary = new Dictionary { { "Entry_1", "1234" }, { "Entry_3", "1234" }, { "Entry_2", "5678" } }; return Verify(dictionary) .DontSortDictionaries(); } ``` snippet source | anchor ## Json/JObject ordered Json and JObject are not ordered. To enable ordering use: ```cs public static class ModuleInitializer { [ModuleInitializer] public static void Init() => VerifierSettings.SortJsonObjects(); } ``` snippet source | anchor ## Ordering IEnumerable items Items in an instance of an IEnumerable can be ordered. This is helpful when verifying items that can have an inconsistent order, for example reading items from a database. ### OrderEnumerableBy #### Globally ```cs [ModuleInitializer] public static void OrderEnumerableByInitializer() => VerifierSettings.OrderEnumerableBy(_ => _.Value); ``` snippet source | anchor #### Instance ```cs [Fact] public Task EnumerableOrder() { var settings = new VerifySettings(); settings.OrderEnumerableBy(_ => _.Value); return Verify( new List { new("a"), new("c"), new("b") }, settings); } ``` snippet source | anchor #### Fluent ```cs [Fact] public Task EnumerableOrderFluent() => Verify( new List { new("a"), new("c"), new("b") }) .OrderEnumerableBy(_ => _.Value); ``` snippet source | anchor #### Result The resulting file will be: ```txt [ { Value: a }, { Value: b }, { Value: c } ] ``` snippet source | anchor ### OrderEnumerableByDescending #### Globally ```cs [ModuleInitializer] public static void OrderEnumerableByDescendingInitializer() => VerifierSettings.OrderEnumerableByDescending(_ => _.Value); ``` snippet source | anchor #### Instance ```cs [Fact] public Task OrderEnumerableByDescending() { var settings = new VerifySettings(); settings.OrderEnumerableByDescending(_ => _.Value); return Verify( new List { new("a"), new("c"), new("b") }, settings); } ``` snippet source | anchor #### Fluent ```cs [Fact] public Task OrderEnumerableByDescendingFluent() => Verify( new List { new("a"), new("c"), new("b") }) .OrderEnumerableByDescending(_ => _.Value); ``` snippet source | anchor #### Result The resulting file will be: ```txt [ { Value: c }, { Value: b }, { Value: a } ] ``` snippet source | anchor