|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information.
|
3 | 3 |
|
4 | 4 | using MUXControlsTestApp.Utilities;
|
@@ -980,6 +980,118 @@ public void SelectRangeRegressionTest()
|
980 | 980 | });
|
981 | 981 | }
|
982 | 982 |
|
| 983 | + [TestMethod] |
| 984 | + public void AlreadySelectedDoesNotRaiseEvent() |
| 985 | + { |
| 986 | + var testName = "Select(int32 index), single select"; |
| 987 | + |
| 988 | + RunOnUIThread.Execute(() => |
| 989 | + { |
| 990 | + var list = Enumerable.Range(0, 10).ToList(); |
| 991 | + |
| 992 | + var selectionModel = new SelectionModel() { |
| 993 | + Source = list, |
| 994 | + SingleSelect = true |
| 995 | + }; |
| 996 | + |
| 997 | + // Single select index |
| 998 | + selectionModel.Select(0); |
| 999 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1000 | + selectionModel.Select(0); |
| 1001 | + |
| 1002 | + selectionModel = new SelectionModel() { |
| 1003 | + Source = list, |
| 1004 | + SingleSelect = true |
| 1005 | + }; |
| 1006 | + // Single select indexpath |
| 1007 | + testName = "SelectAt(IndexPath index), single select"; |
| 1008 | + selectionModel.SelectAt(IndexPath.CreateFrom(1)); |
| 1009 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1010 | + selectionModel.SelectAt(IndexPath.CreateFrom(1)); |
| 1011 | + |
| 1012 | + // multi select index |
| 1013 | + selectionModel = new SelectionModel() { |
| 1014 | + Source = list |
| 1015 | + }; |
| 1016 | + selectionModel.Select(1); |
| 1017 | + selectionModel.Select(2); |
| 1018 | + testName = "Select(int32 index), multiselect"; |
| 1019 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1020 | + selectionModel.Select(1); |
| 1021 | + selectionModel.Select(2); |
| 1022 | + |
| 1023 | + selectionModel = new SelectionModel() { |
| 1024 | + Source = list |
| 1025 | + }; |
| 1026 | + |
| 1027 | + // multi select indexpath |
| 1028 | + selectionModel.SelectAt(IndexPath.CreateFrom(1)); |
| 1029 | + selectionModel.SelectAt(IndexPath.CreateFrom(2)); |
| 1030 | + testName = "SelectAt(IndexPath index), multiselect"; |
| 1031 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1032 | + selectionModel.SelectAt(IndexPath.CreateFrom(1)); |
| 1033 | + selectionModel.SelectAt(IndexPath.CreateFrom(2)); |
| 1034 | + }); |
| 1035 | + |
| 1036 | + void ThrowIfRaisedSelectionChanged(SelectionModel sender, SelectionModelSelectionChangedEventArgs args) |
| 1037 | + { |
| 1038 | + throw new Exception("SelectionChangedEvent was raised, but shouldn't have been raised as selection did not change. Tested method: " + testName); |
| 1039 | + } |
| 1040 | + } |
| 1041 | + |
| 1042 | + [TestMethod] |
| 1043 | + public void AlreadyDeselectedDoesNotRaiseEvent() |
| 1044 | + { |
| 1045 | + var testName = "Deselect(int32 index), single select"; |
| 1046 | + |
| 1047 | + RunOnUIThread.Execute(() => |
| 1048 | + { |
| 1049 | + var list = Enumerable.Range(0, 10).ToList(); |
| 1050 | + |
| 1051 | + var selectionModel = new SelectionModel() { |
| 1052 | + Source = list, |
| 1053 | + SingleSelect = true |
| 1054 | + }; |
| 1055 | + |
| 1056 | + // Single select index |
| 1057 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1058 | + selectionModel.Deselect(0); |
| 1059 | + |
| 1060 | + selectionModel = new SelectionModel() { |
| 1061 | + Source = list, |
| 1062 | + SingleSelect = true |
| 1063 | + }; |
| 1064 | + // Single select indexpath |
| 1065 | + testName = "DeselectAt(IndexPath index), single select"; |
| 1066 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1067 | + selectionModel.DeselectAt(IndexPath.CreateFrom(1)); |
| 1068 | + |
| 1069 | + // multi select index |
| 1070 | + selectionModel = new SelectionModel() { |
| 1071 | + Source = list |
| 1072 | + }; |
| 1073 | + testName = "Deselect(int32 index), multiselect"; |
| 1074 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1075 | + selectionModel.Deselect(1); |
| 1076 | + selectionModel.Deselect(2); |
| 1077 | + |
| 1078 | + selectionModel = new SelectionModel() { |
| 1079 | + Source = list |
| 1080 | + }; |
| 1081 | + |
| 1082 | + // multi select indexpath |
| 1083 | + testName = "DeselectAt(IndexPath index), multiselect"; |
| 1084 | + selectionModel.SelectionChanged += ThrowIfRaisedSelectionChanged; |
| 1085 | + selectionModel.DeselectAt(IndexPath.CreateFrom(1)); |
| 1086 | + selectionModel.DeselectAt(IndexPath.CreateFrom(2)); |
| 1087 | + }); |
| 1088 | + |
| 1089 | + void ThrowIfRaisedSelectionChanged(SelectionModel sender, SelectionModelSelectionChangedEventArgs args) |
| 1090 | + { |
| 1091 | + throw new Exception("SelectionChangedEvent was raised, but shouldn't have been raised as selection did not change. Tested method: " + testName); |
| 1092 | + } |
| 1093 | + } |
| 1094 | + |
983 | 1095 | private void Select(SelectionModel manager, int index, bool select)
|
984 | 1096 | {
|
985 | 1097 | Log.Comment((select ? "Selecting " : "DeSelecting ") + index);
|
|
0 commit comments