Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CompositionContainerCollectionTests.cs « Composition « ComponentModel « System « ComponentModelUnitTest « Tests « System.ComponentModel.Composition « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f4b0233ede92d4bed0d51f437db3a077419ec72 (plain)
1
2
3
4
5
6
7
8
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition.Factories;
using System.UnitTesting;
using System.ComponentModel.Composition.UnitTesting;
using System.ComponentModel.Composition.Hosting;

namespace System.ComponentModel.Composition
{
    [TestClass]
    public class CompositionContainerCollectionTests
    {
        public class SupportedImportCollectionAssignments<T>
        {
            // Fields
            [ImportMany("Value")]
            public IEnumerable<T> IEnumerableOfTField;

            [ImportMany("Value")]
            public IEnumerable<object> IEnumerableOfObjectField;

            [ImportMany("Value")]
            public T[] ArrayOfTField;

            [ImportMany("Value")]
            public object[] ArrayOfObjectField;

            [ImportMany("Value")]
            public IEnumerable<T> IEnumerableOfTProperty { get; set; }

            [ImportMany("Value")]
            public IEnumerable<object> IEnumerableOfObjectProperty { get; set; }

            [ImportMany("Value")]
            public T[] ArrayOfTProperty { get; set; }

            [ImportMany("Value")]
            public object[] ArrayOfObjectProperty { get; set; }
            
            public void VerifyImports(params T[] expectedValues)
            {
                // Fields
                EnumerableAssert.AreEqual(IEnumerableOfTField, expectedValues);
                EnumerableAssert.AreEqual(IEnumerableOfObjectField, expectedValues.Cast<object>());
                EnumerableAssert.AreEqual(ArrayOfTField, expectedValues);
                EnumerableAssert.AreEqual(ArrayOfObjectField, expectedValues.Cast<object>());

                // Properties
                EnumerableAssert.AreEqual(IEnumerableOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(IEnumerableOfObjectProperty, expectedValues.Cast<object>());
                EnumerableAssert.AreEqual(ArrayOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ArrayOfObjectProperty, expectedValues.Cast<object>());
            }
        }

        [TestMethod]
        public void ValidateSupportedImportCollectionAssignments()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();

            var importer = new SupportedImportCollectionAssignments<int>();

            batch.AddPart(importer);
            batch.AddExportedValue("Value", 21);
            batch.AddExportedValue("Value", 32);
            batch.AddExportedValue("Value", 43);

            container.Compose(batch);

            importer.VerifyImports(21, 32, 43);
        }

        public class SupportedImportCollectionMutation<T>
        {
            public SupportedImportCollectionMutation()
            {
                ICollectionOfTReadOnlyField = new List<T>();
                ListOfTReadOnlyField = new List<T>();
                CollectionOfTField = new Collection<T>();
                CollectionOfTReadOnlyField = new Collection<T>();

                _iCollectionOfTReadOnlyProperty = new List<T>();
                _listOfTReadOnlyProperty = new List<T>();
                CollectionOfTProperty = new Collection<T>();
                _collectionOfTReadOnlyProperty = new Collection<T>();

#if !SILVERLIGHT
                ObservableCollectionOfTReadOnlyField = new ObservableCollection<T>();
                _observableCollectionOfTReadOnlyProperty = new ObservableCollection<T>();
#endif // !SILVERLIGHT
            }

            [ImportMany("Value")]
            public readonly ICollection<T> ICollectionOfTReadOnlyField;

            [ImportMany("Value")]
            public List<T> ListOfTField;

            [ImportMany("Value")]
            public readonly List<T> ListOfTReadOnlyField;

            [ImportMany("Value")]
            public Collection<T> CollectionOfTField;
            
            [ImportMany("Value")]
            public Collection<object> CollectionOfObjectField;

            [ImportMany("Value")]
            public readonly Collection<T> CollectionOfTReadOnlyField;

            [ImportMany("Value")]
            public ICollection<T> ICollectionOfTReadOnlyProperty { get { return _iCollectionOfTReadOnlyProperty; } }
            private ICollection<T> _iCollectionOfTReadOnlyProperty;

