예제 #1
0
        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);
        }
예제 #2
0
        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());
        }
예제 #3
0
 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)));
     };
 }
예제 #4
0
        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);
        }
예제 #5
0
        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
        }
예제 #6
0
        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));
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
            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);
            }
예제 #13
0
            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);
            }
예제 #14
0
            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);
            }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
 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");
 }
예제 #19
0
            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);
            }
예제 #20
0
 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()));
 }
예제 #21
0
 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()));
 }
예제 #22
0
/*        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()));
        }
예제 #23
0
        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()));
        }
예제 #24
0
 private Dictionary <string, int> GetWorkItemStatuses()
 {
     return(_optionSetHelper.GetStringValues(ars_workitem.EntityLogicalName, NameOf.Property(() => ((ars_workitem)null).statuscode)).ToDictionary(o => o.Value, o => o.Key));
 }
예제 #25
0
        private Dictionary <int, string> GetOrderStatuses()
        {
            var options = _optionSetHelper.GetStringValues(SalesOrder.EntityLogicalName, NameOf.Property(() => ((SalesOrder)null).StatusCode));

            return(options);
        }