public void AutoWrappedObjectTests() { DataContext dc = new DataContext(); AnObject unwrapped = new AnObject { PropVal = "fooProp", FieldVal = "fooField" }; GenericExpressionEvalWrapper wrapped = new GenericExpressionEvalWrapper(unwrapped); dc.RegisterDataItem("wrapped", wrapped); dc.RegisterDataItem("unwrapped", unwrapped); Assert.IsFalse(string.IsNullOrEmpty(dc.CalculateVariableValue("${wrapped.PropVal}"))); Assert.IsFalse(string.IsNullOrEmpty(dc.CalculateVariableValue("${wrapped.FieldVal}"))); Assert.AreEqual(unwrapped.PropVal, dc.CalculateVariableValue("${wrapped.PropVal}")); Assert.AreEqual(unwrapped.PropVal, dc.CalculateVariableValue("${unwrapped.PropVal}")); string val = dc.CalculateVariableValue("${unwrapped.PropVal}"); Assert.AreEqual(unwrapped.FieldVal, dc.CalculateVariableValue("${wrapped.FieldVal}")); Assert.AreEqual(unwrapped.FieldVal, dc.CalculateVariableValue("${unwrapped.FieldVal}")); }
public void should_be_able_to_set_protected_properties() { var instance = new AnObject(); Expression<Func<AnObject, string>> expression = x => x.ProtectedValue; var setter = new ValuePropertySetter(expression.GetMemberExpression(), "protected"); Assert.AreNotEqual("protected", instance.ProtectedValue); setter.ApplyValue(instance, GetState()); Assert.AreEqual("protected", instance.ProtectedValue); }
public void should_be_able_to_set_properties_backed_by_a_field() { var instance = new AnObject(); Expression<Func<AnObject, string>> expression = x => x.BackingField; var setter = new ValuePropertySetter(expression.GetMemberExpression(), "backingField"); Assert.AreNotEqual("backingField", instance.BackingField); setter.ApplyValue(instance, GetState()); Assert.AreEqual("backingField", instance.BackingField); }
public void should_be_able_to_set_inner_properties() { var instance = new AnObject { InnerObject = new AnInnerObject() }; Expression<Func<AnObject, string>> expression = x => x.InnerObject.InnerName; var setter = new ValuePropertySetter(expression.GetMemberExpression(), "anInnerObject"); Assert.AreNotEqual("anInnerObject", instance.InnerObject.InnerName); setter.ApplyValue(instance, GetState()); Assert.AreEqual("anInnerObject", instance.InnerObject.InnerName); }
public void should_be_able_to_generate_successive_string_values_with_non_numeric_starting_value() { var instance = new AnObject(); var state = new Dictionary<string, object>(); Expression<Func<AnObject, string>> expression = x => x.SuccessiveString; var setter = new SequentialPropertySetter(expression.GetMemberExpression(), "person", null); setter.ApplyValue(instance, state); Assert.AreEqual("person", instance.SuccessiveString); setter.ApplyValue(instance, state); Assert.AreEqual("person0", instance.SuccessiveString); }
public void should_be_able_to_create_an_instance_of_an_object_with_sequential_values_generated_by_a_function() { var instance = new AnObject(); var state = new Dictionary<string, object>(); Expression<Func<AnObject, int>> expression = x => x.OddNumber; var setter = new SequentialPropertySetter(expression.GetMemberExpression(), 1, previous => (int) previous + 2); setter.ApplyValue(instance, state); Assert.AreEqual(1, instance.OddNumber); setter.ApplyValue(instance, state); Assert.AreEqual(3, instance.OddNumber); }
public void should_be_able_to_create_an_instance_of_an_object_with_sequential_values() { var instance = new AnObject(); var state = new Dictionary<string, object>(); Expression<Func<AnObject, int>> expression = x => x.Position; var setter = new SequentialPropertySetter(expression.GetMemberExpression(), 0, null); setter.ApplyValue(instance, state); Assert.AreEqual(0, instance.Position); setter.ApplyValue(instance, state); Assert.AreEqual(1, instance.Position); }
public void should_be_able_to_chain_setters_to_an_arbitrary_depth() { var instance = new AnObject { InnerObject = new AnInnerObject { AnotherInnerObject = new AnotherInnerObject() } }; Expression<Func<AnObject, string>> expression = x => x.InnerObject.AnotherInnerObject.InnerName; var setter = new ValuePropertySetter(expression.GetMemberExpression(), "anotherInnerObject"); Assert.AreNotEqual("anotherInnerObject", instance.InnerObject.AnotherInnerObject.InnerName); setter.ApplyValue(instance, GetState()); Assert.AreEqual("anotherInnerObject", instance.InnerObject.AnotherInnerObject.InnerName); }
public void should_be_able_to_copy_an_existing_object() { var source = new AnObject(); var mockBlueprint = new Mock<IBlueprint<AnObject>>(); var mockPropertySetterFactory = new Mock<IPropertySetterFactory<AnObject>>(); var mockPropertySetter = new Mock<IPropertySetter>(); mockPropertySetterFactory.Setup(x => x.CreateCopyObjectSetter(source)).Returns(mockPropertySetter.Object); var builder = new Builder<AnObject>(mockBlueprint.Object, mockPropertySetterFactory.Object); builder.Copy(source).Build(); mockPropertySetter.Verify(x => x.ApplyValue( It.IsAny<AnObject>(), It.IsAny<IDictionary<string, object>>() ), Times.Once()); }
public ActionResult WithObject(AnObject id) { return(null); }
public virtual void do_work(AnObject o) { }
static void Main(string[] args) { //Assembly //Console //string name = "Karan".Reverse(); //string mrTeeTime = DateTime.Now.ToMrTTime(); //var stuff = Assembly.GetExecutingAssembly(); //var types = stuff.GetTypes(); //foreach (var type in types) //{ // Console.WriteLine($"Class {type.Name} found"); // foreach (var method in type.GetMethods()) // { // Console.WriteLine($"\tMethod {method.Name} found"); // } // Console.WriteLine(); // foreach (var field in type.GetFields()) // { // Console.WriteLine($"\tField {field.Name} found"); // } // Console.WriteLine(); // foreach (var member in type.GetMembers()) // { // Console.WriteLine($"\tMember {member.Name} found"); // } // Console.WriteLine(); //} //var type = typeof(Student).GetTypeInfo(); //foreach (var item in type.DeclaredMembers) //{ // Console.WriteLine(item); //} //var type = typeof(Student); //object t = Activator.CreateInstance(type); //Console.WriteLine((t as Student).GetCharacteristics()); //var blah = type.GetProperties(); //foreach (var property in blah) //{ // Console.WriteLine(property.GetValue(t)); // Console.WriteLine(property.Name); //} //var assembly = Assembly.GetExecutingAssembly(); //foreach (var type in assembly.GetTypes()) //{ // foreach (var member in type.GetMethods()) // { // foreach (var attribute in member.GetCustomAttributes()) // { // if (attribute.GetType() == typeof(MyCool)) // { // Console.WriteLine("found my attribute"); // var method = member.Invoke(null, null); // } // //Console.WriteLine(attribute); // } // } //} Student t = new Student("Karan"); Student s = new Student(); AnObject obj = new AnObject(); ; }
public TileSelection(GameWindow win) { InitializeComponent(); this.win = win; // Grab tiles string[] files = Directory.GetFiles("res/res/tiles", "*.png"); files.ToList().ForEach(x => { RadioButton cb = new RadioButton(); cb.Appearance = Appearance.Button; cb.Image = Bitmap.FromFile(x); cb.Size = new Size(32, 32); flow_tiles.Controls.Add(cb); string tilename = Path.GetFileNameWithoutExtension(x); cb.Tag = win.LoadTile(tilename, x); cb.CheckedChanged += new EventHandler((ob, ev) => { selectedtile = (int)cb.Tag; }); }); MapList ml = new MapList(); ml.Show(); (flow_tiles.Controls[0] as RadioButton).Checked = true; // Make the selection box Bitmap box = new Bitmap(32, 32); using (Graphics gfx = Graphics.FromImage(box)) { gfx.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.Black)), new Rectangle(0, 0, 32, 32)); gfx.DrawRectangle(new Pen(Color.Cyan), new Rectangle(0, 0, 31, 31)); } selectionbox = new AnObject(win.LoadTile("selection", box)); m = new Map(win, 30, 30); m.CheckPassable = false; m.SetCeiling(selectionbox, 0, 0); m.FillFloor(new FloorTile(0)); s = new Scene(m); win.Scene = s; // Set up the keys s.KeyDown += new EventHandler<KeyEventArgs>((o, e) => { m.SetCeiling(null, m.CameraX, m.CameraY); switch (e.KeyCode) { case Keys.Up: m.CameraY--; break; case Keys.Down: m.CameraY++; break; case Keys.Left: m.CameraX--; break; case Keys.Right: m.CameraX++; break; case Keys.Space: m.SetFloor(new FloorTile(selectedtile), m.CameraX, m.CameraY); break; //case Keys.Escape: // mnu.Visible = !mnu.Visible; // break; } m.SetCeiling(selectionbox, m.CameraX, m.CameraY); }); }
public void should_raise_an_error_if_the_generator_does_not_know_how_to_generate_sequential_values() { var instance = new AnObject(); var state = new Dictionary<string, object>(); var initialValue = new object(); Expression<Func<AnObject, object>> expression = x => x.UnsupportedSequentialValue; var setter = new SequentialPropertySetter(expression.GetMemberExpression(), initialValue, null); setter.ApplyValue(instance, state); Assert.AreEqual(initialValue, instance.UnsupportedSequentialValue); Assert.Throws<NotImplementedException>(() => setter.ApplyValue(instance, state)); }
public void should_raise_error_if_property_does_not_have_a_setter_or_backing_field() { var instance = new AnObject(); Expression<Func<AnObject, string>> expression = x => x.InvalidProperty; var setter = new ValuePropertySetter(expression.GetMemberExpression(), "invalid"); Assert.Throws<InvalidOperationException>(() => setter.ApplyValue(instance, null)); }