            [ImportMany("Value")]
            public List<T> ListOfTProperty { get; set; }

            [ImportMany("Value")]
            public List<T> ListOfTReadOnlyProperty { get { return _listOfTReadOnlyProperty; } }
            private readonly List<T> _listOfTReadOnlyProperty;

            [ImportMany("Value")]
            public Collection<T> CollectionOfTProperty { get; set; }

            [ImportMany("Value")]
            public Collection<T> CollectionOfTReadOnlyProperty { get { return _collectionOfTReadOnlyProperty; } }
            private readonly Collection<T> _collectionOfTReadOnlyProperty;

#if !SILVERLIGHT
            [ImportMany("Value")]
            public ObservableCollection<T> ObservableCollectionOfTField;

            [ImportMany("Value")]
            public readonly ObservableCollection<T> ObservableCollectionOfTReadOnlyField;

            [ImportMany("Value")]
            public ObservableCollection<T> ObservableCollectionOfTProperty { get; set; }

            [ImportMany("Value")]
            public ObservableCollection<T> ObservableCollectionOfTReadOnlyProperty { get { return _observableCollectionOfTReadOnlyProperty; } }
            private readonly ObservableCollection<T> _observableCollectionOfTReadOnlyProperty;
#endif // !SILVERLIGHT

            public void VerifyImports(params T[] expectedValues)
            {
                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTField, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyField, expectedValues);

                EnumerableAssert.AreEqual(ICollectionOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ListOfTReadOnlyProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(CollectionOfTReadOnlyProperty, expectedValues);
                
#if !SILVERLIGHT
                EnumerableAssert.AreEqual(ObservableCollectionOfTField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyField, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTProperty, expectedValues);
                EnumerableAssert.AreEqual(ObservableCollectionOfTReadOnlyProperty, expectedValues);
#endif // !SILVERLIGHT
            }
        }

        [TestMethod]
        public void ValidateSupportedImportCollectionMutation()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();

            var importer = new SupportedImportCollectionMutation<int>();

            batch.AddPart(importer);
            batch.AddExportedValue("Value", 21);
            batch.AddExportedValue("Value", 32);
            batch.AddExportedValue("Value", 43);

            container.Compose(batch);

            importer.VerifyImports(21, 32, 43);
        }

        public class ImportCollectionNullValue
        {
            [ImportMany("Value")]
            public List<int> NullValue { get; set; }
        }

        public class NamelessImporter
        {
            [ImportMany]
            public int[] ReadWriteIList { get; set; }

            [ImportMany]
            public Collection<Lazy<int>> ReadWriteMetadata { get; set; }
        }

        public class NamelessExporter
        {
            public NamelessExporter(int value)
            {
                Value = value;
            }

            [Export]
            public int Value { get; set; }
        }

        [TestMethod]
        public void ImportCollectionsNameless()
        {
            // Verifing that the contract name gets the correct value
            var container = ContainerFactory.Create();
            NamelessImporter importer = new NamelessImporter();
            NamelessExporter exporter42 = new NamelessExporter(42);
            NamelessExporter exporter0 = new NamelessExporter(0);

            CompositionBatch batch = new CompositionBatch();
            batch.AddParts(importer, exporter42, exporter0);
            container.Compose(batch);

            EnumerableAssert.AreEqual(importer.ReadWriteIList, 42, 0);
        }

        public class InvalidImporterReadOnlyEnumerable
        {
            IEnumerable<int> readOnlyEnumerable = new List<int>();

            [ImportMany("Value")]
            public IEnumerable<int> ReadOnlyEnumerable
            {
                get
                {
                    return readOnlyEnumerable;
                }
            }
        }

        [TestMethod]
        public void ImportCollectionsExceptionReadOnlyEnumerable()
        {
            ExpectedErrorOnPartActivate(new InvalidImporterReadOnlyEnumerable(),
                ErrorId.ReflectionModel_ImportCollectionNotWritable);  
        }

