public ObjectConstructionExpression <T> SetAllPrimitiveProperties(Predicate <PropertyInfo> filter) { foreach (PropertyInfo property in typeof(T).GetProperties()) { if (!property.CanWrite) { continue; } if (!property.PropertyType.IsSimple()) { continue; } if (!filter(property)) { continue; } var accessor = new SingleProperty(property); var child = new SetPropertyGrammar(accessor); _grammar.AddGrammar(child); } return(this); }
public void create_a_grammar_structure() { SetPropertyGrammar grammar = SetPropertyGrammar.For <Address>(x => x.DistanceFromOffice); var sentence = grammar.ToStructure(new FixtureLibrary()).ShouldBeOfType <Sentence>(); sentence.ShouldEqual(Sentence.For("DistanceFromOffice = {DistanceFromOffice}", Cell.For <double>("DistanceFromOffice"))); }
private IGrammar setter(Expression<Func<AuthenticationSettings, object>> property) { var accessor = property.ToAccessor(); var grammar = new SetPropertyGrammar(accessor.InnerProperty); grammar.CellModifications.DefaultValue(accessor.GetValue(new AuthenticationSettings()).ToString()); return grammar; }
public SetPropertyGrammarFixture() { var grammar = SetPropertyGrammar.For <Address>(x => x.City); grammar.CellModifications.Header("The City").DefaultValue("Austin"); this["SetCity"] = grammar; }
private IGrammar setter(Expression <Func <AuthenticationSettings, object> > property) { var accessor = property.ToAccessor(); var grammar = new SetPropertyGrammar(accessor.InnerProperty); grammar.CellModifications.DefaultValue(accessor.GetValue(new AuthenticationSettings()).ToString()); return(grammar); }
public ObjectConstructionExpression <T> SetProperty(Expression <Func <T, object> > expression, string defaultValue) { Accessor accessor = FubuCore.Reflection.ReflectionHelper.GetAccessor(expression); var grammar = new SetPropertyGrammar(accessor) { DefaultValue = defaultValue }; _grammar.AddGrammar(grammar); return(this); }
public void sets_a_simple_property_happy_path() { SetPropertyGrammar grammar = SetPropertyGrammar.For <Address>(x => x.City); var context = new TestContext(); var address = new Address(); context.CurrentObject = address; Step step = new Step().With("City", "Dripping Springs"); grammar.Execute(step, context); address.City.ShouldEqual("Dripping Springs"); }
public void sets_a_numeric_property_happy_path() { SetPropertyGrammar grammar = SetPropertyGrammar.For <Address>(x => x.DistanceFromOffice); var context = new TestContext(); var address = new Address(); context.CurrentObject = address; Step step = new Step().With("DistanceFromOffice", "112.3"); grammar.Execute(step, context); address.DistanceFromOffice.ShouldEqual(112.3); }
public void sets_a_numeric_property_happy_path_with_a_default_value() { SetPropertyGrammar grammar = SetPropertyGrammar.For <Address>(x => x.DistanceFromOffice); grammar.DefaultValue = "234.1"; var context = new TestContext(); var address = new Address(); context.CurrentObject = address; var step = new Step(); grammar.Execute(step, context); address.DistanceFromOffice.ShouldEqual(234.1); }
public void try_to_set_property_when_the_current_object_is_missing() { SetPropertyGrammar grammar = SetPropertyGrammar.For <Address>(x => x.DistanceFromOffice); var context = new TestContext(); var exceptionText = string.Empty; Step step = new Step().With("DistanceFromOffice", "112.3"); try { grammar.Execute(step, context); } catch (StorytellerAssertionException ex) { exceptionText = ex.ToString(); } string message = string.Format( "Test Error: Expected an object of type '{0}' on ITestContext.CurrentObject", typeof(Address).AssemblyQualifiedName); exceptionText.ShouldContain(message); }