public void Should_Add_Selector_To_Back_Of_List() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); Assert.AreEqual(0, table.CountSelectors<string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add the first selector (our default string selector) table.AddSelector<string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors<string>(), "should have ONE type selectors for type 'string'"); var firstselector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstselector); //Add the second selector (FullNameSelector) to the back of the processing queue table.AddSelector(stringSelector2, SelectorPosition.Last); Assert.AreEqual(2, table.CountSelectors<string>(), "should have TWO type selectors for type 'string'"); firstselector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstselector); var lastselector = table.GetSelectors<string>().Last(); Assert.IsInstanceOf<FullNameSelector>(lastselector); }
public void Should_Add_Type_Selectors_For_Single_Type_To_TypeTable() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); var stringSelector3 = new EmailSelector(); Assert.AreEqual(0, table.CountSelectors <string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add the first selector (our default string selector) table.AddSelector <string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors <string>(), "should have ONE type selectors for type 'string'"); var firstselector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstselector); //Add the second selector (the full name selector) table.AddSelector <string>(stringSelector2); Assert.AreEqual(2, table.CountSelectors <string>(), "should have TWO type selectors for type 'string'"); firstselector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <FullNameSelector>(firstselector); //Oh snap, the new front of the line should be our full name selector! //Add the thrid selector (the email address selector) table.AddSelector <string>(stringSelector3); Assert.AreEqual(3, table.CountSelectors <string>(), "should have THREE type selectors for type 'string'"); firstselector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <EmailSelector>(firstselector); //Oh snap, the new front of the line should be our full name selector! }
public void Should_Add_Selector_To_Back_Of_List() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); Assert.AreEqual(0, table.CountSelectors <string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add the first selector (our default string selector) table.AddSelector <string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors <string>(), "should have ONE type selectors for type 'string'"); var firstselector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstselector); //Add the second selector (FullNameSelector) to the back of the processing queue table.AddSelector(stringSelector2, SelectorPosition.Last); Assert.AreEqual(2, table.CountSelectors <string>(), "should have TWO type selectors for type 'string'"); firstselector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstselector); var lastselector = table.GetSelectors <string>().Last(); Assert.IsInstanceOf <FullNameSelector>(lastselector); }
public void Should_Add_Type_Selectors_For_Multiple_Types_To_TypeTable() { //Create a new TypeTable var table = new TypeTable(false); //Create some string selectors that we're going to add var stringSelector1 = new StringSelector(); //Create some long selectors that we're going to use... var longSelector1 = new LongSelector(); var longSelector2 = new TimeStampSelector(); Assert.AreEqual(0, table.CountSelectors <string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); Assert.AreEqual(0, table.CountSelectors <long>(), "should have ZERO type selectors for type 'long' since we haven't added any yet"); //Add the first and only string selector (our default string selector) table.AddSelector <string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors <string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(0, table.CountSelectors <long>(), "should have ZERO type selectors for type 'long' since we haven't added any yet"); //Assert that we haven't added any long selectors yet var firstStringSelector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstStringSelector); var currentLongSelector = table.GetSelectors <long>().FirstOrDefault(); Assert.IsNull(currentLongSelector); //Since we haven't added any long selectors yet, this should return null //Add the first long selector (our default long selector) table.AddSelector <long>(longSelector1); Assert.AreEqual(1, table.CountSelectors <string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(1, table.CountSelectors <long>(), "should have ONE type selectors for type 'long'"); firstStringSelector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstStringSelector); currentLongSelector = table.GetSelectors <long>().FirstOrDefault(); Assert.IsInstanceOf <LongSelector>(currentLongSelector); //Add the final long selector (our timestamp selector) table.AddSelector <long>(longSelector2); Assert.AreEqual(1, table.CountSelectors <string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(2, table.CountSelectors <long>(), "should have TWO type selectors for type 'long'"); firstStringSelector = table.GetSelectors <string>().First(); Assert.IsInstanceOf <StringSelector>(firstStringSelector); currentLongSelector = table.GetSelectors <long>().FirstOrDefault(); Assert.IsInstanceOf <TimeStampSelector>(currentLongSelector); }
public void Should_Add_Type_Selectors_For_Multiple_Types_To_TypeTable() { //Create a new TypeTable var table = new TypeTable(false); //Create some string selectors that we're going to add var stringSelector1 = new StringSelector(); //Create some long selectors that we're going to use... var longSelector1 = new LongSelector(); var longSelector2 = new TimeStampSelector(); Assert.AreEqual(0, table.CountSelectors<string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); Assert.AreEqual(0, table.CountSelectors<long>(), "should have ZERO type selectors for type 'long' since we haven't added any yet"); //Add the first and only string selector (our default string selector) table.AddSelector<string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors<string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(0, table.CountSelectors<long>(), "should have ZERO type selectors for type 'long' since we haven't added any yet"); //Assert that we haven't added any long selectors yet var firstStringSelector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstStringSelector); var currentLongSelector = table.GetSelectors<long>().FirstOrDefault(); Assert.IsNull(currentLongSelector); //Since we haven't added any long selectors yet, this should return null //Add the first long selector (our default long selector) table.AddSelector<long>(longSelector1); Assert.AreEqual(1, table.CountSelectors<string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(1, table.CountSelectors<long>(), "should have ONE type selectors for type 'long'"); firstStringSelector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstStringSelector); currentLongSelector = table.GetSelectors<long>().FirstOrDefault(); Assert.IsInstanceOf<LongSelector>(currentLongSelector); //Add the final long selector (our timestamp selector) table.AddSelector<long>(longSelector2); Assert.AreEqual(1, table.CountSelectors<string>(), "should have ONE type selectors for type 'string'"); Assert.AreEqual(2, table.CountSelectors<long>(), "should have TWO type selectors for type 'long'"); firstStringSelector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstStringSelector); currentLongSelector = table.GetSelectors<long>().FirstOrDefault(); Assert.IsInstanceOf<TimeStampSelector>(currentLongSelector); }
//public static Arbitrary<ITypeSelector[]> Selectors() //{ // return Gen.Sequence(Gen.Elements(AvailableSelectors)).ToArbitrary(); //} public static Arbitrary<TypeTable> TypeTable() { Func<TypeTable> generator = () => { var table = new TypeTable(Faker.Generators.Booleans.Bool()); var selectors = AvailableSelectors.GetRandomSelection(Generators.Numbers.Int(0, 10)); foreach(var selector in selectors) table.AddSelector(selector); return table; }; return Arb.From(Gen.Fresh(generator)); }
public void Should_Skip_Types_Without_Selectors() { //Create a new TypTable that doesn't use any of the default types var typeTable = new TypeTable(false); //Add just the Float and DateTime selectors typeTable.AddSelector(new FloatSelector()); typeTable.AddSelector(new DateTimeSelector()); //Create a new matcher that users only the type selectors we've specified var typlessMatcher = new Matcher(typeTable); //Create a new instance of our test class var testInstance = new DefaultValueTestClass(); //Match the properties for which we have selectors typlessMatcher.Match(testInstance); /* ASSERT THAT THE PROPERTIES FOR WHICH WE HAVE INJECTORS ARE ALL SET */ //Test to see that proper values have been assigned to the DateTime properties Assert.AreNotEqual(testInstance.DateTime1, default(DateTime)); Assert.AreNotEqual(testInstance.DateTime2, default(DateTime)); //Test to see that the proper values have been assigned to the float properties Assert.AreNotEqual(testInstance.TestFloat, default(float)); Assert.AreNotEqual(testInstance.TestFloat, float.PositiveInfinity); Assert.AreNotEqual(testInstance.TestFloat, float.NegativeInfinity); Assert.AreNotEqual(testInstance.TestFloat2, default(float)); Assert.AreNotEqual(testInstance.TestFloat2, float.PositiveInfinity); Assert.AreNotEqual(testInstance.TestFloat2, float.NegativeInfinity); /* ASSERT THAT THE PROPERTIES THAT DON'T HAVE ANY SELECTORS ARE NOT SET */ Assert.AreEqual(testInstance.TestInt, default(int)); Assert.AreEqual(testInstance.TestLong, default(long)); Assert.AreEqual(testInstance.TestGuid, default(Guid)); Assert.IsNullOrEmpty(testInstance.RandomString); }
public void Should_Clear_TypeSelector_List() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); Assert.AreEqual(0, table.CountSelectors <string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add some type selectors to our typetable table.AddSelector(stringSelector1); table.AddSelector(stringSelector2); //Check to see that our table contains at least two items... Assert.AreEqual(2, table.CountSelectors <string>(), "should have TWO type selectors for type 'string'"); //Clear all of the string selectors table.ClearSelectors <string>(); //Count the new number of string selectors (should equal zero) Assert.AreEqual(0, table.CountSelectors <string>()); }
//public static Arbitrary<ITypeSelector[]> Selectors() //{ // return Gen.Sequence(Gen.Elements(AvailableSelectors)).ToArbitrary(); //} public static Arbitrary <TypeTable> TypeTable() { Func <TypeTable> generator = () => { var table = new TypeTable(Faker.Generators.Booleans.Bool()); var selectors = AvailableSelectors.GetRandomSelection(Generators.Numbers.Int(0, 10)); foreach (var selector in selectors) { table.AddSelector(selector); } return(table); }; return(Arb.From(Gen.Fresh(generator))); }
public void TypeTable_changes_to_original_should_not_modify_clone() { var typeTable = new TypeTable(); var typeTableIntSelectorCount = typeTable.CountSelectors(typeof(int)); var clone = typeTable.Clone(); var oldCloneTableIntSelectorCount = clone.CountSelectors(typeof(int)); typeTable.AddSelector(new IntSelector()); var newTypeTableSelectorCount = typeTable.CountSelectors(typeof(int)); // sanity check to make sure we added the new type selector Assert.AreEqual(typeTableIntSelectorCount, oldCloneTableIntSelectorCount); Assert.AreNotEqual(typeTableIntSelectorCount, newTypeTableSelectorCount); Assert.True(newTypeTableSelectorCount > typeTableIntSelectorCount); // make sure we didn't modify old originak var newCloneSelectorCount = clone.CountSelectors(typeof(int)); Assert.AreEqual(oldCloneTableIntSelectorCount, newCloneSelectorCount); }
public void Should_Add_Type_Selectors_For_Single_Type_To_TypeTable() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); var stringSelector3 = new EmailSelector(); Assert.AreEqual(0, table.CountSelectors<string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add the first selector (our default string selector) table.AddSelector<string>(stringSelector1); Assert.AreEqual(1, table.CountSelectors<string>(), "should have ONE type selectors for type 'string'"); var firstselector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<StringSelector>(firstselector); //Add the second selector (the full name selector) table.AddSelector<string>(stringSelector2); Assert.AreEqual(2, table.CountSelectors<string>(), "should have TWO type selectors for type 'string'"); firstselector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<FullNameSelector>(firstselector); //Oh snap, the new front of the line should be our full name selector! //Add the thrid selector (the email address selector) table.AddSelector<string>(stringSelector3); Assert.AreEqual(3, table.CountSelectors<string>(), "should have THREE type selectors for type 'string'"); firstselector = table.GetSelectors<string>().First(); Assert.IsInstanceOf<EmailSelector>(firstselector); //Oh snap, the new front of the line should be our full name selector! }
public void Should_Clear_TypeSelector_List() { //Create a new TypeTable var table = new TypeTable(false); //Create some selectors that we're going to add var stringSelector1 = new StringSelector(); var stringSelector2 = new FullNameSelector(); Assert.AreEqual(0, table.CountSelectors<string>(), "should have ZERO type selectors for type 'string' since we haven't added any yet"); //Add some type selectors to our typetable table.AddSelector(stringSelector1); table.AddSelector(stringSelector2); //Check to see that our table contains at least two items... Assert.AreEqual(2, table.CountSelectors<string>(), "should have TWO type selectors for type 'string'"); //Clear all of the string selectors table.ClearSelectors<string>(); //Count the new number of string selectors (should equal zero) Assert.AreEqual(0, table.CountSelectors<string>()); }