        public class ImporterWriteOnlyExportCollection
        {
            [ImportMany("Value")]
            public Collection<Lazy<int>> WriteOnlyExportCollection
            {
                set { PublicExportCollection = value; }
            }

            public Collection<Lazy<int>> PublicExportCollection { get; set; }
        }

        [TestMethod]
        public void ImportCollections_WriteOnlyExportCollection()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();

            var importer = new ImporterWriteOnlyExportCollection();

            List<int> values = new List<int>() { 21, 32, 43 };

            batch.AddPart(importer);
            values.ForEach(v => batch.AddExportedValue("Value", v));

            container.Compose(batch);

            EnumerableAssert.AreEqual(values, importer.PublicExportCollection.Select(export => export.Value));            
        }

        public class ImporterWriteOnlyIEnumerableOfT
        {
            [ImportMany("Value")]
            public IEnumerable<int> WriteOnlyIEnumerable
            {
                set { PublicIEnumerable = value; }
            }

            public IEnumerable<int> PublicIEnumerable { get; set; }
        }

        [TestMethod]
        public void ImportCollections_WriteOnlyIEnumerableOfT()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();

            var importer = new ImporterWriteOnlyIEnumerableOfT();

            List<int> values = new List<int>() { 21, 32, 43 };

            batch.AddPart(importer);
            values.ForEach(v => batch.AddExportedValue("Value", v));

            container.Compose(batch);

            EnumerableAssert.AreEqual(values, importer.PublicIEnumerable);
        }

        public class ImporterWriteOnlyArray
        {
            [ImportMany("Value")]
            public int[] WriteOnlyArray
            {
                set { PublicArray = value; }
            }

            public int[] PublicArray { get; set; }
        }

        [TestMethod]
        public void ImportCollections_WriteOnlyArray()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();

            var importer = new ImporterWriteOnlyArray();

            List<int> values = new List<int>() { 21, 32, 43 };

            batch.AddPart(importer);
            values.ForEach(v => batch.AddExportedValue("Value", v));

            container.Compose(batch);

            EnumerableAssert.AreEqual(values, importer.PublicArray);
        }

        public class InvalidImporterNonCollection
        {
            [Import("Value")]
            public int Value { get; set; }
        }

        [TestMethod]
        public void ImportCollectionsExceptionNonCollection()
        {
            ExpectedChangeRejectedErrorOnSetImport(new InvalidImporterNonCollection(),
                ErrorId.ImportEngine_ImportCardinalityMismatch);
        }

        public class InvalidImporterNonAssignableCollection
        {
            [ImportMany("Value", typeof(int))]
            public IEnumerable<string> StringCollection { get; set; }
        }

        [TestMethod]
        public void ImportCollectionsExceptionNonAssignableCollection()
        {
            ExpectedErrorOnSetImport(new InvalidImporterNonAssignableCollection(),
                ErrorId.ReflectionModel_ImportNotAssignableFromExport);  
        }

        public class InvalidImporterNullReadOnlyICollection
        {
            ICollection<int> readOnlyICollection = null;

            [ImportMany("Value")]
            public ICollection<int> Values { get { return readOnlyICollection; } }
        }

        [TestMethod]
        public void ImportCollectionsExceptionNullReadOnlyICollection()
        {
            ExpectedErrorOnPartActivate(new InvalidImporterNullReadOnlyICollection(),
                ErrorId.ReflectionModel_ImportCollectionNull);   
        }

        public class ImporterWeakIEnumerable
        {
            public ImporterWeakIEnumerable()
            {
                ReadWriteEnumerable = new IntCollection();
            }

            [ImportMany("Value")]
            public IntCollection ReadWriteEnumerable { get; set; }

            public class IntCollection : IEnumerable
            {
                List<int> ints = new List<int>();
                public void Add(int item) { ints.Add(item); }
                public void Clear() { ints.Clear(); }
                public bool Remove(int item) { return ints.Remove(item); }
                public IEnumerator GetEnumerator() { return ints.GetEnumerator(); }
            }
        }

        [TestMethod]
        public void ImportCollectionsExceptionWeakCollectionNotSupportingICollectionOfT()
        {
            ExpectedErrorOnPartActivate(new ImporterWeakIEnumerable(),
                ErrorId.ReflectionModel_ImportCollectionNotWritable);
        }

        public class ImporterThrowsOnGetting
        {
            [ImportMany("Value")]
            public List<int> Value
            {
                get
                {
                    throw new NotSupportedException();
                }
            }
        }

        [TestMethod]
        public void ImportCollectionsExceptionGettingValue()
        {
            var container = ContainerFactory.Create();
            ImporterThrowsOnGetting importer = new ImporterThrowsOnGetting();
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(importer);
            batch.AddExportedValue("Value", 42);
            batch.AddExportedValue("Value", 0);

            CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotActivate,
                                          ErrorId.ReflectionModel_ImportCollectionGetThrewException, RetryMode.DoNotRetry, () =>
                                          {
                                              container.Compose(batch);
                                          });
        }

        public class CustomCollectionThrowsDuringConstruction : Collection<int>
        {
            public CustomCollectionThrowsDuringConstruction()
            {
                throw new NotSupportedException();
            }
        }

        public class ImportCustomCollectionThrowsDuringConstruction
        {
            public ImportCustomCollectionThrowsDuringConstruction()
            {
            }

            [ImportMany("Value")]
            public CustomCollectionThrowsDuringConstruction Values { get; set; }
        }

        [TestMethod]
        public void ImportCollections_ImportTypeThrowsOnConstruction()
        {
            ExpectedErrorOnPartActivate(new ImportCustomCollectionThrowsDuringConstruction(),
                ErrorId.ReflectionModel_ImportCollectionConstructionThrewException);
        }

        public class CustomCollectionThrowsDuringClear : Collection<int>
        {
            protected override void ClearItems()
            {
                throw new NotSupportedException();
            }
        }

        public class ImportCustomCollectionThrowsDuringClear
        {
            public ImportCustomCollectionThrowsDuringClear()
            {
            }

            [ImportMany("Value")]
            public CustomCollectionThrowsDuringClear Values { get; set; }
        }

        [TestMethod]
        public void ImportCollections_ImportTypeThrowsOnClear()
        {
            ExpectedErrorOnPartActivate(new ImportCustomCollectionThrowsDuringClear(),
                ErrorId.ReflectionModel_ImportCollectionClearThrewException);
        }

        public class CustomCollectionThrowsDuringAdd : Collection<int>
        {
            protected override void InsertItem(int index, int item)
            {
                throw new NotSupportedException();
            }
        }

        public class ImportCustomCollectionThrowsDuringAdd
        {
            public ImportCustomCollectionThrowsDuringAdd()
            {
            }

            [ImportMany("Value")]
            public CustomCollectionThrowsDuringAdd Values { get; set; }
        }

        [TestMethod]
        public void ImportCollections_ImportTypeThrowsOnAdd()
        {
            ExpectedErrorOnPartActivate(new ImportCustomCollectionThrowsDuringAdd(),
                ErrorId.ReflectionModel_ImportCollectionAddThrewException);
        }

        public class CustomCollectionThrowsDuringIsReadOnly : ICollection<int>
        {
            void ICollection<int>.Add(int item)
            {
                throw new NotImplementedException();
            }

            void ICollection<int>.Clear()
            {
                throw new NotImplementedException();
            }

            bool ICollection<int>.Contains(int item)
            {
                throw new NotImplementedException();
            }

            void ICollection<int>.CopyTo(int[] array, int arrayIndex)
            {
                throw new NotImplementedException();
            }

            int ICollection<int>.Count
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection<int>.IsReadOnly
            {
                get { throw new NotSupportedException(); }
            }

            bool ICollection<int>.Remove(int item)
            {
                throw new NotImplementedException();
            }

            IEnumerator<int> IEnumerable<int>.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                throw new NotImplementedException();
            }
        }

        public class ImportCustomCollectionThrowsDuringIsReadOnly
        {
            public ImportCustomCollectionThrowsDuringIsReadOnly()
            {
                Values = new CustomCollectionThrowsDuringIsReadOnly();
            }

            [ImportMany("Value")]
            public CustomCollectionThrowsDuringIsReadOnly Values { get; set; }
        }

        [TestMethod]
        public void ImportCollections_ImportTypeThrowsOnIsReadOnly()
        {
            ExpectedErrorOnPartActivate(new ImportCustomCollectionThrowsDuringIsReadOnly(),
                ErrorId.ReflectionModel_ImportCollectionIsReadOnlyThrewException);
        }

        public class CollectionTypeWithNoIList<T> : ICollection<T>
        {
            private int _count = 0;
            public CollectionTypeWithNoIList()
            {
                
            }

            public void Add(T item)
            {
                // Do Nothing
                this._count++;
            }

            public void Clear()
            {
                // Do Nothings
            }

            public bool Contains(T item)
            {
                throw new NotImplementedException();
            }

            public void CopyTo(T[] array, int arrayIndex)
            {
                throw new NotImplementedException();
            }

            public int Count
            {
                get { return this._count; }
            }

            public bool IsReadOnly
            {
                get { return false; }
            }

            public bool Remove(T item)
            {
                throw new NotImplementedException();
            }

            public IEnumerator<T> GetEnumerator()
            {
                throw new NotImplementedException();
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                throw new NotImplementedException();
            }
        }

        public class ImportCollectionWithNoIList
        {
            [ImportMany("Value")]
            public CollectionTypeWithNoIList<int> Values { get; set; }
        }

        [TestMethod]
        public void ImportCollections_NoIList_ShouldWorkFine()
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            var importer = new ImportCollectionWithNoIList();
            batch.AddPart(importer);
            batch.AddExportedValue("Value", 42);
            batch.AddExportedValue("Value", 0);

            container.Compose(batch);

            Assert.AreEqual(2, importer.Values.Count);
        }

        public class CollectionWithMultipleInterfaces :  ICollection<int>, ICollection<string>
        {
            private int _count = 0;
            public CollectionWithMultipleInterfaces()
            {

            }

            #region ICollection<int> Members

            void ICollection<int>.Add(int item)
            {
                throw new NotImplementedException();
            }

            void ICollection<int>.Clear()
            {
                throw new NotImplementedException();
            }

            bool ICollection<int>.Contains(int item)
            {
                throw new NotImplementedException();
            }

            void ICollection<int>.CopyTo(int[] array, int arrayIndex)
            {
                throw new NotImplementedException();
            }

            int ICollection<int>.Count
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection<int>.IsReadOnly
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection<int>.Remove(int item)
            {
                throw new NotImplementedException();
            }

            IEnumerator<int> IEnumerable<int>.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            #endregion

            #region IEnumerable Members

            IEnumerator IEnumerable.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            #endregion

            #region ICollection<string> Members

            void ICollection<string>.Add(string item)
            {
                throw new NotImplementedException();
            }

            void ICollection<string>.Clear()
            {
                throw new NotImplementedException();
            }

            bool ICollection<string>.Contains(string item)
            {
                throw new NotImplementedException();
            }

            void ICollection<string>.CopyTo(string[] array, int arrayIndex)
            {
                throw new NotImplementedException();
            }

            int ICollection<string>.Count
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection<string>.IsReadOnly
            {
                get { throw new NotImplementedException(); }
            }

            bool ICollection<string>.Remove(string item)
            {
                throw new NotImplementedException();
            }

            IEnumerator<string> IEnumerable<string>.GetEnumerator()
            {
                throw new NotImplementedException();
            }

            #endregion
        }

        public class ImportCollectionWithMultipleInterfaces
        {
            [ImportMany("Value")]
            public CollectionWithMultipleInterfaces Values { get; set; }
        }
        
        [TestMethod]
        public void ImportCollections_MultipleICollections_ShouldCauseNotWriteable()
        {
            ExpectedErrorOnPartActivate(new ImportCollectionWithMultipleInterfaces(),
                ErrorId.ReflectionModel_ImportCollectionNotWritable);
        }

        public class ImportManyNonCollectionTypeString
        {
            [ImportMany("Value")]
            public string Foo { get; set; }
        }

        [TestMethod]
        public void ImportManyOnNonCollectionTypeString_ShouldCauseNotWritable()
        {
            ExpectedErrorOnPartActivate(new ImportManyNonCollectionTypeString(),
                ErrorId.ReflectionModel_ImportCollectionNotWritable);
        }

        public class ImportManyNonCollectionTypeObject
        {
            [ImportMany("Value")]
            public object Foo { get; set; }
        }

        [TestMethod]
        public void ImportManyOnNonCollectionTypeObject_ShouldCauseNotWritable()
        {
            ExpectedErrorOnPartActivate(new ImportManyNonCollectionTypeObject(),
                ErrorId.ReflectionModel_ImportCollectionNotWritable);
        }

