Пример #1
0
        private void HelloResponse(HelloMessage message)
        {
            //Elaborates the Hello Message
            TempBuilding b = new TempBuilding();

            #region setting fields
            b.Address    = message.Address;
            b.Admin      = message.Admin;
            b.EnBought   = 0;
            b.EnSold     = 0;
            b.EnPeak     = message.EnPeak;
            b.EnPrice    = message.EnPrice;
            b.EnProduced = message.EnProduced;
            b.EnType     = message.EnType;
            b.Name       = message.header.Sender;
            b.status     = message.Status;
            b.iconPath   = b.status == PeerStatus.Producer ? @"/WPF_Resolver;component/img/producer.png" : @"/WPF_Resolver;component/img/consumer.png";
            #endregion

            lock (_lLock)
                _buildings.Add(b);

            XMLLogger.WriteLocalActivity("New Peer: " + b.Name + " is up!");

            //Be polite! Send an HelloResponse
            Connector.channel.HelloResponse(MessageFactory.createHelloResponseMessage("@All", Tools.getResolverName(), Tools.getResolverName()));
        }
        public void LoginModeTracksAvailableConnections()
        {
            var connectionManager    = Substitute.For <IConnectionManager>();
            var connections          = new ObservableCollectionEx <IConnection>();
            var gitHubLogin          = Substitute.For <ILoginToGitHubViewModel>();
            var enterpriseLogin      = Substitute.For <ILoginToGitHubForEnterpriseViewModel>();
            var gitHubConnection     = Substitute.For <IConnection>();
            var enterpriseConnection = Substitute.For <IConnection>();

            connectionManager.Connections.Returns(connections);
            gitHubConnection.HostAddress.Returns(HostAddress.GitHubDotComHostAddress);
            enterpriseConnection.HostAddress.Returns(HostAddress.Create("https://enterprise.url"));
            gitHubConnection.IsLoggedIn.Returns(true);
            enterpriseConnection.IsLoggedIn.Returns(true);

            var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin);

            Assert.Equal(LoginMode.DotComOrEnterprise, loginViewModel.LoginMode);

            connections.Add(enterpriseConnection);
            Assert.Equal(LoginMode.DotComOnly, loginViewModel.LoginMode);

            connections.Add(gitHubConnection);
            Assert.Equal(LoginMode.None, loginViewModel.LoginMode);

            connections.RemoveAt(0);
            Assert.Equal(LoginMode.EnterpriseOnly, loginViewModel.LoginMode);
        }
Пример #3
0
        /// <summary>
        ///A test for DisableNotifications
        ///</summary>
        public void DisabledNotificationTestHelper <T>() where T : new()
        {
            ObservableCollectionEx <T> target = CreateTargetHelper <T>();

            T item0 = new T();
            T item1 = new T();
            T item2 = new T();
            T item3 = new T();
            T item4 = new T();

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();

            using (ObservableCollectionEx <T> iTarget = target.DisableNotifications())
            {
                iTarget.Add(item0);
                iTarget.Add(item1);
                iTarget.Add(item2);
                iTarget.Add(item3);
                iTarget.Add(item4);

                Assert.IsTrue(5 == target.Count, "Count is incorrect");
                Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
                Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
            }

            Assert.IsTrue(5 == target.Count, "Count is incorrect");
            Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
        }
Пример #4
0
        private void UpdateInventoryItems()
        {
            List <IInventoryItem> wieldedItems  = player.WieldedItems;
            List <IInventoryItem> itemsToRemove = new List <IInventoryItem>();

            foreach (IInventoryItem item in inventory)
            {
                if (wieldedItems.Contains(item))
                {
                    itemsToRemove.Add(item);
                }
            }

            foreach (IInventoryItem item in itemsToRemove)
            {
                inventory.Remove(item);
            }

            foreach (IInventoryItem item in player.Inventory.Where(x => !wieldedItems.Contains(x)))
            {
                if (!inventory.Contains(item))
                {
                    inventory.Add(item);
                }
            }
        }
