示例#1
0
        protected virtual void Start()
        {
            _progress = new NotifyingObject<int>(0);
            _command = new NotifyingObject<ICommand>(new DelegateCommand(() =>
            {
                Ticks++;
                Progress = 0;
            }));

            var resourceManager = GetComponentInParent<ResourceManager>();

            var cooldownButton = GetComponentInChildren<CooldownButton>();
            cooldownButton.EnabledColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledColorProperty);
            cooldownButton.DisabledColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledColorProperty);
            cooldownButton.EnabledTextColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledTextColorProperty);
            cooldownButton.DisabledTextColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledTextColorProperty);
            cooldownButton.EnabledProgressBarColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledProgressBarColorProperty);
            cooldownButton.DisabledProgessBarColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledProgressBarColorProperty);
            cooldownButton.TextProperty.SetValue(Text);
            cooldownButton.ProgressProperty.Bind(BindingType.TwoWay, _progress);
            cooldownButton.CommandProperty.Bind(BindingType.OneWay, _command);
        }
        public void Ctor_RefernceType_Initialized()
        {
            var value   = new List();
            var subject = new NotifyingObject <List>(value);

            Assert.AreEqual(value, subject.GetValue());
        }
        public void Ctor_ValueType_Initialized()
        {
            const int value   = 42;
            var       subject = new NotifyingObject <int>(value);

            Assert.AreEqual(value, subject.GetValue());
        }
        public void RegisterNotifyingObject(NotifyingObject obj)
        {
            Contract.Requires<ArgumentNullException>(obj != null);

            RegisterNotifyingObject((INotifyPropertyChanging)obj);
            RegisterNotifyingObject((INotifyPropertyChanged)obj);
        }
示例#5
0
        protected virtual void Start()
        {
            _progress = new NotifyingObject <int>(0);
            _command  = new NotifyingObject <ICommand>(new DelegateCommand(() =>
            {
                Ticks++;
                Progress = 0;
            }));

            var resourceManager = GetComponentInParent <ResourceManager>();

            var cooldownButton = GetComponentInChildren <CooldownButton>();

            cooldownButton.EnabledColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledColorProperty);
            cooldownButton.DisabledColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledColorProperty);
            cooldownButton.EnabledTextColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledTextColorProperty);
            cooldownButton.DisabledTextColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledTextColorProperty);
            cooldownButton.EnabledProgressBarColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonEnabledProgressBarColorProperty);
            cooldownButton.DisabledProgessBarColorProperty.Bind(
                BindingType.OneWay,
                resourceManager.ButtonDisabledProgressBarColorProperty);
            cooldownButton.TextProperty.SetValue(Text);
            cooldownButton.ProgressProperty.Bind(BindingType.TwoWay, _progress);
            cooldownButton.CommandProperty.Bind(BindingType.OneWay, _command);
        }
示例#6
0
        public EnemyViewModel()
        {
            TextProperty     = new NotifyingObject <string>(string.Empty);
            PositionProperty = new NotifyingObject <Vector3>();
            SizeProperty     = new NotifyingObject <Vector2>();

            SizeProperty.PropertyChanged += SizePropertyOnPropertyChanged;
            _stringFormatter              = new StringFormatter(CultureInfo.CurrentCulture);
        }
 protected TowerModel(
     string id,
     Sprite baseSprite,
     TLevel[] levels)
 {
     _id           = id;
     _baseSprite   = baseSprite;
     _levels       = levels;
     LevelProperty = new NotifyingObject <int>();
 }
        public CooldownButtonViewModel()
        {
            ProgressBarAnchorMinProperty = new NotifyingObject<Vector2>();
            ProgressBarAnchorMaxProperty = new NotifyingObject<Vector2>();
            ProgressBarColorPoperty = new NotifyingObject<Color>();
            ButtonColorProperty = new NotifyingObject<Color>();
            ButtonTextProperty = new NotifyingObject<string>();
            ButtonTextColorProperty = new NotifyingObject<Color>();
            CommandProperty = new NotifyingObject<ICommand>();

            _cooldownButtonCommand = new DelegateCommand(CommandExecute, CommandCanExecute);
            CommandProperty.SetValue(_cooldownButtonCommand);
        }