#if !SILVERLIGHT 
        // SILVERLIGHT doesn't have SetEnvironmentVariable set in this test.
        public class ExportADictionaryObject
        {
            [Export]
            public IDictionary<string, object> MyDictionary
            {
                get
                {
                    var dictionary = new Dictionary<string, object>();
                    dictionary.Add("a", 42);
                    dictionary.Add("b", "c");
                    return dictionary;
                }
            }
        }

        public class ImportADictionaryObject
        {
            [Import]
            public IDictionary<string, object> MyDictionary { get; set; }
        }

        [TestMethod]
        public void ImportDictionaryAsSingleObject()
        {
            // Set variable to ensure the hack is turned off.
            Environment.SetEnvironmentVariable("ONLY_ALLOW_IMPORTMANY", "1");

            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            var importer = new ImportADictionaryObject();
            var exporter = new ExportADictionaryObject();

            batch.AddPart(importer);
            batch.AddPart(exporter);
            container.Compose(batch);

            Assert.AreEqual(2, importer.MyDictionary.Count);
        }

        public class ExportACollectionObject
        {
            [Export]
            public Collection<string> MyCollection
            {
                get
                {
                    var collection = new Collection<string>();
                    collection.Add("a");
                    collection.Add("b");
                    return collection;
                }
            }
        }

        public class ImportACollectionObject
        {
            [Import]
            public Collection<string> MyCollection { get; set; }
        }

        [TestMethod]
        public void ImportCollectionAsSingleObject()
        {
            // Set variable to ensure the hack is turned off.
            Environment.SetEnvironmentVariable("ONLY_ALLOW_IMPORTMANY", "1");

            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            var importer = new ImportACollectionObject();
            var exporter = new ExportACollectionObject();

            batch.AddPart(importer);
            batch.AddPart(exporter);
            container.Compose(batch);

            Assert.AreEqual(2, importer.MyCollection.Count);
        }
