Beispiel #1
0
        public static void WriterAsReadOnlyCollection()
        {
            using var writer = new PooledArrayBufferWriter <int>();
            IReadOnlyList <int> collection = writer;

            Empty(collection);

            writer.Add(42);
            Equal(1, writer.WrittenCount);
            Equal(1, collection.Count);
            Equal(42, collection[0]);
            Throws <IndexOutOfRangeException>(() => collection[1]);
            Equal(42, Enumerable.First(collection));
            Equal(1, Enumerable.Count(collection));

            writer.AddAll(new[] { 43, 44 });
            Equal(3, writer.WrittenCount);
            Equal(3, collection.Count);
            Equal(42, collection[0]);
            Equal(43, collection[1]);
            Equal(44, collection[2]);
            Throws <IndexOutOfRangeException>(() => collection[3]);
            Equal(3, Enumerable.Count(collection));
            Equal(new[] { 42, 43, 44 }, Enumerable.ToArray(collection));
        }
Beispiel #2
0
        public static void WriterAsList()
        {
            using var writer = new PooledArrayBufferWriter <int>();
            IList <int> list = writer;

            False(list.IsReadOnly);
            Empty(writer);
            True(list.IndexOf(0) < 0);
            False(list.Contains(0));
            False(list.Remove(0));
            Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(0));

            list.Add(42);
            Equal(1, writer.WrittenCount);
            Equal(1, list.Count);
            Equal(42, list[0]);
            True(list.Contains(42));
            False(list.Contains(0));
            Equal(0, list.IndexOf(42));
            Throws <ArgumentOutOfRangeException>(() => list[1]);
            Equal(42, Enumerable.First(list));
            Equal(1, Enumerable.Count(list));
            list[0] = 10;
            Equal(10, writer.WrittenArray[0]);

            list.Insert(0, 42);
            Equal(2, writer.WrittenCount);
            Equal(2, list.Count);
            True(list.Contains(10));
            True(list.Contains(42));
            Equal(0, list.IndexOf(42));
            Equal(1, list.IndexOf(10));
            Equal(42, list[0]);
            Equal(10, list[1]);

            list.RemoveAt(0);
            Equal(1, writer.WrittenCount);
            Equal(1, list.Count);
            Equal(10, list[0]);
            True(list.Contains(10));
            False(list.Contains(42));

            True(list.Remove(10));
            Empty(list);
            Throws <ArgumentOutOfRangeException>(() => list.Insert(1, 56));

            list.Insert(0, 56);
            Equal(1, writer.WrittenCount);
            Equal(1, list.Count);
            Equal(56, list[0]);

            //check insertion with overflow
            for (var i = writer.Capacity; i > 0; i--)
            {
                list.Insert(0, i + 100);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var values       = new List <int>(Linq.Range(0, 10));
            var useLinqFirst = Linq.First(values);

            Console.WriteLine("LINQ First(): {0}", useLinqFirst);
            var useMyFirst = values.First();

            Console.WriteLine("My First(): {0}", useMyFirst);
            Console.ReadLine();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GeometryProvider"/>.
        /// </summary>
        /// <param name="geometries">
        /// Set of geometries to add to this data source.
        /// </param>
        public GeometryProvider(IEnumerable <IGeometry> geometries)
        {
            if (geometries == null)
            {
                throw new ArgumentNullException("geometries");
            }

            _geoFactory = Enumerable.First(geometries).Factory;
            OriginalSpatialReference = _geoFactory == null ? null : _geoFactory.SpatialReference;
            OriginalSrid             = _geoFactory == null ? null : _geoFactory.Srid;
            _geometries.AddRange(geometries);
        }
Beispiel #5
0
        public void GroupBy_NoObservableKeyChangesEraseGroup_NoUpdate()
        {
            var update = false;

            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();
            var dummy1 = new Dummy <string>("A");
            var dummy2 = new Dummy <string>("B");

            coll.Add(dummy1);
            coll.Add(dummy2);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "A"), dummy1));
            Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "B"), dummy2));
            Assert.IsFalse(update);

            dummy2.Item = "A";

            Assert.IsFalse(update);
        }
        public void Save_Also_Attaches_The_Entity()
        {
            // arrange
            var entity = new Artist();

            var entityServiceMock = TestHelper.SetupMock <IEntityService>();

            entityServiceMock.Setup(s => s.GetChildEntities(entity, Cascade.Save)).Returns(new List <Entity> {
                entity
            });

            var connectionMock = TestHelper.SetupMock <IConnection>();
            var session        = new Session(connectionMock.Object);

            // act
            session.Save(entity);

            // assert
            Assert.Equal(entity, (Artist)Enumerable.First(GetPersistenceContext(session)));

            entityServiceMock.VerifyAll();
            connectionMock.VerifyAll();
        }