예제 #1
0
        public void Execute_SelectedIdentityCommand_LeaveEmptyAndNullProperty()
        {
            //Arange
            IItemSearchView view      = Substitute.For <IItemSearchView>();
            ISearcher       iSearcher = Substitute.For <ISearcher>();

            ItemSearchPresenterResult searchPresenterResult = new ItemSearchPresenterResult()
            {
                DialogResult = System.Windows.Forms.DialogResult.Cancel
            };

            ItemSearchPresenter itemSearchPresenter = Substitute.ForPartsOf <ItemSearchPresenter>(view, iSearcher);

            itemSearchPresenter.When(x => x.Run(Arg.Any <ItemSearchPresenterArgs>())).DoNotCallBase();
            itemSearchPresenter.Run(Arg.Any <ItemSearchPresenterArgs>()).Returns(searchPresenterResult);

            this.dialogFactory.GetItemSearchPresenter("Identity", "Identity").Returns(itemSearchPresenter);

            //Act
            this.createMethodViewModel.SelectedIdentityCommand.Execute(null);

            //Assert
            Assert.IsNull(this.createMethodViewModel.SelectedIdentityKeyedName);
            Assert.IsNull(this.createMethodViewModel.SelectedIdentityId);
            Assert.AreEqual(0, this.projectConfiguration.LastSavedSearch.Count);
        }
예제 #2
0
        public void SearchMethodDialogCommandExcecute_ShouldDoNotSetExpectedProperties()
        {
            //Arange
            ISearcher           searcher            = Substitute.For <ISearcher>();
            IItemSearchView     searchView          = Substitute.For <IItemSearchView>();
            ItemSearchPresenter itemSearchPresenter = Substitute.ForPartsOf <ItemSearchPresenter>(searchView, searcher);

            itemSearchPresenter.When(x => x.Run(Arg.Any <ItemSearchPresenterArgs>())).DoNotCallBase();

            this.dialogFactory.GetItemSearchPresenter("Method", "Method").Returns(itemSearchPresenter);
            this.projectConfiguration.LastSavedSearch.Returns(new Dictionary <string, List <PropertyInfo> >());

            ItemSearchPresenterResult searchResult = new ItemSearchPresenterResult()
            {
                DialogResult = DialogResult.Cancel
            };

            itemSearchPresenter.Run(Arg.Any <ItemSearchPresenterArgs>()).Returns(searchResult);

            //Act
            this.openFromArasViewModel.SearchMethodDialogCommand.Execute(null);

            //Assert
            Assert.IsNull(this.openFromArasViewModel.MethodName);
            Assert.IsNull(this.openFromArasViewModel.MethodId);
            Assert.IsNull(this.openFromArasViewModel.MethodConfigId);
            Assert.IsNull(this.openFromArasViewModel.MethodLanguage);
            Assert.IsNull(this.openFromArasViewModel.IdentityKeyedName);
            Assert.IsNull(this.openFromArasViewModel.IdentityId);
            Assert.IsNull(this.openFromArasViewModel.MethodComment);
            Assert.IsNull(this.openFromArasViewModel.MethodType);
            Assert.IsNull(this.openFromArasViewModel.MethodCode);
            Assert.IsNull(this.openFromArasViewModel.SelectedTemplate);
        }
예제 #3
0
        public void SelectedIdentityCommandExecute_ShouldFillExpected()
        {
            //Arange
            IItemSearchView view      = Substitute.For <IItemSearchView>();
            ISearcher       iSearcher = Substitute.For <ISearcher>();

            ItemSearchPresenterResult searchPresenterResult = new ItemSearchPresenterResult()
            {
                DialogResult    = System.Windows.Forms.DialogResult.OK,
                ItemId          = "A73B655731924CD0B027E4F4D5FCC0A9",
                ItemType        = "Identity",
                LastSavedSearch = new List <PropertyInfo>()
            };

            ItemSearchPresenter itemSearchPresenter = Substitute.ForPartsOf <ItemSearchPresenter>(view, iSearcher);

            itemSearchPresenter.When(x => x.Run(Arg.Any <ItemSearchPresenterArgs>())).DoNotCallBase();
            itemSearchPresenter.Run(Arg.Any <ItemSearchPresenterArgs>()).Returns(searchPresenterResult);

            this.dialogFactory.GetItemSearchPresenter("Identity", "Identity").Returns(itemSearchPresenter);

            this.serverConnection.When(x => x.CallAction("ApplyItem", Arg.Is <XmlDocument>(doc => doc.DocumentElement.Attributes["type"].Value == "Identity"), Arg.Any <XmlDocument>()))
            .Do(x =>
            {
                (x[2] as XmlDocument).Load(Path.Combine(currentPath, @"Dialogs\ViewModels\TestData\WorldItentityItem.xml"));
            });

            //Act
            this.createMethodViewModel.SelectedIdentityCommand.Execute(null);

            //Assert
            Assert.AreEqual("World", this.createMethodViewModel.SelectedIdentityKeyedName);
            Assert.AreEqual("A73B655731924CD0B027E4F4D5FCC0A9", this.createMethodViewModel.SelectedIdentityId);
            Assert.AreEqual(1, this.projectConfiguration.LastSavedSearch.Count);
        }