示例#9
0
        public CooldownButtonViewModel()
        {
            ProgressBarAnchorMinProperty = new NotifyingObject <Vector2>();
            ProgressBarAnchorMaxProperty = new NotifyingObject <Vector2>();
            ProgressBarColorPoperty      = new NotifyingObject <Color>();
            ButtonColorProperty          = new NotifyingObject <Color>();
            ButtonTextProperty           = new NotifyingObject <string>();
            ButtonTextColorProperty      = new NotifyingObject <Color>();
            CommandProperty = new NotifyingObject <ICommand>();

            _cooldownButtonCommand = new DelegateCommand(CommandExecute, CommandCanExecute);
            CommandProperty.SetValue(_cooldownButtonCommand);
        }
示例#10
0
		public void CanSubscribeMockDelegateAsEventListener()
		{
			var notifyingObject = new NotifyingObject();
			var mockListener = new Mock<PropertyChangedEventHandler>();
			notifyingObject.PropertyChanged += mockListener.Object;

			notifyingObject.Value = 5;

			// That should have caused one event to have been fired.
			mockListener
				.Verify(l => l(notifyingObject,
							   It.Is<PropertyChangedEventArgs>(e => e.PropertyName == "Value")),
						Times.Once());
		}
示例#11
0
        public void CanSubscribeMockDelegateAsEventListener()
        {
            var notifyingObject = new NotifyingObject();
            var mockListener    = new Mock <PropertyChangedEventHandler>();

            notifyingObject.PropertyChanged += mockListener.Object;

            notifyingObject.Value = 5;

            // That should have caused one event to have been fired.
            mockListener
            .Verify(l => l(notifyingObject,
                           It.Is <PropertyChangedEventArgs>(e => e.PropertyName == "Value")),
                    Times.Once());
        }
        public void SetValue_ReferenceType_PropertyChangedRaised()
        {
            var newValue = new List();
            var eventRaised = false;
            var subject = new NotifyingObject<List>();
            subject.PropertyChanged += (sender, args) =>
            {
                Assert.IsFalse(eventRaised);
                Assert.IsNull(args.OldValue);
                Assert.AreEqual(newValue, args.NewValue);
                eventRaised = true;
            };

            subject.SetValue(newValue);

            Assert.IsTrue(eventRaised);
        }
示例#13
0
        public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name()
        {
            // Arrange
            var notifyingObject = new NotifyingObject();

            var mockHandler = new Mock <PropertyChangedEventHandler>();

            mockHandler.Setup(_ => _(It.IsAny <object>(), It.IsAny <PropertyChangedEventArgs>()));
            notifyingObject.PropertyChanged += mockHandler.Object;


            // Act
            notifyingObject.ValueWithRandomAdded = 42;


            // Assert
            mockHandler.Verify(_ => _(notifyingObject, It.Is <PropertyChangedEventArgs>(o => o.PropertyName == "ValueWithRandomAdded")), Times.Once());
        }
示例#14
0
        public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name()
        {
            // Arrange
            var notifyingObject = new NotifyingObject();

            var mockHandler = Substitute.For <PropertyChangedEventHandler>();

            mockHandler(Arg.Any <object>(), Arg.Any <PropertyChangedEventArgs>());
            notifyingObject.PropertyChanged += mockHandler;


            // Act
            notifyingObject.ValueWithRandomAdded = 42;


            // Assert
            mockHandler.Received(1)(notifyingObject, Arg.Is <PropertyChangedEventArgs>(o => o.PropertyName == "ValueWithRandomAdded"));
        }
        public void SetValue_ValueType_PropertyChangedRaised()
        {
            const int oldValue = default(int);
            const int newValue = 64;
            var eventRaised = false;
            var subject = new NotifyingObject<int>();
            subject.PropertyChanged += (sender, args) =>
            {
                Assert.IsFalse(eventRaised);
                Assert.AreEqual(oldValue, args.OldValue);
                Assert.AreEqual(newValue, args.NewValue);
                eventRaised = true;
            };

            subject.SetValue(newValue);

            Assert.IsTrue(eventRaised);
        }
