コード例 #1
0
        public void UpdateFromEmpty()
        {
            var view = new ObservableView <int>();

            view.Update(1, 2, 3, 4);
            Assert.IsTrue(view.ToArray().CollectionEquals(new[] { 1, 2, 3, 4 }));
        }
コード例 #2
0
        public void UpdateWithNull()
        {
            var view = new ObservableView <int>(1, 2, 3, 4);

            view.Update(null);
            Assert.IsTrue(view.ToArray().CollectionEquals(new[] { 1, 2, 3, 4 }));
        }
コード例 #3
0
    void Update()
    {
        if (GetComponent <ObservableView>())
        {
            ObservableView  observableView = GetComponent <ObservableView>();
            NetworkedPlayer owner          = EdgeManager.GetPlayer(observableView.ownerId);
            Material        playerMat      = owner.GetComponent <MeshRenderer>().material;
            GetComponent <MeshRenderer>().material = playerMat;
            if (owner.isLocalPlayer)
            {
                float h = Input.GetAxis("Horizontal") * 100 * Time.deltaTime;
                float v = Input.GetAxis("Vertical") * Time.deltaTime;
                transform.Translate(0, 0, v);
                transform.Rotate(0, h, 0);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    Observable      observable = owner.observer.observables[observableView.observableIndex];
                    NetworkedPlayer otherPlayer;

                    //Switch ownership to the other player in the room
                    if (owner.playerIndex == 0)
                    {
                        otherPlayer = EdgeManager.GetPlayer(1);
                    }
                    else
                    {
                        otherPlayer = EdgeManager.GetPlayer(0);
                    }
                    observable.ChangeOwnership(otherPlayer.playerId);
                }
            }
        }
    }
コード例 #4
0
        public void Updates()
        {
            var view = new ObservableView <int>(1, 2, 3, 4);

            view.Update(2, 3, 5);
            Assert.IsTrue(view.ToArray().CollectionEquals(new[] { 2, 3, 5 }));
            view.Update(1, 2, 6, 7);
            Assert.IsTrue(view.ToArray().CollectionEquals(new[] { 1, 2, 6, 7 }));
        }
コード例 #5
0
        public void Adds_items_upon_notification()
        {
            var subject = new ObservableView<int>(source);

            source.Add(10);
            source.Insert(0, 11);
            source.Insert(3, 12);

            subject.ToArray().ShouldBe(new[] { 11, 5, 4, 12, 3, 2, 1, 10 });
        }
コード例 #6
0
        public MainPage()
        {
            this.InitializeComponent();

            this.Malls = new ObservableView <Mall>(MallManager.GetMalls());
            this.Malls.SearchSpecification.Add(mall => mall.Title);
            this.Malls.SearchSpecification.Add(mall => mall.Subtitle);

            this.BindingContext = this;
        }
コード例 #7
0
        public void Enumeration()
        {
            var view  = new ObservableView <int>(1, 2, 3, 4, 5);
            var index = 0;

            foreach (var item in view)
            {
                index++;
                Assert.AreEqual(index, item);
            }
        }
コード例 #8
0
 private void Start()
 {
     view = GetComponent <ObservableView>();
     if (view == null)
     {
         throw new System.Exception("Can't find ObservableView component on the ball.");
     }
     if (GetComponent <Rigidbody2D>())
     {
         rb2d = GetComponent <Rigidbody2D>();
     }
 }
コード例 #9
0
        public void Filters_newly_added_items()
        {
            var subject = new ObservableView<int>(source, x => x % 2 == 0);

            source.Add(10);
            source.Add(11);
            source.Insert(0, 12);
            source.Insert(0, 13);
            source.Insert(1, 14);

            subject.ToArray().ShouldBe(new[] { 12, 14, 4, 2, 10 });
        }
コード例 #10
0
        public void View_is_readonly()
        {
            IList<int> trans = new ObservableView<int>(source);

            trans.IsReadOnly.ShouldBe(true);
            Should.Throw<InvalidOperationException>(() => trans.Add(3));
            Should.Throw<InvalidOperationException>(() => trans.Clear());
            Should.Throw<InvalidOperationException>(() => trans.Remove(3));
            Should.Throw<InvalidOperationException>(() => trans.RemoveAt(0));
            Should.Throw<InvalidOperationException>(() => trans.Insert(0, 3));
            Should.Throw<InvalidOperationException>(() => trans[0] = 3);
        }
コード例 #11
0
        public void UpdatesWithNotifications()
        {
            _console.Reset();
            var view = new ObservableView <int>(1, 2, 3, 4);

            view.CollectionChanged += (s, e) =>
            {
                Console.WriteLine($"{e.Action}:{(e.OldItems ?? e.NewItems)?.Cast<object>().ToString(",")}");
            };
            view.Update(2, 3, 5);
            Assert.AreEqual(3, _console.Lines.Count);
            Assert.AreEqual("Add:5", _console.LastText);
        }
