public void UpdatesNextSourceOnPropertyChange() { var fakeInpc = new Fake { Next = new Level { Name = "1" } }; var rootItem = new RootItem(fakeInpc); var nextName = NameOf.Property <Fake>(x => x.Next); var nextProp = typeof(Fake).GetProperty(nextName); var firstProperty = new PathProperty(null, nextProp); var first = new NotifyingPathItem(rootItem, firstProperty); var isTrueName = NameOf.Property <Level>(x => x.IsTrue); var isTrueProp = typeof(Level).GetProperty(isTrueName); var secondProperty = new PathProperty(firstProperty, isTrueProp); var second = new NotifyingPathItem(first, secondProperty); Assert.AreSame(fakeInpc.Next, second.Source); fakeInpc.Next = new Level { Name = "2" }; Assert.AreSame(fakeInpc.Next, second.Source); }
public void ThrowsOnSettingSourceToWrongType() { var propertyName = NameOf.Property <Fake>(x => x.IsTrue); var propertyInfo = typeof(Fake).GetProperty(propertyName); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); Assert.Throws <TargetException>(() => pathItem.Source = new StructLevel()); }
public UnitParts(IUnit baseUnit, IEnumerable <UnitAndPower> parts) : base(baseUnit, (up, u) => up.Parent = u, parts) { base.CollectionChanged += (sender, args) => { base.OnPropertyChanged(new PropertyChangedEventArgs(NameOf.Property(() => Expression))); base.OnPropertyChanged(new PropertyChangedEventArgs(NameOf.Property(() => BaseUnitExpression))); }; }
public void SetSourceToIncorrectTypeThrows() { var propertyName = NameOf.Property <Fake>(x => x.IsTrue); var propertyInfo = typeof(Fake).GetProperty(propertyName); var level = new Level(); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); Assert.Throws <TargetException>(() => pathItem.Source = level); }
public void SetSourceToSubtype() { var propertyName = NameOf.Property <IFake>(x => x.IsTrue); var propertyInfo = typeof(IFake).GetProperty(propertyName); var fakeInpc = new Fake(); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); pathItem.Source = fakeInpc; Assert.AreSame(fakeInpc, pathItem.Source); // Really just scheking that we don't throw here }
public void ThrowsOnNotINotifyPropertyChanged() { var propertyInfo = typeof(NotInpc).GetProperty(NameOf.Property <NotInpc>(x => x.Name)); Assert.NotNull(propertyInfo); var pathItem = new PathProperty(null, propertyInfo); var item = new NotifyingPathItem(null, pathItem); Assert.Throws <ArgumentException>(() => new NotifyingPathItem(item, pathItem)); }
public void ThrowsOnStruct() { var propertyInfo = typeof(StructLevel).GetProperty(NameOf.Property <StructLevel>(x => x.Name)); Assert.NotNull(propertyInfo); var pathItem = new PathProperty(null, propertyInfo); var item = new NotifyingPathItem(null, pathItem); Assert.Throws <ArgumentException>(() => new NotifyingPathItem(item, pathItem)); }
public void DoesNotNotifyOnNewNullSourceWhenPropGoesFromNullToNull() { var propertyName = NameOf.Property <Fake>(x => x.Name); var propertyInfo = typeof(Fake).GetProperty(propertyName); var fakeInpc = new Fake(); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); pathItem.ObservePropertyChanged().Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); pathItem.Source = null; Assert.AreEqual(0, _changes.Count); }
public void PropertyHappyPath2() { var name = NameOf.Property(() => StringProp); Assert.AreEqual("StringProp", name); name = NameOf.Property <PropertyTests>(x => x.StringProp); Assert.AreEqual("StringProp", name); name = NameOf.Property <PropertyTests, string>(x => x.StringProp); Assert.AreEqual("StringProp", name); }
public void OnNestedMethod() { var property = NameOf.Property(() => Fake.Method().Name, true); Assert.AreEqual("Name", property); property = NameOf.Property <PropertyTests>(x => Fake.Method().Name); Assert.AreEqual("Name", property); property = NameOf.Property <PropertyTests, string>(x => Fake.Method().Name); Assert.AreEqual("Name", property); }
public void NestedPropertyHappyPath() { var name = NameOf.Property(() => Fake.Next.Name, true); Assert.AreEqual("Name", name); name = NameOf.Property <PropertyTests>(x => Fake.Next.Name); Assert.AreEqual("Name", name); name = NameOf.Property <PropertyTests, string>(x => Fake.Next.Name); Assert.AreEqual("Name", name); }
public void NestedPropertyHappyPath() { var name = NameOf.Property(() => this.Fake.Next.Name, allowNestedProperty: true); Assert.AreEqual("Name", name); name = NameOf.Property <Property>(x => this.Fake.Next.Name); Assert.AreEqual("Name", name); name = NameOf.Property <Property, string?>(x => this.Fake.Next.Name); Assert.AreEqual("Name", name); }
public void PropertyHappyPath() { var name = NameOf.Property(() => this.StringProp); Assert.AreEqual(nameof(this.StringProp), name); name = NameOf.Property <Property>(x => this.StringProp); Assert.AreEqual(nameof(this.StringProp), name); name = NameOf.Property <Property, string?>(x => this.StringProp); Assert.AreEqual(nameof(this.StringProp), name); }
public void BoxedPropertyHappyPath() { var fakeInpc = new Fake(); var name = NameOf.Property(() => fakeInpc.IsTrue, allowNestedProperty: true); Assert.AreEqual("IsTrue", name); name = NameOf.Property <Fake>(x => x.IsTrue); Assert.AreEqual("IsTrue", name); name = NameOf.Property <Fake, bool>(x => x.IsTrue); Assert.AreEqual("IsTrue", name); }
public void NotifiesOnSourcePropertyChangedEvent(string eventArgsPropName) { var propertyName = NameOf.Property <Fake>(x => x.IsTrue); var propertyInfo = typeof(Fake).GetProperty(propertyName); var fakeInpc = new Fake(); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); pathItem.Source = fakeInpc; pathItem.ObservePropertyChanged().Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); fakeInpc.OnPropertyChanged(eventArgsPropName); Assert.AreEqual(1, _changes.Count); Assert.AreEqual(eventArgsPropName, _changes.Single().EventArgs.PropertyName); Assert.AreSame(fakeInpc, _changes.Single().Sender); }
public void NotifiesOnSourceChangeAffectingPropByBeingSetToNull() { var propertyName = NameOf.Property <Fake>(x => x.IsTrue); var propertyInfo = typeof(Fake).GetProperty(propertyName); var fakeInpc = new Fake(); var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); pathItem.Source = fakeInpc; pathItem.ObservePropertyChanged().Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); pathItem.Source = null; Assert.AreEqual(1, _changes.Count); Assert.AreEqual(propertyName, _changes.Single().EventArgs.PropertyName); Assert.AreSame(null, _changes.Single().Sender); }
public void NotifiesOnNewSourceWhenPropGoesFromTrueToTrue() { var propertyName = NameOf.Property <Fake>(x => x.IsTrue); var propertyInfo = typeof(Fake).GetProperty(propertyName); var fakeInpc = new Fake { IsTrue = true }; var pathItem = new NotifyingPathItem(null, new PathProperty(null, propertyInfo)); pathItem.ObservePropertyChanged().Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); pathItem.Source = fakeInpc; Assert.AreEqual(1, _changes.Count); pathItem.Source = new Fake { IsTrue = true }; Assert.AreEqual(2, _changes.Count); }
public Quantity(IUnit unit) : base(null) { _unit = unit; _unit.Quantity = this; if (_unit.Settings == null) { _unit.PropertyChanged += (_, e) => { if (e.PropertyName == NameOf.Property(() => _unit.Settings, true)) { _unit.Settings.SiUnits.CollectionChanged += (__, _e) => OnPropertyChanged("OperatorOverloads"); _unit.Settings.DerivedUnits.CollectionChanged += (__, _e) => OnPropertyChanged("OperatorOverloads"); } }; } else { _unit.Settings.SiUnits.CollectionChanged += (_, e) => OnPropertyChanged("OperatorOverloads"); _unit.Settings.DerivedUnits.CollectionChanged += (_, e) => OnPropertyChanged("OperatorOverloads"); } _unit.PropertyChanged += (_, e) => OnPropertyChanged("Interface"); }
public void ThrowsOnNestedProperty() { var exception = Assert.Throws <ArgumentException>(() => NameOf.Property(() => this.StringProp.Length)); Assert.AreEqual("Trying to get the name of a nested property: StringProp.Length", exception !.Message); }
public void ThrowsOnNestedMethod() { Assert.Throws <ArgumentException>(() => NameOf.Property(() => this.Fake.Next.Method())); Assert.Throws <ArgumentException>(() => NameOf.Property <Property>(x => x.Fake.Next.Method())); Assert.Throws <ArgumentException>(() => NameOf.Property <Property, Level?>(x => x.Fake.Next.Method())); }
public void ThrowsOnMethod() { Assert.Throws <ArgumentException>(() => NameOf.Property(() => Fake.Method())); Assert.Throws <ArgumentException>(() => NameOf.Property <PropertyTests>(x => x.Fake.Method())); Assert.Throws <ArgumentException>(() => NameOf.Property <PropertyTests, Level>(x => x.Fake.Method())); }
/* private void CreateWorkOrderEventOnNteIncrease(Incident workOrder, ars_technician technician, decimal money, decimal hours) * { * var eventTypecode = GetEventTypeValue(EventType.NteIncreaseRequest); * * var workorderevent = new ars_workorderevent * { * ars_name = string.Format("{0} - NTE Increase Request", workOrder.Title), * ars_DateTime = DateTime.UtcNow, * ars_WorkOrder = workOrder.ToEntityReference(), * ars_Technician = technician.ToEntityReference(), * ars_EventType = new OptionSetValue * { * Value = Convert.ToInt32(eventTypecode.Key) * }, * ars_Amount = new Money(money), * ars_Hours = hours * }; * * * _context.AddObject(workorderevent); * } */ private KeyValuePair <int, string> GetStatusOptionSetValue(StatusCode statusCode) { var options = _optionSetHelper.GetStringValues(Incident.EntityLogicalName, NameOf.Property(() => ((Incident)null).StatusCode)); return(options.Single(x => x.Value == statusCode.GetDescription())); }
private KeyValuePair <int, string> GetEventTypeValue(EventType statusCode) { var options = _optionSetHelper.GetStringValues(ars_workorderevent.EntityLogicalName, NameOf.Property(() => ((ars_workorderevent)null).ars_EventType)); return(options.Single(x => x.Value == statusCode.GetDescription())); }
private Dictionary <string, int> GetWorkItemStatuses() { return(_optionSetHelper.GetStringValues(ars_workitem.EntityLogicalName, NameOf.Property(() => ((ars_workitem)null).statuscode)).ToDictionary(o => o.Value, o => o.Key)); }
private Dictionary <int, string> GetOrderStatuses() { var options = _optionSetHelper.GetStringValues(SalesOrder.EntityLogicalName, NameOf.Property(() => ((SalesOrder)null).StatusCode)); return(options); }