示例#16
0
        public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name()
        {
            // Arrange
            var notifyingObject = new NotifyingObject();

            var mockHandler = MockRepository.GenerateStub <PropertyChangedEventHandler>();

            mockHandler.Stub(_ => _(Arg <object> .Is.Anything, Arg <PropertyChangedEventArgs> .Is.Anything));
            notifyingObject.PropertyChanged += mockHandler;


            // Act
            notifyingObject.ValueWithRandomAdded = 42;


            // Assert
            mockHandler.AssertWasCalled(_ => _(Arg <object> .Is.Same(notifyingObject), Arg <PropertyChangedEventArgs> .Matches(o => o.PropertyName == "ValueWithRandomAdded")), options => options.Repeat.Once());
        }
        public void SetValue_ReferenceType_PropertyChangedRaised()
        {
            var newValue    = new List();
            var eventRaised = false;
            var subject     = new NotifyingObject <List>();

            subject.PropertyChanged += (sender, args) =>
            {
                Assert.IsFalse(eventRaised);
                Assert.IsNull(args.OldValue);
                Assert.AreEqual(newValue, args.NewValue);
                eventRaised = true;
            };

            subject.SetValue(newValue);

            Assert.IsTrue(eventRaised);
        }
示例#18
0
        public void ValueWithRandomAdded_should_raise_PropertyChanged_event_with_its_name()
        {
            // Arrange
            var notifyingObject = new NotifyingObject();

            var mockHandler = A.Fake <PropertyChangedEventHandler>();

            A.CallTo(() => mockHandler(A <object> ._, A <PropertyChangedEventArgs> ._));
            notifyingObject.PropertyChanged += mockHandler;


            // Act
            notifyingObject.ValueWithRandomAdded = 42;


            // Assert
            A.CallTo(() => mockHandler(notifyingObject, A <PropertyChangedEventArgs> .That.Matches(_ => _.PropertyName == "ValueWithRandomAdded"))).MustHaveHappened();
        }
        public void SetValue_ValueType_PropertyChangedRaised()
        {
            const int oldValue    = default(int);
            const int newValue    = 64;
            var       eventRaised = false;
            var       subject     = new NotifyingObject <int>();

            subject.PropertyChanged += (sender, args) =>
            {
                Assert.IsFalse(eventRaised);
                Assert.AreEqual(oldValue, args.OldValue);
                Assert.AreEqual(newValue, args.NewValue);
                eventRaised = true;
            };

            subject.SetValue(newValue);

            Assert.IsTrue(eventRaised);
        }
示例#20
0
        public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var notifyingObject = new NotifyingObject();

                var mockNext = MockRepository.GenerateStub <IndirectionFunc <Random, int> >();
                mockNext.Stub(_ => _(Arg <Random> .Is.Anything)).Return(10);
                PRandom.Next().Body = mockNext;


                // Act
                notifyingObject.ValueWithRandomAdded = 32;
                var actual = notifyingObject.ValueWithRandomAdded;


                // Assert
                mockNext.AssertWasCalled(_ => _(Arg <Random> .Is.Anything), options => options.Repeat.Once());
                Assert.AreEqual(42, actual);
            }
        }
示例#21
0
        public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var notifyingObject = new NotifyingObject();

                var mockNext = A.Fake <IndirectionFunc <Random, int> >();
                A.CallTo(() => mockNext(A <Random> ._)).Returns(10);
                PRandom.Next().Body = mockNext;


                // Act
                notifyingObject.ValueWithRandomAdded = 32;
                var actual = notifyingObject.ValueWithRandomAdded;


                // Assert
                A.CallTo(() => mockNext(A <Random> ._)).MustHaveHappened();
                Assert.AreEqual(42, actual);
            }
        }
示例#22
0
        public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var notifyingObject = new NotifyingObject();

                var mockNext = Substitute.For <IndirectionFunc <Random, int> >();
                mockNext(Arg.Any <Random>()).Returns(10);
                PRandom.Next().Body = mockNext;


                // Act
                notifyingObject.ValueWithRandomAdded = 32;
                var actual = notifyingObject.ValueWithRandomAdded;


                // Assert
                mockNext.Received(1)(Arg.Any <Random>());
                Assert.AreEqual(42, actual);
            }
        }
