public void TestClassWithChildren() { var c = new ClassWithChildren(); Assert.Equal(0, c.SumValue); var a = new ClassWithProperty { Value = 11 }; c.Children.Add(a); Assert.Equal(11, c.SumValue); var b = new ClassWithProperty { Value = 11 }; c.Children.Add(b); Assert.Equal(22, c.SumValue); a.Value = 21; Assert.Equal(32, c.SumValue); b.Value = 21; Assert.Equal(42, c.SumValue); }
private static void HandleAmbigurityBetweenPropertyNameAndType() { var c = new ClassWithProperty(); var s = c.Run("A", "B"); Assert("AB", s); }
public void SetPropertyByNameInManagedObject() { var classWithProperty = new ClassWithProperty(); _context.SetParameter("myObject", classWithProperty); _context.Run("myObject.MyProperty = 'hello'"); classWithProperty.MyProperty.Should().Be("hello"); }
public void SetPropertyByNameInManagedObject() { var classWithProperty = new ClassWithProperty(); _context.SetParameter("myObject", classWithProperty); _context.Run("myObject.MyProperty = 'hello'"); Assert.That(classWithProperty.MyProperty, Is.EqualTo("hello")); }
public void GivenAnInitialStateToPerformCommandsOn() { this.testObject = new ClassWithProperty { MyProperty = 1 }; Logger.Log("Initial state: " + this.testObject.MyProperty); this.commandManager = new ReversibleCommandManager(); }
public void Test3() { string json = "{\"Array1\":\"A1 2D,F6\"}"; var options = new JsonSerializerOptions(); options.Converters.Add(new ByteArrayHexTextJsonConverter()); ClassWithProperty obj = JsonSerializer.Deserialize <ClassWithProperty>(json, options); Assert.Equal(0xA1, obj.Array1[0]); Assert.Equal(0x2D, obj.Array1[1]); Assert.Equal(0xF6, obj.Array1[2]); }
public void Test4() { string json = "{\"Array1\":\"A1 2D,O6\"}"; var options = new JsonSerializerOptions(); options.Converters.Add(new ByteArrayHexTextJsonConverter()); try { ClassWithProperty obj = JsonSerializer.Deserialize <ClassWithProperty>(json, options); } catch (System.FormatException ex) { Assert.Equal("Could not find any recognizable digits.", ex.Message); } }
public void Test() { var c = new ClassWithCollection(); var countItem = 0; var countCount = 0; var countOthers = 0; if (c.Children is INotifyPropertyChanged p) { p.PropertyChanged += (s, a) => { switch (a.PropertyName) { case "Item": countItem++; break; case "Count": countCount++; break; default: countOthers++; break; } }; } var child1 = new ClassWithProperty { Value = 25 }; c.Children.Add(child1); var child2 = new ClassWithProperty { Value = 17 }; c.Children.Add(child2); Assert.Equal(c.Children.Sum(i => i.Value), c.Sum); Assert.Equal(0, countOthers); //Assert.Equal(2, countCount); //Assert.Equal(2,countItem); child1.Value = 8; child2.Value = 2; Assert.Equal(c.Children.Sum(i => i.Value), c.Sum); }
private static void TestClassWithProperties() { var c = new ClassWithProperty(); Assert(0, c.IntProperty); c.AutoProperty = "A"; Assert("A", c.AutoProperty); Assert("GetValue", c.PropertyWithGet); c.PropertyWithGetAndSet = "B"; Assert(Output, "B"); Output = "C"; Assert("C", c.PropertyWithGetAndSet); c.PropertyWithSet = "D"; Assert(Output, "D"); }
public static void Main() { ClassWithProperty test = new ClassWithProperty(); Console.WriteLine("The Caption property: {0}", test.Caption); Console.WriteLine("----------"); // Get the type and PropertyInfo. Type t = Type.GetType("ClassWithProperty"); PropertyInfo propInfo = t.GetProperty("Caption"); // Get the public GetAccessors method. MethodInfo[] methInfos = propInfo.GetAccessors(); Console.WriteLine("There are {0} accessors.", methInfos.Length); for (int ctr = 0; ctr < methInfos.Length; ctr++) { MethodInfo m = methInfos[ctr]; Console.WriteLine("Accessor #{0}:", ctr + 1); Console.WriteLine(" Name: {0}", m.Name); Console.WriteLine(" Visibility: {0}", GetVisibility(m)); Console.Write(" Property Type: "); // Determine if this is the property getter or setter. if (m.ReturnType == typeof(void)) { Console.WriteLine("Setter"); Console.WriteLine(" Setting the property value."); // Set the value of the property. m.Invoke(test, new object[] { "The Modified Caption" }); } else { Console.WriteLine("Getter"); // Get the value of the property. Console.WriteLine(" Property Value: {0}", m.Invoke(test, new object[] {})); } } Console.WriteLine("----------"); Console.WriteLine("The Caption property: {0}", test.Caption); }
public void TestNotifyCount() { var count = 0; var fail = 0; var test = 0; var c = new ClassWithProperty(); c.PropertyChanged += (sender, args) => { switch (args.PropertyName) { case "Value": count++; break; default: fail++; break; } Assert.Equal(test, c.Value); }; test = 42; c.Value = test; Assert.Equal(1, count); test = 43; c.Value = test; Assert.Equal(2, count); test++; c.Value++; Assert.Equal(3, count); Assert.Equal(0, fail); }