Пример #1
0
 public void TestRemove()
 {
     List<object> list = new List<object>(new object[] { "a", "b" });
     var test = new CollectionAdapter<object, string>(list);
     Assert.True(test.Remove("a"));
     Utilities.TestSequenceEqual(list, "b");
 }
Пример #2
0
        public void TestRemoveInvalid()
        {
            List <string> list = new List <string>();
            var           test = new CollectionAdapter <string, object>(list);

            Assert.Throws <InvalidOperationException>(delegate() { test.Remove(new object()); });
        }
Пример #3
0
 public void TestAddNull()
 {
     List<object> list = new List<object>();
     var test = new CollectionAdapter<object, string>(list);
     test.Add(null);
     Utilities.TestSequenceEqual(list, (object)null);
 }
Пример #4
0
        public void TestReadonly()
        {
            List <object> list = new List <object>(new object[] { "a", "b" });
            var           test = new CollectionAdapter <object, string>(list);

            Assert.False(test.IsReadOnly);
        }
Пример #5
0
        public void TestRemoveNull()
        {
            List <object> list = new List <object>();
            var           test = new CollectionAdapter <object, string>(list);

            Assert.False(test.Remove(null));
        }
Пример #6
0
        public void CountMatchesSource()
        {
            IList <int> baseCollection = System.Linq.Enumerable.Range(0, 10).ToList();
            var         col            = new CollectionAdapter <int>(() => baseCollection);

            Assert.Equal(baseCollection.Count, col.Count);
        }
Пример #7
0
        public void AddRemoveElement()
        {
            IList <int> baseCollection      = new List <int>(new[] { 2, 3, 4 });
            bool        hitAdd              = false;
            bool        hitRemove           = false;
            var         forwardedCollection = new CollectionAdapter <int>(
                () => baseCollection,
                x => { hitAdd = true; baseCollection.Add(x); },
                x => { hitRemove = true; return(baseCollection.Remove(x)); });

            Assert.Equal(baseCollection, forwardedCollection);
            Assert.False(hitAdd);
            Assert.False(hitRemove);

            forwardedCollection.Add(5);
            Assert.Equal(baseCollection, forwardedCollection);
            Assert.True(hitAdd);
            Assert.False(hitRemove);

            hitRemove = false;
            hitAdd    = false;
            forwardedCollection.Remove(2);

            Assert.Equal(baseCollection, forwardedCollection);
            Assert.False(hitAdd);
            Assert.True(hitRemove);
        }
            public override void OnNext(ChangedCollectionData <T> value)
            {
                var change = new CollectionChange <T, TAdaptee>(value.Change, _selector);
                var state  = new CollectionAdapter <T, TAdaptee>(value.ReachedState, _selector);

                this.Adaptee.OnNext(new ChangedCollectionData <TAdaptee>(change, state));
            }
Пример #9
0
        public void TestConstructor()
        {
            CollectionAdapter <object, string> test;

            Assert.Throws <ArgumentNullException>(
                delegate() { test = new CollectionAdapter <object, string>(null); });
        }
Пример #10
0
        public void ContainsEnsureSourcePresence()
        {
            IList <int> baseCollection = System.Linq.Enumerable.Range(0, 10).ToList();
            var         col            = new CollectionAdapter <int>(() => baseCollection, baseCollection.Add, baseCollection.Remove);

            Assert.Contains(3, col);
            Assert.Throws <ContainsException>(() => Assert.Contains(10, col));
        }
Пример #11
0
 public void TestCount()
 {
     List<object> list = new List<object>(new object[] { "a", "b" });
     var test = new CollectionAdapter<object, string>(list);
     Assert.True(test.Count == 2);
     list.Clear();
     Assert.True(test.Count == 0);
 }
Пример #12
0
 public void TestConstructor()
 {
     #pragma warning disable 219 //disable warning about 'test' not being used
     CollectionAdapter<object, string> test;
     #pragma warning restore 219
     Assert.Throws<ArgumentNullException>(
         delegate() { test = new CollectionAdapter<object, string>(null); });
 }
Пример #13
0
        public void TestAddNull()
        {
            List <object> list = new List <object>();
            var           test = new CollectionAdapter <object, string>(list);

            test.Add(null);
            Utilities.TestSequenceEqual(list, (object)null);
        }
Пример #14
0
        public void TestRemove()
        {
            List <object> list = new List <object>(new object[] { "a", "b" });
            var           test = new CollectionAdapter <object, string>(list);

            Assert.True(test.Remove("a"));
            Utilities.TestSequenceEqual(list, "b");
        }
 public void TestConstructor()
 {
     #pragma warning disable 219 //disable warning about 'test' not being used
     CollectionAdapter <object, string> test;
     #pragma warning restore 219
     Assert.Throws <ArgumentNullException>(
         delegate() { test = new CollectionAdapter <object, string>(null); });
 }
Пример #16
0
        public void TestCount()
        {
            List <object> list = new List <object>(new object[] { "a", "b" });
            var           test = new CollectionAdapter <object, string>(list);

            Assert.True(test.Count == 2);
            list.Clear();
            Assert.True(test.Count == 0);
        }
Пример #17
0
        public void ClearCleansSource()
        {
            IList <int> baseCollection = System.Linq.Enumerable.Range(0, 10).ToList();
            var         col            = new CollectionAdapter <int>(() => baseCollection, baseCollection.Add, baseCollection.Remove);

            col.Clear();
            Assert.Empty(baseCollection);
            Assert.Empty(col);
        }
