internal static void InitializeUniqueEmailAddressSource()
 {
     var recordCount = Fixture.Words(FromDictionary.PersonEmailAddress).Data.Count;
     var generator = new SequentialGenerator(0, recordCount, listShouldBeUnique: true);
     _uniquePersonEmailAddressSource = new Words(generator, new CachedFileDictionaryRepository(),
         FromDictionary.PersonEmailAddress);
 }
 public void WhenGeneratingIntegers_ThenShouldBeSequential()
 {
     var sut = new SequentialGenerator(0, 11);
     for (int index = sut.StartIndex; index < sut.ListSize; index++)
     {
         sut.Generate().ShouldBe(index);
     }
 }
        public void GivenGeneratorIsNotUnique_WhenGeneratingIntegers_ThenShouldResetAtEndOfList()
        {
            var sut = new SequentialGenerator(0, 2);
            for (int index = sut.StartIndex; index < sut.ListSize; index++)
            {
                sut.Generate().ShouldBe(index);
            }

            sut.Generate().ShouldBe(sut.StartIndex);
        }
        /// <summary>
        /// Generate and return a unique email address (within the fixture).
        /// </summary>
        /// <param name="fixture">The fixture to generate a unique email for</param>
        /// <returns>The generated unique email</returns>
        public static string UniqueEmailAddress(this AnonymousValueFixture fixture)
        {
            if (_uniquePersonEmailAddressSource == null)
            {
                if (_personEmailAddressSource == null) _personEmailAddressSource = new PersonEmailAddressSource();
                var generator = new SequentialGenerator(0, _personEmailAddressSource.Data.Count, listShouldBeUnique: true);
                _uniquePersonEmailAddressSource = new PersonEmailAddressSource(generator);
            }

            return _uniquePersonEmailAddressSource.Next();
        }
        public void GivenGeneratorIsUnique_WhenGeneratingIntegers_ThenShouldThrowAtEndOfList()
        {
            var sut = new SequentialGenerator(0, 2, true);
            for (int index = sut.StartIndex; index < sut.ListSize; index++)
            {
                sut.Generate().ShouldBe(index);
            }

            Should.Throw<InvalidOperationException>(()=>sut.Generate())
                .Message.ShouldBe("There are not enough elements in the data source to continue adding items");
        }
        public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesImplicitly_ThenTheCustomisationShouldTakeEffect()
        {
            var generator = new SequentialGenerator(0, 100);
            
            List<Customer> data = CustomerBuilder.CreateListOfSize(3)
                .All().With(b => b.WithFirstName(generator.Generate().ToString()));

            data.Select(c => c.FirstName).ToArray()
                .ShouldBe(new[] { "0", "1", "2" });
        }
        public void GivenListOfBuildersWithCustomisation_WhenBuildingObjectsExplicitly_ThenTheCustomisationShouldTakeEffect()
        {
            var generator = new SequentialGenerator(0, 100);
            var list = Builder<StudentViewModel>.CreateListOfSize(3)
                .All().With(b => b.Set(x => x.FirstName, generator.Generate().ToString()));

            var data = list.BuildList();

            data.Select(c => c.FirstName).ToArray()
                .ShouldBe(new[] { "0", "1", "2" });
        }