Пример #5
0
        public void LoginModeIgnoresAvailableConnections()
        {
            // We always want to option to log-in to GitHub or GitHub Enterprise

            var connectionManager    = Substitute.For <IConnectionManager>();
            var connections          = new ObservableCollectionEx <IConnection>();
            var gitHubLogin          = Substitute.For <ILoginToGitHubViewModel>();
            var enterpriseLogin      = Substitute.For <ILoginToGitHubForEnterpriseViewModel>();
            var gitHubConnection     = Substitute.For <IConnection>();
            var enterpriseConnection = Substitute.For <IConnection>();

            connectionManager.Connections.Returns(connections);
            gitHubConnection.HostAddress.Returns(HostAddress.GitHubDotComHostAddress);
            enterpriseConnection.HostAddress.Returns(HostAddress.Create("https://enterprise.url"));
            gitHubConnection.IsLoggedIn.Returns(true);
            enterpriseConnection.IsLoggedIn.Returns(true);

            var loginViewModel = new LoginCredentialsViewModel(connectionManager, gitHubLogin, enterpriseLogin);

            Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

            connections.Add(enterpriseConnection);
            Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

            connections.Add(gitHubConnection);
            Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

            connections.RemoveAt(0);
            Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));
        }
Пример #6
0
        private void btnAddDescription_Click(object sender, RoutedEventArgs e)
        {
            description Description = new description()
            {
                name       = "Третьи соревнования",
                start_date = new DateTime(2016, 11, 25)
            };

            Thread th = new Thread(() =>
            {
                descriptionCollection.Add(Description);
                if (!ChangesSavedSuccessfully)
                {
                    descriptionCollection.CollectionChanged -= descriptionCollection_CollectionChanged;
                    descriptionCollection.Remove(Description);
                    descriptionCollection.CollectionChanged += descriptionCollection_CollectionChanged;
                }
            })
            {
                IsBackground = true
            };

            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }
        public void ReEntranceTestHelper <T>() where T : new()
        {
            ObservableCollectionEx <T> target = new ObservableCollectionEx <T>();

            target.Add(new T());
            target.Add(new T());

            (target as INotifyCollectionChanged).CollectionChanged += ReEntranceHandler1TestHelper;
            target.Add(new T());
        }
        void MoveTestHelper()
        {
            ObservableCollectionEx <GenericParameterHelper> target = CreateTargetHelper <GenericParameterHelper>();

            GenericParameterHelper item0 = new GenericParameterHelper(0);
            GenericParameterHelper item1 = new GenericParameterHelper(1);
            GenericParameterHelper item2 = new GenericParameterHelper(2);
            GenericParameterHelper item3 = new GenericParameterHelper(3);
            GenericParameterHelper item4 = new GenericParameterHelper(4);

            target.Add(item0);
            target.Add(item1);
            target.Add(item2);
            target.Add(item3);
            target.Add(item4);

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();

            Assert.IsTrue(1 == target.IndexOf(item1));
            target.Move(1, 3);
            Assert.IsTrue(3 == target.IndexOf(item1));

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (var iDisabled = target.DisableNotifications())
            {
                iDisabled.Move(3, 1);
                iDisabled.Move(1, 3);
                iDisabled.Move(3, 1);
                iDisabled.Move(1, 3);
                iDisabled.Move(3, 1);
            }
            Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (var iDelayed = target.DelayNotifications())
            {
                iDelayed.Move(1, 3);
                try
                {
                    iDelayed.Move(3, 1);
                    Assert.Fail("Only one move allowed");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(InvalidOperationException));
                }
            }
            Assert.IsTrue(1 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
        }
Пример #9
0
        public ListViewModel()
        {
            DataCollection = new ObservableCollectionEx<CmdArgItem>();
            DataCollectionView = CollectionViewSource.GetDefaultView(DataCollection);

            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                DataCollection.Add(new CmdArgItem() { Enabled = true, Command = @"C:\Users\Markus\Desktop\" });
                DataCollection.Add(new CmdArgItem() { Enabled = false, Command = "Hello World" });
                DataCollection.Add(new CmdArgItem() { Enabled = true, Command = "A very long commandline to test very long commandlines to see how very long commandlines work in our UI." });
            }
        }
Пример #10
0
        public void RunningNonAuthFlowWhenLoggedInRunsNonAuthFlow()

        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            cm.GetLoadedConnections().Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider));

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Clone);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryCloneViewModel> >(uc);
                        TriggerCancel(data.View.ViewModel);
                        break;
                    }
                });

                uiController.Start();
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
Пример #11
0
        public void FlowWithConnection()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            var connection = SetupConnection(provider);

            // simulate being logged in
            cons.Add(connection);

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var count = 0;
                var flow  = uiController.Configure(UIControllerFlow.Publish, connection);
                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IRepositoryPublishViewModel> >(uc);
                        ((IGitHubServiceProvider)provider).Received().AddService(uiController, connection);
                        TriggerDone(data.View.ViewModel);
                        break;
                    }
                });

                uiController.Start();
                Assert.Equal(1, count);
                Assert.True(uiController.IsStopped);
            }
        }
