public void Parse_WhenItPresentRangedBehaviour_ShouldReturnCorrectBehaviour(string maxValue, string minValue, object isMin) { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var document = GenerateDocumentWithOneOption(a => a.Use == XmlSchemaUse.Required, null, null, CreateRangedBehaviourMinMax(optionValue, minValue, maxValue, isMin)); var actual = Sut.Parse(CreateReader(document)); Assert.That(actual.Options[0].Behaviour, Is.TypeOf <RangedOptionBehaviour>()); var rangedOptionBehaviour = (RangedOptionBehaviour)actual.Options[0].Behaviour; Assert.That(rangedOptionBehaviour.MaxValue, Is.EqualTo(maxValue)); Assert.That(rangedOptionBehaviour.MinValue, Is.EqualTo(minValue)); if (isMin == null) { Assert.That(rangedOptionBehaviour.IsMaxValueExists, Is.True); Assert.That(rangedOptionBehaviour.IsMinValueExists, Is.True); } else if (!(bool)isMin) { Assert.That(rangedOptionBehaviour.IsMaxValueExists, Is.True); Assert.That(rangedOptionBehaviour.IsMinValueExists, Is.False); } else if ((bool)isMin) { Assert.That(rangedOptionBehaviour.IsMaxValueExists, Is.False); Assert.That(rangedOptionBehaviour.IsMinValueExists, Is.True); } }
public void MultiListOptionBehaviour_WhenWePassValidItems_TheyAssignedCorrectly() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var list = Fake <List <ListItem> >(); var actual = new MultiListOptionBehaviour(optionValue, list); Assert.That(actual.ListItems, Is.EqualTo(list)); }
public void MultiListOptionBehaviour_WhenWePassSortedAndSeparator_TheyAssignedCorrectly(bool sorted, string separator) { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var list = Fake <List <ListItem> >(); var actual = new MultiListOptionBehaviour(optionValue, list, sorted, separator); Assert.That(actual.Sorted, Is.EqualTo(sorted)); Assert.That(actual.Separator, Is.EqualTo(separator)); }
public void SqlMultiListOptionBehaviour_WhenWePassNullQuery_ThrowException() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); void Delegate() { new SqlMultiListOptionBehaviour(optionValue, null); } AssertEx.ThrowsArgumentNullException(Delegate, "query"); }
public void StringValue_WhenWePassString_SameStringShouldBeReturned() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var sut = new OptionBehaviourTest(optionValue); object expected = Fake <string>(); var actual = sut.StringValue(expected); Assert.That(actual, Is.EqualTo(expected)); }
public void SqlFixedListOptionBehaviour_WhenWePassValidItems_TheyAssignedCorrectly() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var query = "Test Query"; var value = "Test Value"; var displayValue = "Test Display Value"; var actual = new SqlFixedListOptionBehaviour(optionValue, query, value, displayValue); Assert.That(actual.Query, Is.EqualTo(query)); Assert.That(actual.ValueMember, Is.EqualTo(value)); Assert.That(actual.DisplayMember, Is.EqualTo(displayValue)); }
public void RangedOptionBehaviour_WhenWePassMinAndMax_TheyAssignedCorrectly() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var maxValue = Fake <string>(); var minValue = Fake <string>(); var actual = new RangedOptionBehaviour(optionValue, minValue, maxValue); Assert.That(actual.IsMaxValueExists, Is.True); Assert.That(actual.IsMinValueExists, Is.True); Assert.That(actual.MaxValue, Is.EqualTo(maxValue)); Assert.That(actual.MinValue, Is.EqualTo(minValue)); }
public void SqlMultiListOptionBehaviour_WhenWePassValidItems_TheyAssignedCorrectly() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var query = Fake <string>(); var separator = Fake <string>(); var value = Fake <string>(); var displayValue = Fake <string>(); var actual = new SqlMultiListOptionBehaviour(optionValue, query, true, separator, value, displayValue); Assert.That(actual.Query, Is.EqualTo(query)); Assert.That(actual.Sorted, Is.True); Assert.That(actual.Separator, Is.EqualTo(separator)); Assert.That(actual.ValueMember, Is.EqualTo(value)); Assert.That(actual.DisplayMember, Is.EqualTo(displayValue)); }
private static void FillParsers() { lock (OptionSetParsers) { if (OptionSetParsers.Count < 1) { var assembly = Assembly.GetExecutingAssembly(); var marker = typeof(OptionSetParser); var types = assembly.GetTypes().Where(t => !t.IsAbstract && marker.IsAssignableFrom(t)); var optionValueFactory = new OptionValueFactory(); foreach (var type in types) { var instance = (OptionSetParser)Activator.CreateInstance(type, optionValueFactory); OptionSetParsers[instance.Version] = instance; } } } }
public void Parse_WhenItPresentSqlFlagListBehaviour_ShouldReturnCorrectBehaviour() { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var query = Fake <string>(); var memberValue = Fake <string>(); var displayValue = Fake <string>(); var document = GenerateDocumentWithOneOption(a => a.Use == XmlSchemaUse.Required, null, null, CreateSqlFlagListBehaviour(optionValue, query, memberValue, displayValue)); var actual = Sut.Parse(CreateReader(document)); Assert.That(actual.Options[0].Behaviour, Is.TypeOf <SqlFlagListOptionBehaviour>()); var sqlFlagListOptionBehaviour = (SqlFlagListOptionBehaviour)actual.Options[0].Behaviour; Assert.That(sqlFlagListOptionBehaviour.Query, Is.EqualTo(query)); Assert.That(sqlFlagListOptionBehaviour.ValueMember, Is.EqualTo(memberValue)); Assert.That(sqlFlagListOptionBehaviour.DisplayMember, Is.EqualTo(displayValue)); }
private OptionSet GetExpectedOptionSet(Option actual) { var optionSet = new OptionSet(); optionSet.Version = "1"; var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); optionSet.Options.Add(new Option { Name = actual.Name, DisplayName = OptionAttributeDefaults.DisplayName, Description = OptionAttributeDefaults.Description, DefaultValue = OptionAttributeDefaults.DefaultValue, ValueType = OptionAttributeDefaults.ValueType, Behaviour = new SimpleOptionBehaviour(optionValue) }); return(optionSet); }
public void Parse_WhenItPresentMultiListBehaviour_ShouldReturnCorrectBehaviour(bool sorted, string separator) { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var list = new List <ListItem> { new ListItem { Value = "Value 1", DisplayValue = "Display Value 1" }, new ListItem { Value = "Value 2", DisplayValue = "Display Value 2" }, new ListItem { Value = "Value 3", DisplayValue = "Display Value 3" }, new ListItem { Value = "Value 4", DisplayValue = "Display Value 4" }, }; var document = GenerateDocumentWithOneOption(a => a.Use == XmlSchemaUse.Required, null, null, CreateMultiListBehaviour(optionValue, list, sorted, separator)); var actual = Sut.Parse(CreateReader(document)); Assert.That(actual.Options[0].Behaviour, Is.TypeOf <MultiListOptionBehaviour>()); var multiListOptionBehaviour = (MultiListOptionBehaviour)actual.Options[0].Behaviour; Assert.That(multiListOptionBehaviour.ListItems, Is.EqualTo(list)); Assert.That(multiListOptionBehaviour.Sorted, Is.EqualTo(sorted)); Assert.That(multiListOptionBehaviour.Separator, Is.EqualTo(separator)); }
public void RangedOptionBehaviour_WhenWePassValueAndBool_TheyAssignedCorrectly(bool isMin) { var optionValueFactory = new OptionValueFactory(); var optionValue = optionValueFactory.Create(OptionValueType.String); var value = Fake <string>(); var actual = new RangedOptionBehaviour(optionValue, value, isMin); Assert.That(actual.IsMinValueExists, Is.EqualTo(isMin)); Assert.That(actual.IsMaxValueExists, Is.EqualTo(!isMin)); if (isMin) { Assert.That(actual.MaxValue, Is.Null); Assert.That(actual.MinValue, Is.EqualTo(value)); } else { Assert.That(actual.MinValue, Is.Null); Assert.That(actual.MaxValue, Is.EqualTo(value)); } }