示例#23
0
        public void ValueWithRandomAdded_should_hold_passed_value_plus_random_value()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var notifyingObject = new NotifyingObject();

                var mockNext = new Mock <IndirectionFunc <Random, int> >();
                mockNext.Setup(_ => _(It.IsAny <Random>())).Returns(10);
                PRandom.Next().Body = mockNext.Object;


                // Act
                notifyingObject.ValueWithRandomAdded = 32;
                var actual = notifyingObject.ValueWithRandomAdded;


                // Assert
                mockNext.Verify(_ => _(It.IsAny <Random>()), Times.Once());
                Assert.AreEqual(42, actual);
            }
        }
示例#24
0
        public ViewModel()
        {
            PositionProperty          = new NotifyingObject <Vector3>();
            UpButtonTextProperty      = new NotifyingObject <string>();
            DownButtonTextProperty    = new NotifyingObject <string>();
            UpThresholdProperty       = new NotifyingObject <float>();
            DownThresholdProperty     = new NotifyingObject <float>();
            UpButtonCommandProperty   = new NotifyingObject <ICommand>();
            DownButtonCommandProperty = new NotifyingObject <ICommand>();
            DownButtonTextProperty    = new NotifyingObject <string>();
            UpAvailableProperty       = new NotifyingObject <bool>();
            DownAvailableProperty     = new NotifyingObject <bool>();

            PositionProperty.PropertyChanged += (o, e) =>
            {
                SetUpAvailable();
                SetDownAvailable();
            };
            SetUpAvailable();
            SetDownAvailable();
            UpAvailableProperty.PropertyChanged   += (o, e) => SetUpAvailable();
            DownAvailableProperty.PropertyChanged += (o, e) => SetDownAvailable();

            var upButtonCommand = new DelegateCommand(
                () => Position += _upDownVector,
                () => UpAvailable);

            PositionProperty.PropertyChanged    += (o, e) => upButtonCommand.RaiseCanExecuteChanged();
            UpThresholdProperty.PropertyChanged += (o, e) => upButtonCommand.RaiseCanExecuteChanged();
            UpButtonCommandProperty.SetValue(upButtonCommand);

            var downButtonCommand = new DelegateCommand(
                () => Position -= _upDownVector,
                () => DownAvailable);

            PositionProperty.PropertyChanged      += (o, e) => downButtonCommand.RaiseCanExecuteChanged();
            DownThresholdProperty.PropertyChanged += (o, e) => downButtonCommand.RaiseCanExecuteChanged();
            DownButtonCommandProperty.SetValue(downButtonCommand);
        }
        public void ParamlessCtor_RefernceType_Null()
        {
            var subject = new NotifyingObject <List>();

            Assert.IsNull(subject.GetValue());
        }
示例#26
0
 public Enemy()
 {
     HealthProperty   = new NotifyingObject <float>();
     PositionProperty = new NotifyingObject <Vector3>();
     _state           = State.Undefinded;
 }
        public void ParamlessCtor_ValueType_DefaultValue()
        {
            var subject = new NotifyingObject <TimeSpan>();

            Assert.AreEqual(default(TimeSpan), subject.GetValue());
        }
 public TowerViewModel()
 {
     VisibleProperty     = new NotifyingObject <bool>();
     TowerSpriteProperty = new NotifyingObject <Sprite>();
     RangeProperty       = new NotifyingObject <float>();
 }
 public void ParamlessCtor_ValueType_DefaultValue()
 {
     var subject = new NotifyingObject<TimeSpan>();
     Assert.AreEqual(default(TimeSpan), subject.GetValue());
 }
 public void ParamlessCtor_RefernceType_Null()
 {
     var subject = new NotifyingObject<List>();
     Assert.IsNull(subject.GetValue());
 }
 public void Ctor_ValueType_Initialized()
 {
     const int value = 42;
     var subject = new NotifyingObject<int>(value);
     Assert.AreEqual(value, subject.GetValue());
 }
 public void Ctor_RefernceType_Initialized()
 {
     var value = new List();
     var subject = new NotifyingObject<List>(value);
     Assert.AreEqual(value, subject.GetValue());
 }