public static void WhenArtSourceSometimesFailsTheRequestedNumberOfObjectsIsReturns()
        {
            Art.Object[] sourceObjects = new Art.Object[] { null, new Art.Object(), null, new Art.Object(), null, new Art.Object() };

            MockArtSource sometimesFailSource = new MockArtSource(sourceObjects);

            Art art = new Art(new IArtSource[] { sometimesFailSource });

            IEnumerable <Art.Object> objects = art.GetRandomObjects(1);

            Assert.Single(objects);
            Assert.NotNull(objects.First());
        }
Esempio n. 2
0
        public IEnumerable <Object> GetRandomObjects(int numObjects)
        {
            System.Random random = new System.Random();

            IArtSource artSource = sources.RandomElement(random);

            List <Art.Object> objects = new List <Art.Object>();

            for (int numberOfTries = 0; objects.Count < numObjects && numberOfTries < (numObjects + 10); numberOfTries++)
            {
                Art.Object newObject = artSource.GetRandomObject(random);
                if (newObject != null)
                {
                    objects.Add(newObject);
                }
            }

            return(objects);
        }