예제 #4
0
        public void SearchMethodDialogCommandExcecute_ShouldSetExpectedPropertyValue()
        {
            //Arange
            ISearcher           searcher            = Substitute.For <ISearcher>();
            IItemSearchView     searchView          = Substitute.For <IItemSearchView>();
            ItemSearchPresenter itemSearchPresenter = Substitute.ForPartsOf <ItemSearchPresenter>(searchView, searcher);

            itemSearchPresenter.When(x => x.Run(Arg.Any <ItemSearchPresenterArgs>())).DoNotCallBase();

            this.dialogFactory.GetItemSearchPresenter("Method", "Method").Returns(itemSearchPresenter);
            this.projectConfiguration.LastSavedSearch.Returns(new Dictionary <string, List <PropertyInfo> >());

            ItemSearchPresenterResult searchResult = new ItemSearchPresenterResult()
            {
                DialogResult = DialogResult.OK,
                ItemType     = "Method",
                ItemId       = "1BF96D4255962F7EA5970426401A841E"
            };

            itemSearchPresenter.Run(Arg.Any <ItemSearchPresenterArgs>()).Returns(searchResult);

            this.serverConnection.When(x => x.CallAction("ApplyItem", Arg.Any <XmlDocument>(), Arg.Any <XmlDocument>()))
            .Do(callBack =>
            {
                (callBack[2] as XmlDocument).Load(Path.Combine(currentPath, @"Dialogs\ViewModels\TestData\TestMethodItem.xml"));
            });

            //Act
            this.openFromArasViewModel.SearchMethodDialogCommand.Execute(null);

            //Assert
            Assert.AreEqual("ReturnNullMethodName", this.openFromArasViewModel.MethodName);
            Assert.AreEqual("1BF96D4255962F7EA5970426401A841E", this.openFromArasViewModel.MethodId);
            Assert.AreEqual("616634B3DC344D51964CD7AD988051D7", this.openFromArasViewModel.MethodConfigId);
            Assert.AreEqual("C#", this.openFromArasViewModel.MethodLanguage);
            Assert.AreEqual("World", this.openFromArasViewModel.IdentityKeyedName);
            Assert.AreEqual("A73B655731924CD0B027E4F4D5FCC0A9", this.openFromArasViewModel.IdentityId);
            Assert.IsEmpty(this.openFromArasViewModel.MethodComment);
            Assert.AreEqual("server", this.openFromArasViewModel.MethodType);
            Assert.AreEqual("return null;", this.openFromArasViewModel.MethodCode);
            Assert.IsNull(this.openFromArasViewModel.SelectedTemplate);
            Assert.AreEqual(1, this.projectConfiguration.LastSavedSearch.Count);
        }
        private void SelectedIdentityCommandClick()
        {
            string itemTypeName          = "Identity";
            string itemTypeSingularLabel = "Identity";

            List <PropertyInfo> predefinedSearchItems;

            if (!projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch.TryGetValue(itemTypeName, out predefinedSearchItems))
            {
                predefinedSearchItems = new List <PropertyInfo>();
            }

            var searchArguments = new ItemSearchPresenterArgs()
            {
                Title = "Search dialog",
                PredefinedPropertyValues = predefinedSearchItems
            };

            ItemSearchPresenter presenter = dialogFactory.GetItemSearchPresenter(itemTypeName, itemTypeSingularLabel);
            var result = presenter.Run(searchArguments);

            if (result.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                // TODO : should be replaced by better approach
                dynamic item = authManager.InnovatorInstance.newItem(itemTypeName, "get");
                item.setID(result.ItemId);
                item.setAttribute("select", "keyed_name");
                item = item.apply();

                this.SelectedIdentityKeyedName = item.getProperty("keyed_name");
                this.selectedIdentityId        = result.ItemId;

                if (projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch.ContainsKey(result.ItemType))
                {
                    projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch[result.ItemType] = result.LastSavedSearch;
                }
                else
                {
                    projectConfigurationManager.CurrentProjectConfiguraiton.LastSavedSearch.Add(result.ItemType, result.LastSavedSearch);
                }
            }
        }