Пример #1
0
            public void Otherwise_disperses_all_items_amongst_the_enumerable()
            {
                var        source           = new[] { -125, 512, -512, 0, 46, 733 };
                var        dispersion       = new[] { 0, 0xFF };
                Lot <long> dispersionPoints = new ArrayLot <long>(
                    new long[] { 1, 4 });
                long currentCount = 0;

                foreach (var item in this.disperser.Disperse(
                             source,
                             dispersion,
                             dispersionPoints))
                {
                    ++currentCount;
                    if (currentCount == 2) // dispersion point of 1
                    {
                        Assert.Equal(0, item);
                        continue;
                    }

                    if (currentCount == 6) // dispersion point of 4
                    {
                        Assert.Equal(0xFF, item);
                        continue;
                    }

                    Assert.Contains(item, source);
                }

                Assert.Equal(
                    currentCount,
                    source.Length + dispersionPoints.Count);
            }
            public void If_source_is_null_and_injections_is_null_yield_breaks()
            {
                var noItems         = true;
                var injectionPoints = new ArrayLot <long>(
                    new long[] { 0xFF, 0xFFF });

                foreach (var item in this.injector.Inject <object>(
                             null,
                             injectionPoints,
                             (Lot <object>)null))
                {
                    noItems = false;
                }

                Assert.True(noItems);
            }
            public void Otherwise_injects_the_injections_at_the_injection_points_in_the_enumerable()
            {
                var source = new object[]
                {
                    0xFFABF,
                    3.567,
                    @"testing 1 2 3...",
                    999,
                    0,
                    @"more test data"
                };
                byte       counter         = 0;
                Lot <long> injectionPoints = new ArrayLot <long>(
                    new long[] { 1, 3, 4 });
                var injections = new List <object>
                {
                    @"injection 1",
                    @"injection 2",
                    @"injection 3"
                };

                foreach (var item in this.injector.Inject(
                             source,
                             injectionPoints,
                             injections))
                {
                    object currentObject = null;
                    switch (counter)
                    {
                    case 0:
                        currentObject = source[0];
                        break;

                    case 1:
                        currentObject = injections[0];
                        break;

                    case 2:
                        currentObject = source[1];
                        break;

                    case 3:
                        currentObject = source[2];
                        break;

                    case 4:
                        currentObject = injections[1];
                        break;

                    case 5:
                        currentObject = source[3];
                        break;

                    case 6:
                        currentObject = injections[2];
                        break;

                    case 7:
                        currentObject = source[4];
                        break;

                    case 8:
                        currentObject = source[5];
                        break;
                    }

                    Assert.Same(item, currentObject);
                    ++counter;
                }
            }