#endif

        public void ExpectedErrorOnPartActivate(object importer, ErrorId expectedErrorId)
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            batch.AddPart(importer);
            batch.AddExportedValue("Value", 42);
            batch.AddExportedValue("Value", 0);

            CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotActivate,
              expectedErrorId, RetryMode.DoNotRetry, () =>
              {
                  container.Compose(batch);
              });
        }

        public void ExpectedErrorOnSetImport(object importer, ErrorId expectedErrorId)
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            batch.AddPart(importer);
            batch.AddExportedValue("Value", 42);
            batch.AddExportedValue("Value", 0);

            CompositionAssert.ThrowsError(ErrorId.ImportEngine_PartCannotSetImport,
              expectedErrorId, RetryMode.DoNotRetry, () =>
              {
                  container.Compose(batch);
              });
        }

        public void ExpectedChangeRejectedErrorOnSetImport(object importer, ErrorId expectedErrorId)
        {
            var container = ContainerFactory.Create();
            var batch = new CompositionBatch();
            batch.AddPart(importer);
            batch.AddExportedValue("Value", 42);
            batch.AddExportedValue("Value", 0);

            CompositionAssert.ThrowsChangeRejectedError(ErrorId.ImportEngine_PartCannotSetImport,
              expectedErrorId, RetryMode.DoNotRetry, () =>
              {
                  container.Compose(batch);
              });
        }
    }
}