Пример #1
0
        public void TestCollectionToThreadSafeCollectionReadOnly()
        {
            const string metadataKey   = "Test";
            const string metadataValue = "Result";

            IEnumerable <Protocol.Models.MetadataItem> collection = new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem(metadataKey, metadataValue)
            };


            IEnumerable <MetadataItem> result = UtilitiesInternal.CollectionToThreadSafeCollectionIModifiable(
                collection,
                objectCreationFunc: o => new MetadataItem(o)).AsReadOnly();

            Assert.NotNull(result);
            Assert.Equal(1, result.Count());

            MetadataItem protoItem = result.First();

            Assert.Equal(metadataKey, protoItem.Name);
            Assert.Equal(metadataValue, protoItem.Value);

            Assert.IsAssignableFrom <IReadOnlyList <MetadataItem> >(result); //The list should be read only
        }
Пример #2
0
        public void TestCollectionToThreadSafeCollectionWithNull()
        {
            IEnumerable <Protocol.Models.MetadataItem> collection = null;
            IEnumerable <MetadataItem> result = UtilitiesInternal.CollectionToThreadSafeCollectionIModifiable(
                collection,
                objectCreationFunc: o => new MetadataItem(o));

            Assert.Null(result);
        }
Пример #3
0
        public void IModifiableCollectionFromExistingCollectionIsNotChanged()
        {
            IEnumerable <Protocol.Models.MetadataItem> collection = new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem("a", "b")
            };

            ConcurrentChangeTrackedModifiableList <MetadataItem> result = UtilitiesInternal.CollectionToThreadSafeCollectionIModifiable(
                collection,
                objectCreationFunc: o => new MetadataItem(o));

            Assert.False(result.HasBeenModified);
        }
Пример #4
0
        public void TestCollectionToThreadSafeCollectionNullItem()
        {
            IEnumerable <Protocol.Models.MetadataItem> collection = new List <Protocol.Models.MetadataItem>()
            {
                null
            };

            IEnumerable <MetadataItem> result = UtilitiesInternal.CollectionToThreadSafeCollectionIModifiable(
                collection,
                objectCreationFunc: o => new MetadataItem(o));

            Assert.NotNull(result);
            Assert.Equal(1, result.Count());

            MetadataItem protoItem = result.First();

            Assert.Null(protoItem);
        }
        public void TestCollectionToThreadSafeCollectionOneItem()
        {
            const string metadataKey   = "Test";
            const string metadataValue = "Result";

            IEnumerable <Protocol.Models.MetadataItem> collection = new List <Protocol.Models.MetadataItem>()
            {
                new Protocol.Models.MetadataItem(metadataKey, metadataValue)
            };


            IEnumerable <MetadataItem> result = UtilitiesInternal.CollectionToThreadSafeCollectionIModifiable(
                collection,
                objectCreationFunc: o => new MetadataItem(o));

            Assert.NotNull(result);
            Assert.Single(result);

            MetadataItem protoItem = result.First();

            Assert.Equal(metadataKey, protoItem.Name);
            Assert.Equal(metadataValue, protoItem.Value);
        }