コード例 #12
0
        public MainPage()
        {
            this.InitializeComponent();

            var listItems = MallManager.GetMalls();

            this.ListItemsView = new ObservableView <Mall>(listItems);
            this.ListItemsView.AddSearchSpecification(x => x.Title);
            this.ListItemsView.AddSearchSpecification(x => x.Subtitle);

            this.searchBox.Focus(FocusState.Keyboard);
            this.searchBox.TextChanged += this.OnSearchBoxTextChanged; // You could use SearchText data binding in XAML instead

            this.DataContext = this;
        }
コード例 #13
0
        public MainWindow()
        {
            this.InitializeComponent();

            var listItems = MallManager.GetMalls();

            this.ListItemsView = new ObservableView <Mall>(listItems);
            this.ListItemsView.AddSearchSpecification(x => x.Title);
            this.ListItemsView.AddSearchSpecification(x => x.Subtitle);

            this.searchBox.Focus();


            // In this example we use the binding Text = "{Binding ListItemsView.SearchText, Mode=TwoWay}"
            // in order to bind the searchBox.Text to the SearchText property of the ObservableView< Mall >.
            // Therefore, the following OnSearchBoxTextChanged event handler can be removed:

            // this.searchBox.TextChanged += this.OnSearchBoxTextChanged;


            this.DataContext = this;
        }
コード例 #14
0
        public void Replaces_values_upon_notification()
        {
            var subject = new ObservableView<int>(source);

            source[2] = 10;

            subject.ToArray().ShouldBe(new[] { 5, 4, 10, 2, 1 });
        }
コード例 #15
0
        public void Sorts_items()
        {
            var subject = new ObservableView<int>(source, null, Comparer<int>.Default);

            subject.ToArray().ShouldBe(new[] { 1, 2, 3, 4, 5 });
        }
コード例 #16
0
        public void Filters_items()
        {
            var subject = new ObservableView<int>(source, x => x % 2 == 0);

            subject.ToArray().ShouldBe(new[] { 4, 2 });
        }
コード例 #17
0
        public void Fetches_items_from_source()
        {
            var subject = new ObservableView<int>(source);

            subject.ShouldBe(source);
        }
コード例 #18
0
        public void Filter_ignores_removed_items_even_after_source_reset()
        {
            var obj1 = new MyObject { Value = 1 };
            var obj2 = new MyObject { Value = 2 };
            var obj3 = new MyObject { Value = 3 };
            var objects = new ObservableCollection<MyObject> { obj1, obj2, obj3 };

            var subject = new ObservableView<MyObject>(objects, x => x.Value % 2 == 1);

            objects.Clear();
            obj2.ChangeValue(5);

            subject.ShouldBeEmpty();
        }
コード例 #19
0
        public void Filter_ignores_removed_items()
        {
            var obj1 = new MyObject { Value = 1 };
            var obj2 = new MyObject { Value = 2 };
            var obj3 = new MyObject { Value = 3 };
            var objects = new ObservableCollection<MyObject> { obj1, obj2, obj3 };

            var subject = new ObservableView<MyObject>(objects, x => x.Value%2 == 1);

            objects.Remove(obj2);
            obj2.ChangeValue(5);

            subject.ToArray().ShouldBe(new[] { obj1, obj3 });
        }
コード例 #20
0
        public void Filter_respects_item_changes()
        {
            var obj = new MyObject { Value = 0 };
            var obj2 = new MyObject { Value = 2 };
            var obj3 = new MyObject { Value = 3 };
            var objects = new ObservableCollection<MyObject> { obj2, obj, obj3, obj };

            var subject = new ObservableView<MyObject>(objects, x => x.Value > 0);

            obj.ChangeValue(10);
            obj2.ChangeValue(-1);

            subject.ToArray().ShouldBe(new[] { obj, obj3, obj });
        }
コード例 #21
0
        public void New_items_preserve_sort_order()
        {
            var subject = new ObservableView<int>(source, null, Comparer<int>.Default);

            source.Add(-2);
            source.Add(3);
            source.Add(3);
            source.Add(10);

            subject.ToArray().ShouldBe(new[] { -2, 1, 2, 3, 3, 3, 4, 5, 10 });
        }
コード例 #22
0
        public void Removes_values_upon_notification()
        {
            var subject = new ObservableView<int>(source);

            source.Remove(4);
            source.RemoveAt(1);

            subject.ToArray().ShouldBe(new[] { 5, 2, 1 });
        }
コード例 #23
0
        public void Handles_source_collection_reset()
        {
            var subject = new ObservableView<int>(source);

            source.Add(3);
            source.Add(5);
            source.Clear();
            source.Add(2);
            source.Add(4);

            subject.ToArray().ShouldBe(new[] { 2, 4 });
        }