Пример #12
0
        private void MachineOnTaskActionChange(object obj)
        {
            var collectionTaskAction = ((IList)obj).Cast <OctopusLib.TaskAction>();
            List <OctopusLib.TaskAction> selectedTaskActions = new List <OctopusLib.TaskAction>(collectionTaskAction);

            if (selectedTaskActions != null)
            {
                ObservableCollectionEx <OctopusLib.Machine> selectedMachines = new ObservableCollectionEx <Machine>();
                if (this.SelectedTaskActionRow.Machine != null)
                {
                    selectedMachines.Add(this.SelectedTaskActionRow.Machine);
                }

                MachineSelect rmsWindow = new MachineSelect()
                {
                    Title                 = "Task Machines selection Dialog",
                    ShowInTaskbar         = false,               // don't show the dialog on the taskbar
                    Topmost               = true,                // ensure we're Always On Top
                    ResizeMode            = ResizeMode.NoResize, // remove excess caption bar buttons
                    Owner                 = Application.Current.MainWindow,
                    WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner,
                    SelectedMachines      = selectedMachines,
                    IsAllowSelectAll      = false,
                };
                rmsWindow.BindingAvailableMachineList();
                rmsWindow.ShowDialog();

                if (rmsWindow.SelectedMachines != null)
                {
                    this.SelectedTaskActionRow.Machine = rmsWindow.SelectedMachines.Count == 0 ? null : rmsWindow.SelectedMachines[0];
                }
            }
        }
        public void ObsCollExWPFTest()
        {
            ObservableCollectionEx <string> target = new ObservableCollectionEx <string>();

            target.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(target_CollectionChanged);
            ListBox listBox = new ListBox();

            listBox.Name        = "testListBox";
            listBox.ItemsSource = target;

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem(new WaitCallback((x) =>
            {
                target.Add("Hank Schrader");
                resetEvent.Set();
            }));
            resetEvent.WaitOne(1000);

            Assert.AreEqual(1, listBox.Items.Count);
            Assert.AreEqual("Hank Schrader", listBox.Items[0] as string);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, _Args.Action);
            Assert.AreEqual(1, _Args.NewItems.Count);
            Assert.AreEqual("Hank Schrader", _Args.NewItems[0]);
        }
Пример #14
0
        private static void TestCase3()
        {
            ObservableCollectionEx <Person> coll = new ObservableCollectionEx <Person>();

            coll.CollectionChanged += OnCollectionChanged2;

            var eric    = new Person("Eric");
            var charles = new Person("Charles");

            coll.Add(eric);
            coll.Add(charles);

            coll.Remove(eric);

            coll.Clear(); // Will Charles say 'goodbye' to us?
        }