Пример #18
0
        public void IsReadOnlyOnNullCallbacks()
        {
            IList <int> baseCollection = System.Linq.Enumerable.Range(0, 10).ToList();
            var         col            = new CollectionAdapter <int>(() => baseCollection);

            Assert.True(col.IsReadOnly);
            col = new CollectionAdapter <int>(() => baseCollection, baseCollection.Add, baseCollection.Remove);
            Assert.False(col.IsReadOnly);
        }
Пример #19
0
        public static ICollection <T> AsCollection <T>(this IEnumerable <T> collection)
        {
            var result = collection as ICollection <T>;

            if (null != result)
            {
                return(result);
            }
            result = new CollectionAdapter <T>(collection);
            return(result);
        }
Пример #20
0
        public SpatialQuery(params ISpatialQuery <TInput>[] queries)
        {
            if (queries == null)
            {
                throw new ArgumentNullException("query");
            }

            this.Condition    = d => d is TOutput;
            this.Converter    = d => (TOutput)(object)d;
            this.InnerQueries = new List <ISpatialQuery <TInput> >(queries);
            this.adapter      = new CollectionAdapter()
            {
                Parent = this
            };
        }
Пример #21
0
 public SceneQuery(List <ISceneManager <ISpatialQueryable> > sceneManagers, IList <object> topLevelObjects, Predicate <T> condition)
 {
     this.sceneManagers   = sceneManagers;
     this.topLevelObjects = topLevelObjects;
     this.adapter         = new CollectionAdapter(condition);
 }
Пример #22
0
        public void MapCollection()
        {
            var person = new Person()
            {
                Id      = Guid.NewGuid(),
                Name    = "Timuçin",
                Surname = "KIVANÇ",
                Project = Projects.A,
                X       = new int[] { 1, 2, 3, 4 },
                Y       = new List <int>()
                {
                    5, 6, 7
                },
                Z   = new ArrayList((ICollection)(new List <Guid>()
                {
                    Guid.NewGuid(), Guid.NewGuid()
                })),
                Ids = new List <Guid>()
                {
                    Guid.Empty, Guid.NewGuid()
                },
                CityId    = Guid.NewGuid(),
                Picture   = new byte[] { 0, 1, 2 },
                Countries = new List <string> {
                    "Turkey", "Germany"
                },
                XX = new List <string> {
                    "Nederland", "USA"
                },
                YY = new List <int> {
                    22, 33
                },
                ZZ = new List <int> {
                    44, 55
                },
                RelatedDepartments = new Departments[] { Departments.IT, Departments.Finance },
                Projects           = new List <XProject>()
                {
                    new XProject {
                        Id = 1, Name = "Project X"
                    }
                }
            };

            var persons = new List <Person>()
            {
                person
            };

            var dtos = (Person[])CollectionAdapter <List <Person>, Person, Person[]> .Adapt(persons);

            Assert.IsNotNull(dtos);
            Assert.IsTrue(dtos.Length == 1);
            Assert.IsTrue(dtos.First().Id == person.Id &&
                          dtos.First().Name == "Timuçin" &&
                          dtos.First().Surname == "KIVANÇ");

            Assert.IsNotNull(dtos[0].Projects);

            Assert.IsTrue(dtos[0].Projects.First().Id == 1 && dtos[0].Projects.First().Name == "Project X");
        }
Пример #23
0
 public void TestReadonly()
 {
     List<object> list = new List<object>(new object[] { "a", "b" });
     var test = new CollectionAdapter<object, string>(list);
     Assert.False(test.IsReadOnly);
 }
Пример #24
0
 public void Initialize()
 {
     _targetAdapter = new CollectionAdapter();
     _sourceAdapter = new ValueAdapter();
     _comparer      = EqualityComparer <object> .Default;
 }
Пример #25
0
 public void TestRemoveNull()
 {
     List<object> list = new List<object>();
     var test = new CollectionAdapter<object, string>(list);
     Assert.False(test.Remove(null));
 }
Пример #26
0
 public void TestConstructor()
 {
     CollectionAdapter<object, string> test;
     Assert.Throws<ArgumentNullException>(
         delegate() { test = new CollectionAdapter<object, string>(null); });
 }
Пример #27
0
        static void Main(string[] args)
        {
            ICollectionBase adapter = new CollectionAdapter();

            adapter.Add("dddd");
        }
Пример #28
0
 public void TestRemoveInvalid()
 {
     List<string> list = new List<string>();
     var test = new CollectionAdapter<string, object>(list);
     Assert.Throws<InvalidOperationException>(delegate() { test.Remove(new object()); });
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ItemStorageAdapter"/> class.
 /// </summary>
 /// <param name="actualStorage">The actual storage.</param>
 /// <param name="firstItemSlot">The first item slot.</param>
 /// <param name="itemSlotCount">The item slot count.</param>
 public ItemStorageAdapter(ItemStorage actualStorage, byte firstItemSlot, byte itemSlotCount)
 {
     this.adapter       = new CollectionAdapter(actualStorage.Items, firstItemSlot, itemSlotCount);
     this.ActualStorage = actualStorage;
 }
Пример #30
0
        public void CanTestContentsOfCollectionNotImplementingIList()
        {
            CollectionAdapter ints = new CollectionAdapter(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            Assert.That(ints, new CollectionContainsConstraint(9));
        }