├── .gitattributes
├── .gitignore
├── ExtendedObservableCollection
├── ExtendedObservableCollection.sln
├── Gstc.Collections.Observable.Examples
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Customer.cs
│ ├── CustomerViewModel.cs
│ ├── CustomerViewModelList.cs
│ ├── Gstc.Collection.Observable.Examples.csproj
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── NotifyPropertyChanged.cs
│ ├── ObservableDictionaryControl.xaml
│ ├── ObservableDictionaryControl.xaml.cs
│ ├── ObservableListAdapterControl.xaml
│ ├── ObservableListAdapterControl.xaml.cs
│ ├── ObservableListControl.xaml
│ ├── ObservableListControl.xaml.cs
│ ├── ObservableListSyncControl.xaml
│ ├── ObservableListSyncControl.xaml.cs
│ ├── ObservableListTest.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── TestModel.cs
│ └── TestViewModel.cs
├── Gstc.Collections.Observable.Test
│ ├── CollectionTestBase.cs
│ ├── Extended
│ │ ├── ObservableListAdapterTest.cs
│ │ ├── ObservableListKeyedTest.cs
│ │ └── ObservableListKeyedTestInterface.cs
│ ├── Gstc.Collections.Observable.Test.csproj
│ ├── InterfaceTestCases.cs
│ ├── NotifyCollectionIndexTest.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Standard
│ │ ├── ObservableDictionaryTest.cs
│ │ ├── ObservableDictionaryTestInterface.cs
│ │ ├── ObservableListTest.cs
│ │ ├── ObservableListTestInterface.cs
│ │ ├── ObservableSortedListTest.cs
│ │ └── ObservableSortedListTestInterface.cs
│ ├── app.config
│ └── packages.config
└── Gstc.Collections.Observable
│ ├── Base
│ ├── BaseObservableCollection.cs
│ ├── BaseObservableDictionary.cs
│ ├── BaseObservableDictionaryCollection.cs
│ ├── BaseObservableList.cs
│ ├── BaseObservableListDictionary.cs
│ ├── BaseObservableSortedList.cs
│ ├── INotifyListChanged.cs
│ ├── NotifyCollection.cs
│ ├── NotifyDictionary.cs
│ ├── NotifyDictionaryChangedEventArgs.cs
│ ├── NotifyDictionaryChangedEventArgs_Generic.cs
│ ├── NotifyDictionaryCollection.cs
│ └── NotifyProperty.cs
│ ├── Extended
│ ├── INotifyPropertySyncChanged.cs
│ ├── ObservableDictionaryCollection.cs
│ ├── ObservableListAdapter.cs
│ ├── ObservableListAdapterFunc.cs
│ ├── ObservableListKeyed.cs
│ ├── ObservableListKeyedFunc.cs
│ ├── ObservableListSync.cs
│ ├── ObservableListSyncFunc.cs
│ └── PropertySyncNotifier.cs
│ ├── Gstc.Collections.Observable.csproj
│ ├── Gstc.Collections.Observable.nuspec
│ ├── IObservableCollection.cs
│ ├── IObservableDictionary.cs
│ ├── IObservableDictionaryCollection.cs
│ ├── IObservableList.cs
│ ├── Misc
│ ├── CollectionViewAdapter.cs
│ ├── EnumeratorAdapter.cs
│ ├── KeyedList.cs
│ ├── ObservableCollectionSync.cs
│ ├── RefDictionary.cs
│ └── RefObservableCollection.cs
│ ├── ObservableDictionary.cs
│ ├── ObservableList.cs
│ ├── ObservableSortedList.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── packages.config
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | [Nn]uget.exe
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # DNX
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 |
50 | *_i.c
51 | *_p.c
52 | *_i.h
53 | *.ilk
54 | *.meta
55 | *.obj
56 | *.pch
57 | *.pdb
58 | *.pgc
59 | *.pgd
60 | *.rsp
61 | *.sbr
62 | *.tlb
63 | *.tli
64 | *.tlh
65 | *.tmp
66 | *.tmp_proj
67 | *.log
68 | *.vspscc
69 | *.vssscc
70 | .builds
71 | *.pidb
72 | *.svclog
73 | *.scc
74 |
75 | # Chutzpah Test files
76 | _Chutzpah*
77 |
78 | # Visual C++ cache files
79 | ipch/
80 | *.aps
81 | *.ncb
82 | *.opendb
83 | *.opensdf
84 | *.sdf
85 | *.cachefile
86 | *.VC.db
87 | *.VC.VC.opendb
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 | *.sap
94 |
95 | # TFS 2012 Local Workspace
96 | $tf/
97 |
98 | # Guidance Automation Toolkit
99 | *.gpState
100 |
101 | # ReSharper is a .NET coding add-in
102 | _ReSharper*/
103 | *.[Rr]e[Ss]harper
104 | *.DotSettings.user
105 |
106 | # JustCode is a .NET coding add-in
107 | .JustCode
108 |
109 | # TeamCity is a build add-in
110 | _TeamCity*
111 |
112 | # DotCover is a Code Coverage Tool
113 | *.dotCover
114 |
115 | # NCrunch
116 | _NCrunch_*
117 | .*crunch*.local.xml
118 | nCrunchTemp_*
119 |
120 | # MightyMoose
121 | *.mm.*
122 | AutoTest.Net/
123 |
124 | # Web workbench (sass)
125 | .sass-cache/
126 |
127 | # Installshield output folder
128 | [Ee]xpress/
129 |
130 | # DocProject is a documentation generator add-in
131 | DocProject/buildhelp/
132 | DocProject/Help/*.HxT
133 | DocProject/Help/*.HxC
134 | DocProject/Help/*.hhc
135 | DocProject/Help/*.hhk
136 | DocProject/Help/*.hhp
137 | DocProject/Help/Html2
138 | DocProject/Help/html
139 |
140 | # Click-Once directory
141 | publish/
142 |
143 | # Publish Web Output
144 | *.[Pp]ublish.xml
145 | *.azurePubxml
146 | # TODO: Comment the next line if you want to checkin your web deploy settings
147 | # but database connection strings (with potential passwords) will be unencrypted
148 | #*.pubxml
149 | *.publishproj
150 |
151 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
152 | # checkin your Azure Web App publish settings, but sensitive information contained
153 | # in these scripts will be unencrypted
154 | PublishScripts/
155 |
156 | # NuGet Packages
157 | *.nupkg
158 | # The packages folder can be ignored because of Package Restore
159 | **/packages/*
160 | # except build/, which is used as an MSBuild target.
161 | !**/packages/build/
162 | # Uncomment if necessary however generally it will be regenerated when needed
163 | #!**/packages/repositories.config
164 | # NuGet v3's project.json files produces more ignoreable files
165 | *.nuget.props
166 | *.nuget.targets
167 |
168 | # Microsoft Azure Build Output
169 | csx/
170 | *.build.csdef
171 |
172 | # Microsoft Azure Emulator
173 | ecf/
174 | rcf/
175 |
176 | # Windows Store app package directories and files
177 | AppPackages/
178 | BundleArtifacts/
179 | Package.StoreAssociation.xml
180 | _pkginfo.txt
181 |
182 | # Visual Studio cache files
183 | # files ending in .cache can be ignored
184 | *.[Cc]ache
185 | # but keep track of directories ending in .cache
186 | !*.[Cc]ache/
187 |
188 | # Others
189 | ClientBin/
190 | ~$*
191 | *~
192 | *.dbmdl
193 | *.dbproj.schemaview
194 | *.jfm
195 | *.pfx
196 | *.publishsettings
197 | node_modules/
198 | orleans.codegen.cs
199 |
200 | # Since there are multiple workflows, uncomment next line to ignore bower_components
201 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
202 | #bower_components/
203 |
204 | # RIA/Silverlight projects
205 | Generated_Code/
206 |
207 | # Backup & report files from converting an old project file
208 | # to a newer Visual Studio version. Backup files are not needed,
209 | # because we have git ;-)
210 | _UpgradeReport_Files/
211 | Backup*/
212 | UpgradeLog*.XML
213 | UpgradeLog*.htm
214 |
215 | # SQL Server files
216 | *.mdf
217 | *.ldf
218 |
219 | # Business Intelligence projects
220 | *.rdl.data
221 | *.bim.layout
222 | *.bim_*.settings
223 |
224 | # Microsoft Fakes
225 | FakesAssemblies/
226 |
227 | # GhostDoc plugin setting file
228 | *.GhostDoc.xml
229 |
230 | # Node.js Tools for Visual Studio
231 | .ntvs_analysis.dat
232 |
233 | # Visual Studio 6 build log
234 | *.plg
235 |
236 | # Visual Studio 6 workspace options file
237 | *.opt
238 |
239 | # Visual Studio LightSwitch build output
240 | **/*.HTMLClient/GeneratedArtifacts
241 | **/*.DesktopClient/GeneratedArtifacts
242 | **/*.DesktopClient/ModelManifest.xml
243 | **/*.Server/GeneratedArtifacts
244 | **/*.Server/ModelManifest.xml
245 | _Pvt_Extensions
246 |
247 | # Paket dependency manager
248 | .paket/paket.exe
249 | paket-files/
250 |
251 | # FAKE - F# Make
252 | .fake/
253 |
254 | # JetBrains Rider
255 | .idea/
256 | *.sln.iml
257 |
258 | # CodeRush
259 | .cr/
260 |
261 | # Python Tools for Visual Studio (PTVS)
262 | __pycache__/
263 | *.pyc
--------------------------------------------------------------------------------
/ExtendedObservableCollection/ExtendedObservableCollection.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2043
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gstc.Collections.Observable", "Gstc.Collections.Observable\Gstc.Collections.Observable.csproj", "{9B12917B-3860-474A-8A9F-30F89C2CEAE8}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gstc.Collections.Observable.Test", "Gstc.Collections.Observable.Test\Gstc.Collections.Observable.Test.csproj", "{E0F76C87-2255-4102-8350-2F50F6288184}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gstc.Collection.Observable.Examples", "Gstc.Collections.Observable.Examples\Gstc.Collection.Observable.Examples.csproj", "{5B2C012D-751C-4B9C-92BD-CB3DBA421845}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {9B12917B-3860-474A-8A9F-30F89C2CEAE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {9B12917B-3860-474A-8A9F-30F89C2CEAE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {9B12917B-3860-474A-8A9F-30F89C2CEAE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {9B12917B-3860-474A-8A9F-30F89C2CEAE8}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {E0F76C87-2255-4102-8350-2F50F6288184}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {E0F76C87-2255-4102-8350-2F50F6288184}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {E0F76C87-2255-4102-8350-2F50F6288184}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {E0F76C87-2255-4102-8350-2F50F6288184}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {5B2C012D-751C-4B9C-92BD-CB3DBA421845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {5B2C012D-751C-4B9C-92BD-CB3DBA421845}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {5B2C012D-751C-4B9C-92BD-CB3DBA421845}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {5B2C012D-751C-4B9C-92BD-CB3DBA421845}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {47899EAE-767F-481E-B6C7-EAA57A8ED983}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 | ///
5 | /// Interaction logic for App.xaml
6 | ///
7 | public partial class App : Application {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Customer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Gstc.Collection.Observable.Examples {
5 | public class Customer {
6 | public string FirstName { get; set; }
7 | public string LastName { get; set; }
8 | public DateTime BirthDate { get; set; }
9 | public double PurchaseAmount { get; set; }
10 | public string Id { get; set; }
11 |
12 | private static Random RandomGenerator { get; set; } = new Random();
13 |
14 | private static int _idCounter = 0;
15 |
16 | private static string GenerateId() => "id_" + _idCounter++;
17 |
18 | public static Customer GenerateCustomer() {
19 | return new Customer() {
20 | FirstName = _firstNameList[RandomGenerator.Next(10)],
21 | LastName = _lastNameList[RandomGenerator.Next(10)],
22 | BirthDate = DateTime.Now.AddDays(-1 * RandomGenerator.Next(30000) - 3000),
23 | PurchaseAmount = 1 + RandomGenerator.Next(10000) * 0.01,
24 | Id = GenerateId()
25 | };
26 | }
27 |
28 | public static List GenerateCustomerList() {
29 | return new List() {
30 | Customer.GenerateCustomer(),
31 | Customer.GenerateCustomer(),
32 | Customer.GenerateCustomer(),
33 | Customer.GenerateCustomer(),
34 | Customer.GenerateCustomer(),
35 | };
36 | }
37 |
38 | private static List _firstNameList = new List() {
39 | "Emma",
40 | "Sophia",
41 | "Olivia",
42 | "Isabella",
43 | "Ava",
44 | "Mason",
45 | "Noah",
46 | "Lucas",
47 | "Jacob",
48 | "Jack"
49 | };
50 |
51 | private static List _lastNameList = new List() {
52 | "Smith",
53 | "Trujillo",
54 | "Jackson",
55 | "Lee",
56 | "Mercado",
57 | "Sonnenberg",
58 | "Valdez",
59 | "Johnson",
60 | "Parker",
61 | "Warren"
62 | };
63 | }
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/CustomerViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 | public class CustomerViewModel {
5 |
6 | public CustomerViewModel(Customer customer) { Customer = customer; }
7 |
8 | public Customer Customer { get; }
9 |
10 | public string Name => Customer.FirstName + " " + Customer.LastName;
11 | public int Age => (int)((DateTime.Now - Customer.BirthDate).TotalDays / 365);
12 | public string Amount => Customer.PurchaseAmount + " Dollars";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/CustomerViewModelList.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable.Extended;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 | //Implementation of abstract class Observable list Adapter.
5 | public class CustomerViewModelList : ObservableListAdapter {
6 | public override CustomerViewModel Convert(Customer item) => new CustomerViewModel(item);
7 | public override Customer Convert(CustomerViewModel item) => item.Customer;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Gstc.Collection.Observable.Examples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5B2C012D-751C-4B9C-92BD-CB3DBA421845}
8 | WinExe
9 | Gstc.Collection.Observable.Examples
10 | Gstc.Collection.Observable.Examples
11 | v4.8
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 |
60 |
61 |
62 | MSBuild:Compile
63 | Designer
64 |
65 |
66 | App.xaml
67 | Code
68 |
69 |
70 |
71 |
72 |
73 | MainWindow.xaml
74 | Code
75 |
76 |
77 | Designer
78 | MSBuild:Compile
79 |
80 |
81 | Designer
82 | MSBuild:Compile
83 |
84 |
85 | Designer
86 | MSBuild:Compile
87 |
88 |
89 | Designer
90 | MSBuild:Compile
91 |
92 |
93 |
94 |
95 | ObservableDictionaryControl.xaml
96 |
97 |
98 | ObservableListAdapterControl.xaml
99 |
100 |
101 | ObservableListControl.xaml
102 |
103 |
104 | ObservableListSyncControl.xaml
105 |
106 |
107 |
108 | Code
109 |
110 |
111 | True
112 | True
113 | Resources.resx
114 |
115 |
116 | True
117 | Settings.settings
118 | True
119 |
120 |
121 | ResXFileCodeGenerator
122 | Resources.Designer.cs
123 |
124 |
125 | SettingsSingleFileGenerator
126 | Settings.Designer.cs
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | {8e22a176-7ae7-4f41-8fae-edc8a0add7a8}
135 | Gstc.Collections.Observable
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 |
5 | public partial class MainWindow : Window {
6 |
7 | public MainWindow() {
8 | InitializeComponent();
9 |
10 |
11 | }
12 |
13 |
14 |
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/NotifyPropertyChanged.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable.Extended;
2 | using System.ComponentModel;
3 |
4 | namespace Gstc.Collection.Observable.Examples {
5 | public abstract class NotifyPropertySyncChanged : INotifyPropertySyncChanged, INotifyPropertyChanged {
6 |
7 | // Notify Property Changed Fields
8 | public event PropertyChangedEventHandler PropertyChanged;
9 |
10 | //Sync Fields
11 | public void OnPropertyChanged(object sender, PropertyChangedEventArgs args) => PropertyChanged?.Invoke(this, args);
12 |
13 | //Convience Fields
14 | public void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableDictionaryControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableDictionaryControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Controls;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 | ///
5 | /// Interaction logic for ObservableDictionaryControl.xaml
6 | ///
7 | public partial class ObservableDictionaryControl : UserControl {
8 | public ObservableDictionaryControl() {
9 | InitializeComponent();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListAdapterControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListAdapterControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable;
2 | using System.Windows.Controls;
3 |
4 | namespace Gstc.Collection.Observable.Examples {
5 | ///
6 | /// Interaction logic for ObservableListAdapterControl.xaml
7 | ///
8 | public partial class ObservableListAdapterControl : UserControl {
9 |
10 | //List of Customer models
11 | public ObservableList CustomerList {
12 | get => (ObservableList)CustomerViewModelList.SourceCollection;
13 | set => CustomerViewModelList.SourceCollection = value;
14 | }
15 |
16 | //List of Customer View Models: Method one - using implementation of abstract class.
17 | public CustomerViewModelList CustomerViewModelList { get; set; } = new CustomerViewModelList();
18 |
19 | //List of Customer View Models: Method two - using anonymous functions to map Model to ViewModel.
20 | //public ObservableListAdapter CustomerViewModelList { get; set;}
21 | // = new ObservableListAdapterFunc( (customer) => new CustomerViewModel(customer), (customerVm) => customerVm.Customer );
22 |
23 | public ObservableListAdapterControl() {
24 | InitializeComponent();
25 | DataContext = this;
26 | CustomerList = CreateList();
27 | }
28 |
29 | private void Button_Click_Add(object sender, System.Windows.RoutedEventArgs e) {
30 | CustomerList.Add(Customer.GenerateCustomer());
31 | }
32 |
33 | private void Button_Click_Remove(object sender, System.Windows.RoutedEventArgs e) {
34 | if (CustomerList.Count > 0) CustomerList.RemoveAt(0);
35 | }
36 |
37 | private void Button_Click_New(object sender, System.Windows.RoutedEventArgs e) {
38 | CustomerList = CreateList();
39 | }
40 |
41 | private static ObservableList CreateList() => new ObservableList() {
42 | Customer.GenerateCustomer(),
43 | Customer.GenerateCustomer(),
44 | Customer.GenerateCustomer(),
45 | Customer.GenerateCustomer()
46 | };
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable;
2 | using System.Windows.Controls;
3 |
4 | namespace Gstc.Collection.Observable.Examples {
5 | ///
6 | /// Interaction logic for ObservableListControl.xaml
7 | ///
8 | public partial class ObservableListControl : UserControl {
9 |
10 | public ObservableList CustomerObservableList { get; set; } = new ObservableList();
11 |
12 | public ObservableListControl() {
13 | InitializeComponent();
14 | DataContext = this;
15 |
16 | CustomerObservableList.List = Customer.GenerateCustomerList();
17 | CustomerObservableList.CollectionChanged += (sender, args) => {
18 | string message = "\nCollection Changed:";
19 |
20 | if (args.NewItems != null)
21 | foreach (Customer customer in args.NewItems)
22 | message += ("\nCustomer Added: " + customer.FirstName + " " + customer.LastName);
23 |
24 | if (args.OldItems != null)
25 | foreach (Customer customer in args.OldItems)
26 | message += ("\nCustomer Removed: " + customer.FirstName + " " + customer.LastName);
27 |
28 | EventTextBox.Text = message + "\n\n";
29 | };
30 | }
31 |
32 | private void Button_Click_AddRange(object sender, System.Windows.RoutedEventArgs e) {
33 | CustomerObservableList.AddRange(Customer.GenerateCustomerList());
34 | }
35 |
36 | private void Button_Click_Add(object sender, System.Windows.RoutedEventArgs e) {
37 | CustomerObservableList.Add(Customer.GenerateCustomer());
38 | }
39 |
40 | private void Button_Click_Remove(object sender, System.Windows.RoutedEventArgs e) {
41 | if (CustomerObservableList.Count > 0) CustomerObservableList.RemoveAt(0);
42 | }
43 |
44 | private void Button_Click_New(object sender, System.Windows.RoutedEventArgs e) {
45 | CustomerObservableList.List = Customer.GenerateCustomerList();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListSyncControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListSyncControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable;
2 | using Gstc.Collections.Observable.Extended;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 |
6 | namespace Gstc.Collection.Observable.Examples {
7 | ///
8 | /// Interaction logic for ObservableListSyncControl.xaml
9 | ///
10 | public partial class ObservableListSyncControl : UserControl {
11 |
12 | ///
13 | /// The syncronized observable list for viewmodel.
14 | ///
15 | private ObservableListSync ObvListSync =
16 | new ObservableListSyncFunc(
17 | (sourceItem) => new TestViewModel(sourceItem),
18 | (destItem) => destItem.TestModel
19 | );
20 |
21 | ///
22 | /// The source list to insert into the syrnchonized observable list.
23 | ///
24 | public ObservableList SourceObvList {
25 | get => ObvListSync.SourceObservableList;
26 | set {
27 | ObvListSync.SourceObservableList = value;
28 | SourceGrid.ItemsSource = value;
29 | DestGrid.ItemsSource = ObvListSync;
30 | }
31 | }
32 |
33 | public ObservableListSyncControl() {
34 | InitializeComponent();
35 | //Initializes example data
36 | ObservableList obvList = new ObservableList() {
37 | new TestModel {Num1=1, Num2 = 2},
38 | new TestModel {Num1=10, Num2 = 20},
39 | new TestModel {Num1=100, Num2 = 200},
40 | };
41 |
42 | SourceObvList = obvList;
43 | }
44 |
45 | private void Button_Click(object sender, RoutedEventArgs e) {
46 | SourceObvList[0].Num1 += 100;
47 | }
48 |
49 | private void Button_Click_1(object sender, RoutedEventArgs e) {
50 | ObvListSync[0].Num2 += 40;
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/ObservableListTest.cs:
--------------------------------------------------------------------------------
1 | using Gstc.Collections.Observable;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 |
6 | namespace Gstc.Collection.Observable.Examples {
7 | public class ObservableListDemo {
8 | public List CustomerList { get; set; }
9 | public ObservableList CustomerObservableListWrapper { get; set; }
10 | public ObservableList CustomerObservableList { get; set; }
11 |
12 | public ObservableListDemo() {
13 | CustomerList = new List();
14 | CustomerObservableList = new ObservableList();
15 | CustomerObservableListWrapper = new ObservableList();
16 |
17 | CustomerObservableListWrapper.CollectionChanged += (sender, args) => {
18 | Console.WriteLine("Collection Changed");
19 | foreach (Customer customer in args.NewItems)
20 | Console.WriteLine("Customer Added: " + customer.FirstName + " " + customer.LastName);
21 | };
22 |
23 | CustomerObservableList.CollectionChanged += (sender, args) => {
24 | Console.WriteLine("Collection Changed");
25 | foreach (Customer customer in args.NewItems)
26 | Console.WriteLine("Customer Added: " + customer.FirstName + " " + customer.LastName);
27 | };
28 |
29 | //Populates initial standard list.
30 | CustomerList.Add(Customer.GenerateCustomer());
31 | CustomerList.Add(Customer.GenerateCustomer());
32 | CustomerList.Add(Customer.GenerateCustomer());
33 | CustomerList.Add(Customer.GenerateCustomer());
34 |
35 | //Inserts standard list into the wrapper as its backing list.
36 | CustomerObservableListWrapper.List = CustomerList;
37 |
38 | //Adds customers directly to second observable list.
39 | CustomerObservableList.Add(Customer.GenerateCustomer());
40 | CustomerObservableList.Add(Customer.GenerateCustomer());
41 | CustomerObservableList.Add(Customer.GenerateCustomer());
42 |
43 | //Adds list of customers from initial list into second observable list.
44 | CustomerObservableList.AddRange(CustomerList);
45 |
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Windows;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Gstc.Collection.Observable.Examples")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Gstc.Collection.Observable.Examples")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | //In order to begin building localizable applications, set
23 | //CultureYouAreCodingWith in your .csproj file
24 | //inside a . For example, if you are using US english
25 | //in your source files, set the to en-US. Then uncomment
26 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
27 | //the line below to match the UICulture setting in the project file.
28 |
29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
30 |
31 |
32 | [assembly: ThemeInfo(
33 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
34 | //(used if a resource is not found in the page,
35 | // or application resource dictionaries)
36 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
37 | //(used if a resource is not found in the page,
38 | // app, or any theme specific resource dictionaries)
39 | )]
40 |
41 |
42 | // Version information for an assembly consists of the following four values:
43 | //
44 | // Major Version
45 | // Minor Version
46 | // Build Number
47 | // Revision
48 | //
49 | // You can specify all the values or you can default the Build and Revision Numbers
50 | // by using the '*' as shown below:
51 | // [assembly: AssemblyVersion("1.0.*")]
52 | [assembly: AssemblyVersion("1.0.0.0")]
53 | [assembly: AssemblyFileVersion("1.0.0.0")]
54 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Gstc.Collection.Observable.Examples.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Gstc.Collection.Observable.Examples.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Gstc.Collection.Observable.Examples.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/TestModel.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace Gstc.Collection.Observable.Examples {
4 | public class TestModel : INotifyPropertyChanged {
5 |
6 | private int num1 = 5;
7 | private int num2 = 10;
8 |
9 | public event PropertyChangedEventHandler PropertyChanged;
10 | public void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
11 |
12 | public int Num1 { get => num1; set { num1 = value; OnPropertyChanged(null); } }
13 | public int Num2 { get => num2; set { num2 = value; OnPropertyChanged(null); } }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Examples/TestViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace Gstc.Collection.Observable.Examples {
2 | public class TestViewModel : NotifyPropertySyncChanged {
3 | public TestModel TestModel;
4 |
5 | public TestViewModel() => TestModel = new TestModel();
6 |
7 | public TestViewModel(TestModel testModel) => TestModel = testModel;
8 |
9 | public string Num1 {
10 | get => TestModel.Num1.ToString();
11 | set {
12 | int num = 0;
13 | var isParsed = int.TryParse(value, out num);
14 | if (!isParsed) return;
15 | TestModel.Num1 = num;
16 | OnPropertyChanged(null);
17 | }
18 | }
19 |
20 | public int Num2 {
21 | get => TestModel.Num2 + 5;
22 | set {
23 | TestModel.Num2 = value - 5;
24 | OnPropertyChanged(null);
25 | }
26 | }
27 | }
28 |
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Test/CollectionTestBase.cs:
--------------------------------------------------------------------------------
1 | using AutoFixture;
2 | using Gstc.Collections.Observable.Base;
3 | using Moq;
4 | using NUnit.Framework;
5 | using System;
6 | using System.Collections.Specialized;
7 | using System.ComponentModel;
8 |
9 | namespace Gstc.Collections.Observable.Test {
10 | public class CollectionTestBase {
11 |
12 | #region Default Test Tools
13 | protected static Fixture Fixture { get; } = new Fixture();
14 | protected MockEventClass MockEvent { get; set; }
15 | protected AssertEventClass AssertEvent { get; set; }
16 | #endregion
17 |
18 | #region Default test items
19 |
20 | protected TItem DefaultTestItem { get; set; }
21 | protected TItem UpdateTestItem { get; set; }
22 |
23 | protected TItem Item1 { get; set; }
24 | protected TItem Item2 { get; set; }
25 | protected TItem Item3 { get; set; }
26 |
27 |
28 | protected TKey Key1 { get; set; }
29 | protected TKey Key2 { get; set; }
30 | protected TKey Key3 { get; set; }
31 |
32 | protected TKey DefaultKey { get; set; }
33 | protected TKey UpdateKey { get; set; }
34 | protected TItem DefaultValue { get; set; }
35 | protected TItem UpdateValue { get; set; }
36 |
37 |
38 |
39 | #endregion
40 |
41 | public void TestInit() {
42 | MockEvent = new MockEventClass();
43 | AssertEvent = MockEvent.Object;
44 |
45 | //Generalize mock data
46 | DefaultTestItem = Fixture.Create();
47 | UpdateTestItem = Fixture.Create();
48 |
49 | Item1 = Fixture.Create();
50 | Item2 = Fixture.Create();
51 | Item3 = Fixture.Create();
52 |
53 | Key1 = Fixture.Create();
54 | Key2 = Fixture.Create();
55 | Key3 = Fixture.Create();
56 |
57 | DefaultKey = Fixture.Create();
58 | UpdateKey = Fixture.Create();
59 | DefaultValue = Fixture.Create();
60 | UpdateValue = Fixture.Create();
61 | }
62 |
63 | #region Collection Event Args Tests
64 | protected void AssertCollectionEventReset(object sender, NotifyCollectionChangedEventArgs args) {
65 | Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Reset));
66 | Assert.That(args.OldItems, Is.Null);
67 | Assert.That(args.NewItems, Is.Null);
68 | Assert.That(args.OldStartingIndex == -1);
69 | Assert.That(args.NewStartingIndex == -1);
70 | }
71 |
72 | protected NotifyCollectionChangedEventHandler GenerateAssertCollectionEventAddOne(int index, TItem item) {
73 | return (sender, args) => {
74 | Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
75 | Assert.That(args.OldStartingIndex == -1);
76 | Assert.That(args.NewStartingIndex == index);
77 | Assert.That(args.OldItems, Is.Null);
78 | Assert.That(args.NewItems[0], Is.EqualTo(item));
79 | };
80 | }
81 |
82 | protected NotifyCollectionChangedEventHandler GenerateAssertCollectionEventAddThree(int index, TItem item1, TItem item2, TItem item3) {
83 | return (sender, args) => {
84 | Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
85 | Assert.That(args.OldStartingIndex, Is.EqualTo(-1));
86 | Assert.That(args.NewStartingIndex, Is.EqualTo(index));
87 | Assert.That(args.OldItems, Is.Null);
88 | Assert.That(args.NewItems[0], Is.EqualTo(item1));
89 | Assert.That(args.NewItems[1], Is.EqualTo(item2));
90 | Assert.That(args.NewItems[2], Is.EqualTo(item3));
91 | };
92 | }
93 |
94 | protected NotifyCollectionChangedEventHandler GenerateAssertCollectionEventRemoveOne(int index, TItem item) {
95 | return (sender, args) => {
96 | Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Remove));
97 | Assert.That(args.OldStartingIndex == index);
98 | Assert.That(args.NewStartingIndex == -1);
99 | Assert.That(args.OldItems[0], Is.EqualTo(item));
100 | Assert.That(args.NewItems, Is.Null);
101 | };
102 | }
103 | #endregion
104 |
105 | #region Dictionary Event Arg Tests
106 | protected void AssertDictionaryEventReset(object sender, NotifyDictionaryChangedEventArgs args) {
107 | Assert.That(args.Action, Is.EqualTo(NotifyDictionaryChangedAction.Reset));
108 | Assert.That(args.OldItems, Is.Null);
109 | Assert.That(args.NewItems, Is.Null);
110 | Assert.That(args.OldKeys, Is.Null);
111 | Assert.That(args.NewKeys, Is.Null);
112 | }
113 |
114 | protected NotifyDictionaryChangedEventHandler GenerateAssertDictionaryEventAddOne(TKey key, TItem item) {
115 | return (sender, args) => {
116 | Assert.That(args.Action, Is.EqualTo(NotifyDictionaryChangedAction.Add));
117 | Assert.That(args.OldItems, Is.Null);
118 | Assert.That(args.OldKeys, Is.Null);
119 | Assert.That(args.NewKeys[0], Is.EqualTo(key));
120 | Assert.That(args.NewItems[0], Is.EqualTo(item));
121 | };
122 | }
123 |
124 | protected NotifyDictionaryChangedEventHandler GenerateAssertDictionaryEventRemoveOne(TKey key, TItem item) {
125 | return (sender, args) => {
126 | Assert.That(args.Action, Is.EqualTo(NotifyDictionaryChangedAction.Remove));
127 | Assert.That(args.NewKeys, Is.Null);
128 | Assert.That(args.NewItems, Is.Null);
129 | Assert.That(args.OldKeys[0], Is.EqualTo(key));
130 | Assert.That(args.OldItems[0], Is.EqualTo(item));
131 | };
132 | }
133 | #endregion
134 |
135 | protected void Log(object message) => Console.WriteLine(message);
136 |
137 | #region Event Call Test
138 |
139 |
140 | ///
141 | /// Class for testing mock events for observable collections. Uses Moq framework to verify event are called.
142 | ///
143 | public class MockEventClass : Mock {
144 |
145 | private int _timesPropertyCalled = 0;
146 | private int _timesCollectionCalled = 0;
147 | private int _timesDictionaryCalled = 0;
148 |
149 | public void AddNotifiersCollectionAndProperty(IObservableCollection obvList) {
150 | //Sets up event testers
151 | obvList.PropertyChanged += OnPropertyChanged;
152 | obvList.CollectionChanged += OnCollectionChanged;
153 | }
154 |
155 | public void AddNotifiersDictionary(INotifyDictionaryChanged obvDict) {
156 | //Sets up event testers
157 | obvDict.DictionaryChanged += OnDictionaryChanged;
158 |
159 | }
160 |
161 | public void AssertMockNotifiersCollection(int timesPropertyCalled, int timesCollectionCalled) {
162 | _timesPropertyCalled += timesPropertyCalled;
163 | _timesCollectionCalled += timesCollectionCalled;
164 | Verify(m => m.Call("PropertyChanged"), Times.Exactly(_timesPropertyCalled));
165 | Verify(m => m.Call("CollectionChanged"), Times.Exactly(_timesCollectionCalled));
166 | }
167 |
168 | public void AssertMockNotifiersDictionary(int timesDictionaryCalled) {
169 | _timesDictionaryCalled += timesDictionaryCalled;
170 | Verify(m => m.Call("DictionaryChanged"), Times.Exactly(_timesDictionaryCalled));
171 | }
172 |
173 | public void RemoveCollectionAndPropertyNotifiers(IObservableCollection obvList) {
174 | obvList.PropertyChanged -= OnPropertyChanged;
175 | obvList.CollectionChanged -= OnCollectionChanged;
176 | }
177 |
178 | public void RemoveDictionaryNotifiers(IObservableDictionary obvDict) {
179 | obvDict.DictionaryChanged -= OnDictionaryChanged;
180 | }
181 |
182 | private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
183 | => Object.Call("CollectionChanged");
184 |
185 | private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
186 | => Object.Call("PropertyChanged");
187 |
188 | private void OnDictionaryChanged(object sender, NotifyDictionaryChangedEventArgs e)
189 | => Object.Call("DictionaryChanged");
190 | }
191 |
192 | ///
193 | /// Simple class for testing events using Moq. Moq proxies the Call method and counts number of times called.
194 | ///
195 | public class AssertEventClass {
196 | public virtual void Call(string obj) { }
197 | }
198 |
199 | #endregion
200 |
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/ExtendedObservableCollection/Gstc.Collections.Observable.Test/Extended/ObservableListAdapterTest.cs:
--------------------------------------------------------------------------------
1 | using AutoFixture;
2 | using Gstc.Collections.Observable.Base;
3 | using Gstc.Collections.Observable.Extended;
4 | using Moq;
5 | using NUnit.Framework;
6 | using System.Linq;
7 |
8 | namespace Gstc.Collections.Observable.Test.Extended {
9 |
10 | [TestFixture]
11 | public class ObservableListAdapterTest : CollectionTestBase