Пример #15
0
        public void Update()
        {
            _header.Text = this.Value.Signature;

            foreach (var item in _listViewItemCollection.OfType <BoxTreeViewItem>().ToArray())
            {
                if (!_value.Boxes.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Boxes)
            {
                if (!_listViewItemCollection.OfType <BoxTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new BoxTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
Пример #16
0
        public void Update()
        {
            _header.Text = string.Format("{0} ({1})", _value.SearchItem.Name, _hit);

            base.IsExpanded = this.Value.IsExpanded;

            foreach (var item in _listViewItemCollection.OfType <SearchTreeViewItem>().ToArray())
            {
                if (!_value.Children.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Children)
            {
                if (!_listViewItemCollection.OfType <SearchTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new SearchTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
Пример #17
0
        private async void RequestTypes()
        {
            if (Property == null)
            {
                return;
            }

            if (Editors.Count == 0)
            {
                SuggestedTypes  = new ObservableCollectionEx <ITypeInfo> ();
                AssignableTypes = new AsyncValue <IReadOnlyDictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > > (
                    Task.FromResult <IReadOnlyDictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > > (
                        new Dictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > ()));
                SelectedType = null;
                return;
            }

            var types = Editors.GetCommonAssignableTypes(Property, childTypes: true);
            var assignableTypesTask = types.ContinueWith(t => t.Result.GetTypeTree(), TaskScheduler.Default);

            AssignableTypes = new AsyncValue <IReadOnlyDictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > > (assignableTypesTask);

            var results   = await types;
            var suggested = new ObservableCollectionEx <ITypeInfo> (results.SuggestedTypes);

            if (results.AssignableTypes.Count > suggested.Count)
            {
                suggested.Add(OtherType);
            }

            SuggestedTypes = suggested;
            SelectedType   = (results.SuggestedTypes.Count > 0) ? results.SuggestedTypes[0] : null;
        }
        public void BUG__0001__CollectionIsReadOnlyAfterInstanceCreated_NothingCanBeAdded()
        {
            var col = new ObservableCollectionEx<object>();
            col.Add(1);

            Assert.IsTrue(true);
        }
Пример #19
0
 /// <summary>
 /// Adds Rally to Playlist if not already in Playlist
 /// </summary>
 /// <param name="r">Rally which should be added to the playlist</param>
 public void Add(Rally r)
 {
     if (!rallyIDs.Contains(r.ID))
     {
         rallyIDs.Add(r.ID);
     }
 }
Пример #20
0
        protected override bool OnUpdateFrom(Device newDevice, List <string> updatedPropertyNames)
        {
            var isUpdated = UpdateValue(() => CreatedAt, newDevice, updatedPropertyNames);

            isUpdated = UpdateValue(() => Id, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => LastSeenAt, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Name, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Platform, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => PlatformVersion, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ProductVersion, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Provides, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => PublicAddress, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ScreenDensity, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ScreenResolution, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Token, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Vendor, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Version, newDevice, updatedPropertyNames) | isUpdated;

            foreach (var connection in Connections.ToList().Where(con => newDevice.Connections.All(c => c.Uri != con.Uri)))
            {
                Connections.Remove(connection);
                isUpdated = true;
            }

            foreach (var connection in newDevice.Connections.Where(con => Connections.All(c => c.Uri != con.Uri)))
            {
                Connections.Add(connection);
                isUpdated = true;
            }

            return(isUpdated);
        }
Пример #21
0
 private async void _browser_ServiceFound(object sender, NetServiceEventArgs e)
 {
     ThreadUtility.RunOnUIThread(() =>
     {
         _discoveredServices.Add(e.Service.Name);
     });
     await e.Service.ResolveAsync();
 }
Пример #22
0
        public void AddBufferToHistory()
        {
            if (!_SaveHistory)
            {
                return;
            }

            if (_Undo.Count >= 100)
            {
                _Undo.RemoveAt(0);
            }

            _Undo.Add(buffer.ToArray());
            buffer.Clear();

            ClearRedoHistory();
        }
Пример #23
0
        public void Update()
        {
            _header.Text = this.Value.Name;

            base.IsExpanded = this.Value.IsExpanded;

            foreach (var item in _listViewItemCollection.OfType <StoreCategorizeTreeViewItem>().ToArray())
            {
                if (!_value.Children.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Children)
            {
                if (!_listViewItemCollection.OfType <StoreCategorizeTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new StoreCategorizeTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            foreach (var item in _listViewItemCollection.OfType <StoreTreeViewItem>().ToArray())
            {
                if (!_value.StoreTreeItems.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.StoreTreeItems)
            {
                if (!_listViewItemCollection.OfType <StoreTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new StoreTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
        public void ObsCollExConstructorTest()
        {
            ObservableCollectionEx <string> target = new ObservableCollectionEx <string>();

            target.Add("Jesse Pinkman");
            Assert.AreEqual(1, target.Count);
            target.Clear();
            Assert.AreEqual(0, target.Count);
        }
 public void ObsCollExCollectionChangedTest()
 {
     ObservableCollectionEx<string> target = new ObservableCollectionEx<string>();
     target.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(target_CollectionChanged);
     target.Add("Walter White");
     Assert.AreEqual(NotifyCollectionChangedAction.Add,_Args.Action);
     Assert.AreEqual(1, _Args.NewItems.Count);
     Assert.AreEqual("Walter White", _Args.NewItems[0]);
     _Args = null;
 }
Пример #26
0
 /// <summary>
 /// Resizes the map using the OOB flag method
 /// </summary>
 /// <param name="newWidth"></param>
 /// <param name="newHeight"></param>
 private void OOBResize(short newWidth, short newHeight)
 {
     using (ObservableCollectionEx <byte?> safeMapData = this.data.DisableNotifications())
         while (safeMapData.Count < newWidth * newHeight)
         {
             safeMapData.Add(null);
         }
     this.width  = newWidth;
     this.height = newHeight;
 }
Пример #27
0
        public async Task When_Collection_Reset()
        {
            var count = 0;
            var panel = new StackPanel();

            var SUT = new ItemsControl()
            {
                ItemsPanelRoot         = panel,
                ItemContainerStyle     = BuildBasicContainerStyle(),
                InternalItemsPanelRoot = panel,
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            SUT.ApplyTemplate();

            var c = new ObservableCollectionEx <string>();

            c.Add("One");
            c.Add("Two");
            c.Add("Three");

            SUT.ItemsSource = c;
            Assert.AreEqual(count, 3);

            Assert.AreEqual(SUT.Items.Count, 3);

            using (c.BatchUpdate())
            {
                c.Add("Four");
                c.Add("Five");
            }

            Assert.AreEqual(SUT.Items.Count, 5);
            Assert.AreEqual(count, 5);
            Assert.IsNotNull(SUT.ContainerFromItem("One"));
            Assert.IsNotNull(SUT.ContainerFromItem("Four"));
            Assert.IsNotNull(SUT.ContainerFromItem("Five"));
        }
        public void ObsCollExCollectionChangedTest()
        {
            ObservableCollectionEx <string> target = new ObservableCollectionEx <string>();

            target.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(target_CollectionChanged);
            target.Add("Walter White");
            Assert.AreEqual(NotifyCollectionChangedAction.Add, _Args.Action);
            Assert.AreEqual(1, _Args.NewItems.Count);
            Assert.AreEqual("Walter White", _Args.NewItems[0]);
            _Args = null;
        }
Пример #29
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            SelectedMachines = new ObservableCollectionEx <Machine>();

            foreach (OctopusLib.Machine machine in lbMachines.SelectedItems)
            {
                SelectedMachines.Add(machine);
            }

            this.Close();
        }
Пример #30
0
        /// <summary>
        /// Contructor that takes size. The size is readonly, since it is not designed to chenge.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public Board(int width, int height)
        {
            _gameBoard = new ObservableCollectionEx <GamePiece>();
            _width     = width;
            _height    = height;

            //todo delete this test code
            Point p = new Point(160, 160);

            _gameBoard.Add(new GamePiece(p));
        }
Пример #31
0
        public void ShowsGistDialog()
        {
            var provider = Substitutes.GetFullyMockedServiceProvider();
            var factory  = SetupFactory(provider);
            var cm       = provider.GetConnectionManager();
            var cons     = new ObservableCollectionEx <IConnection>();

            cm.Connections.Returns(cons);
            cm.GetLoadedConnections().Returns(cons);

            // simulate being logged in
            cons.Add(SetupConnection(provider, true));

            using (var uiController = new UIController((IGitHubServiceProvider)provider, factory, cm))
            {
                var  count   = 0;
                bool?success = null;
                var  flow    = uiController.Configure(UIControllerFlow.Gist);
                uiController.ListenToCompletionState()
                .Subscribe(s =>
                {
                    success = s;
                    Assert.Equal(1, count);
                    count++;
                });

                flow.Subscribe(data =>
                {
                    var uc = data.View;
                    switch (++count)
                    {
                    case 1:
                        Assert.IsAssignableFrom <IViewFor <IGistCreationViewModel> >(uc);
                        TriggerDone(data.View.ViewModel);
                        break;

                    default:
                        Assert.True(false, "Received more views than expected");
                        break;
                    }
                }, () =>
                {
                    Assert.Equal(2, count);
                    count++;
                });

                uiController.Start();
                Assert.Equal(3, count);
                Assert.True(uiController.IsStopped);
                Assert.True(success.HasValue);
                Assert.True(success);
            }
        }
        public ListViewModel()
        {
            DataCollection     = new ObservableCollectionEx <CmdArgItem>();
            DataCollectionView = CollectionViewSource.GetDefaultView(DataCollection);

            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                DataCollection.Add(new CmdArgItem()
                {
                    Enabled = true, Command = @"C:\Users\Markus\Desktop\"
                });
                DataCollection.Add(new CmdArgItem()
                {
                    Enabled = false, Command = "Hello World"
                });
                DataCollection.Add(new CmdArgItem()
                {
                    Enabled = true, Command = "A very long commandline to test very long commandlines to see how very long commandlines work in our UI."
                });
            }
        }
Пример #33
0
        private static ObservableCollectionEx <GuiMetaDataModel> MapToGuiMetadataEntities(
            IEnumerable <MetadataEntityInformationUnit> metadataEntityInformationUnits)
        {
            var guiMetadataEntities = new ObservableCollectionEx <GuiMetaDataModel>();

            foreach (MetadataEntityInformationUnit metadataEntityInformationUnit in metadataEntityInformationUnits)
            {
                guiMetadataEntities.Add(MapToGuiMetadataEntity(metadataEntityInformationUnit));
            }

            return(guiMetadataEntities);
        }
        public void BUG__0002__BulkUpdateFailsWhenCalledFromMultipleThreads()
        {
            var col = new ObservableCollectionEx<int>();

            var t1 =
                Task.Factory.StartNew(() =>
                {
                    using (col.BeginBulkUpdate())
                    {
                        col.Add(1);
                        Thread.Sleep(10);
                    }
                });

            using (col.BeginBulkUpdate())
            {
                col.Clear();
            }

            // code above would normally fail by now.
        }
Пример #35
0
        private void ParseTwitterResults(XDocument doc, ObservableCollectionEx<TwitterStatusModel> feedModel)
        {
            foreach (TwitterStatusModel model in doc.Descendants("status").Select(BuildTwitterStatusl))
            {
                feedModel.Add(model);
            }

            if (!(App.isoSettings.Contains("Twitter")))
            {
                ThreadPool.QueueUserWorkItem(o => App.isoSettings.Add("Twitter", JsonHelpers.SerializeJson(feedModel)));
            }
            else
            {
                ThreadPool.QueueUserWorkItem(o => App.isoSettings["Twitter"] = JsonHelpers.SerializeJson(feedModel));
            }
        }
 public void ObsCollExWorkerThreadTest()
 {
     ObservableCollectionEx<string> target = new ObservableCollectionEx<string>();
     target.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(target_CollectionChanged);
     ManualResetEvent resetEvent = new ManualResetEvent(false);
     ThreadPool.QueueUserWorkItem(new WaitCallback((x) =>
         {
             target.Add("Crystal Meth");
             resetEvent.Set();
         }));
     resetEvent.WaitOne(1000);
     Assert.AreEqual(NotifyCollectionChangedAction.Add, _Args.Action);
     Assert.AreEqual(1, _Args.NewItems.Count);
     Assert.AreEqual("Crystal Meth", _Args.NewItems[0]);
 }
        public void ObsCollExWPFTest()
        {
            ObservableCollectionEx<string> target = new ObservableCollectionEx<string>();
            target.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(target_CollectionChanged);
            ListBox listBox = new ListBox();
            listBox.Name = "testListBox";
            listBox.ItemsSource = target;

            ManualResetEvent resetEvent = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback((x) =>
            {
                target.Add("Hank Schrader");
                resetEvent.Set();
            }));
            resetEvent.WaitOne(1000);

            Assert.AreEqual(1, listBox.Items.Count);
            Assert.AreEqual("Hank Schrader", listBox.Items[0] as string);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, _Args.Action);
            Assert.AreEqual(1, _Args.NewItems.Count);
            Assert.AreEqual("Hank Schrader", _Args.NewItems[0]);
        }
 public void ObsCollExConstructorTest()
 {
     ObservableCollectionEx<string> target = new ObservableCollectionEx<string>();
     target.Add("Jesse Pinkman");
     Assert.AreEqual(1, target.Count);
     target.Clear();
     Assert.AreEqual(0, target.Count);
 }