Пример #1
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NoItemSelected_ShouldReturnResourceNameNoPath()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.Children).Returns(new ObservableCollection <IExplorerItemViewModel>());
            mockEnvironmentModel.Setup(model => model.LoadDialogAsync(It.IsAny <Guid>())).Returns(Task.FromResult(true));
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "TestResource";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsNotNull(requestServiceNameViewModel.ResourceName);
            Assert.AreEqual("", requestServiceNameViewModel.ResourceName.Path);
            Assert.AreEqual("TestResource", requestServiceNameViewModel.ResourceName.Name);
        }
Пример #2
0
        public async Task RequestServiceNameViewModel_HasLoadedFalse_CanDuplicateFalse()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            mockRequestServiceNameView.Setup(view => view.RequestClose()).Verifiable();
            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();
            var serverRepo           = new Mock <IServerRepository>();
            var connectionObject     = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            var fieldInfo = typeof(RequestServiceNameViewModel).GetField("_selectedPath", BindingFlags.NonPublic | BindingFlags.Instance);

            fieldInfo.SetValue(requestServiceNameViewModel, "Hello World");
            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.SingleEnvironmentExplorerViewModel.Environments = new ObservableCollection <IEnvironmentViewModel>();
            //------------Execute Test---------------------------
            requestServiceNameViewModel.Name = "Test";
            //------------Assert Results-------------------------
            Assert.AreEqual("", requestServiceNameViewModel.ErrorMessage);
            var canExecute = requestServiceNameViewModel.DuplicateCommand.CanExecute(null);

            Assert.IsFalse(canExecute);
        }
Пример #3
0
        public async Task RequestServiceNameViewModel_Header_Set_ShouldFirePropertyChangedEvent()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();
            var called = false;

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.LoadDialogAsync(It.IsAny <Guid>())).Returns(Task.FromResult(false));
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "") as RequestServiceNameViewModel;

            Assert.IsNotNull(requestServiceNameViewModel);
            requestServiceNameViewModel.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Header")
                {
                    called = true;
                }
            };
            //------------Execute Test---------------------------
            requestServiceNameViewModel.Header = "TestHeader";
            //------------Assert Results-------------------------
            Assert.IsTrue(called);
            Assert.AreEqual("TestHeader", requestServiceNameViewModel.Header);
        }
Пример #4
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NameValidNotLoaded_CanClickOk()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.LoadDialogAsync(It.IsAny <Guid>())).Returns(Task.FromResult(false));
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "TesResource";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual("", requestServiceNameViewModel.ErrorMessage);
            var canExecute = requestServiceNameViewModel.OkCommand.CanExecute(null);

            Assert.IsTrue(canExecute);
        }
Пример #5
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NoItemSelectedHasDuplicateName_ShouldReturnError()
        {
            //------------Setup for test--------------------------
            const string expectedErrorMessage       = "An item with this name already exists in this folder.";
            var          mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();
            var mockExplorerTreeItem = new Mock <IExplorerTreeItem>();

            mockExplorerTreeItem.Setup(item => item.ResourceType).Returns("Folder");
            mockExplorerTreeItem.Setup(item => item.ResourceName).Returns("MyFolder");
            var childDuplicateExplorerTreeItem = new Mock <IExplorerItemViewModel>();

            childDuplicateExplorerTreeItem.Setup(item => item.ResourceType).Returns("DbService");
            childDuplicateExplorerTreeItem.Setup(item => item.Children).Returns(new ObservableCollection <IExplorerItemViewModel>());
            childDuplicateExplorerTreeItem.Setup(item => item.ResourceName).Returns("TestResource");
            childDuplicateExplorerTreeItem.Setup(model => model.Parent).Returns(mockExplorerTreeItem.Object);
            var explorerItemViewModels = new ObservableCollection <IExplorerItemViewModel> {
                childDuplicateExplorerTreeItem.Object
            };

            mockEnvironmentModel.Setup(model => model.Children).Returns(explorerItemViewModels);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "TestResource";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual(expectedErrorMessage, requestServiceNameViewModel.ErrorMessage);
            Assert.IsFalse(requestServiceNameViewModel.OkCommand.CanExecute(null));
        }
        public async Task RequestServiceNameViewModel_ShowSaveDialog_ItemSelected_ShouldReturnResourceNameWithPath()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.Children).Returns(new ObservableCollection <IExplorerItemViewModel>());
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "TestResource";
            var mockExplorerTreeItem = new Mock <IExplorerTreeItem>();

            mockExplorerTreeItem.Setup(item => item.ResourceType).Returns("Folder");
            mockExplorerTreeItem.Setup(item => item.Children).Returns(new ObservableCollection <IExplorerItemViewModel>());
            mockExplorerTreeItem.Setup(item => item.ResourceName).Returns("MyFolder");
            requestServiceNameViewModel.SingleEnvironmentExplorerViewModel.SelectedItem = mockExplorerTreeItem.Object;
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsNotNull(requestServiceNameViewModel.ResourceName);
            Assert.AreEqual("MyFolder\\", requestServiceNameViewModel.ResourceName.Path);
            Assert.AreEqual("TestResource", requestServiceNameViewModel.ResourceName.Name);
        }
Пример #7
0
        public void RequestServiceNameViewModel_CreateAsync_NullParameters_ShouldError()
        {
            //------------Setup for test--------------------------


            //------------Execute Test---------------------------
            RequestServiceNameViewModel.CreateAsync(null, "", "");
            //------------Assert Results-------------------------
        }
Пример #8
0
        public void CallDuplicateService_GivenValidComsController_ShouldExecuteCorrectly()
        {
            //---------------Set up test pack-------------------

            var envMock    = new Mock <IEnvironmentConnection>();
            var controller = new Mock <ICommunicationController>();
            var envModel   = new Mock <IEnvironmentViewModel>();

            envModel.Setup(model => model.Children).Returns(new ObservableCollection <IExplorerItemViewModel>());
            var itemObj          = new Mock <IExplorerItemViewModel>();
            var selectedItemMock = new Mock <IExplorerViewModel>();
            var item             = new Mock <IExplorerTreeItem>();

            item.Setup(model => model.ResourceName).Returns("name");
            item.Setup(model => model.ResourceType).Returns("type");
            item.Setup(model => model.ResourceName).Returns("name");
            selectedItemMock.Setup(sitem => sitem.SelectedItem).Returns(item.Object);
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var viewModel = RequestServiceNameViewModel.CreateAsync(envModel.Object, "", "", itemObj.Object).Result;

            controller.Setup(communicationController => communicationController.AddPayloadArgument("ResourceID", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("NewResourceName", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("FixRefs", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.ExecuteCommand <ExecuteMessage>(It.IsAny <IEnvironmentConnection>(), It.IsAny <Guid>()));
            var lazyCon = typeof(RequestServiceNameViewModel).GetField("_lazyCon", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            lazyCon.SetValue(viewModel, envMock.Object);
            var lazyComs = typeof(RequestServiceNameViewModel).GetField("_communicationController", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            lazyComs.SetValue(viewModel, controller.Object);
            var selectedItem = typeof(RequestServiceNameViewModel).GetProperty("SingleEnvironmentExplorerViewModel", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public);

            selectedItem.SetValue(viewModel, selectedItemMock.Object);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(viewModel);
            //---------------Execute Test ----------------------

            try
            {
                viewModel.DuplicateCommand.Execute(null);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
            //---------------Test Result -----------------------
            controller.Verify(communicationController => communicationController.AddPayloadArgument("ResourceID", It.IsAny <string>()));
            controller.Verify(communicationController => communicationController.AddPayloadArgument("NewResourceName", It.IsAny <string>()));
            controller.Verify(communicationController => communicationController.ExecuteCommandAsync <ResourceCatalogDuplicateResult>(It.IsAny <IEnvironmentConnection>(), It.IsAny <Guid>()));
        }
Пример #9
0
        public async Task RequestServiceNameViewModel_CreateAsync_ParametersPassed_ShouldConstructCorrectly()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(new Mock <IEnvironmentViewModel>().Object, "", "");

            //------------Assert Results-------------------------
            Assert.IsNotNull(requestServiceNameViewModel);
            Assert.IsNotNull(requestServiceNameViewModel.OkCommand);
            Assert.IsNotNull(requestServiceNameViewModel.CancelCommand);
            Assert.AreEqual("", requestServiceNameViewModel.Name);
        }
Пример #10
0
        public void CallDuplicateService_GivenValidComsController_ShouldExecuteCorrectly()
        {
            //---------------Set up test pack-------------------

            var envMock          = new Mock <IEnvironmentConnection>();
            var controller       = new Mock <ICommunicationController>();
            var envModel         = new Mock <IEnvironmentViewModel>();
            var itemObj          = new Mock <IExplorerItemViewModel>();
            var selectedItemMock = new Mock <IExplorerViewModel>();
            var item             = new Mock <IExplorerTreeItem>();

            item.Setup(model => model.ResourceName).Returns("name");
            item.Setup(model => model.ResourceType).Returns("type");
            item.Setup(model => model.ResourceName).Returns("name");
            selectedItemMock.Setup(sitem => sitem.SelectedItem).Returns(item.Object);
            var viewModel = RequestServiceNameViewModel.CreateAsync(envModel.Object, "", "", itemObj.Object).Result;

            controller.Setup(communicationController => communicationController.AddPayloadArgument("ResourceID", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("NewResourceName", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("FixRefs", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.ExecuteCommand <ExecuteMessage>(It.IsAny <IEnvironmentConnection>(), It.IsAny <Guid>()));
            var lazyCon = typeof(RequestServiceNameViewModel).GetField("_lazyCon", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            // ReSharper disable once PossibleNullReferenceException
            lazyCon.SetValue(viewModel, envMock.Object);
            var lazyComs = typeof(RequestServiceNameViewModel).GetField("_lazyComs", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            // ReSharper disable once PossibleNullReferenceException
            lazyComs.SetValue(viewModel, controller.Object);
            var selectedItem = typeof(RequestServiceNameViewModel).GetProperty("SingleEnvironmentExplorerViewModel", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public);

            // ReSharper disable once PossibleNullReferenceException
            selectedItem.SetValue(viewModel, selectedItemMock.Object);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(viewModel);
            //---------------Execute Test ----------------------

            try
            {
                viewModel.DuplicateCommand.Execute(null);
            }
            catch (Exception)
            {
                //
            }
            //---------------Test Result -----------------------
            controller.Verify(communicationController => communicationController.AddPayloadArgument("ResourceID", It.IsAny <string>()));
            controller.Verify(communicationController => communicationController.AddPayloadArgument("NewResourceName", It.IsAny <string>()));
            controller.Verify(communicationController => communicationController.ExecuteCommand <ResourceCatalogDuplicateResult>(It.IsAny <IEnvironmentConnection>(), It.IsAny <Guid>()));
        }
Пример #11
0
        public async Task RequestServiceNameViewModel_SetName_SingleEnvironmentModelNull_ErrorMessageEmpty()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            mockRequestServiceNameView.Setup(view => view.RequestClose()).Verifiable();
            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel        = new Mock <IEnvironmentViewModel>();
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            //------------Execute Test---------------------------
            requestServiceNameViewModel.Name = "Test";
            //------------Assert Results-------------------------
            Assert.AreEqual("", requestServiceNameViewModel.ErrorMessage);
        }
Пример #12
0
        public async Task RequestServiceNameViewModel_CreateAsync_ParametersPassed_ShouldConstructCorrectly()
        {
            //------------Setup for test--------------------------
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            //------------Execute Test---------------------------
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(new Mock <IEnvironmentViewModel>().Object, "", "");

            //------------Assert Results-------------------------
            Assert.IsNotNull(requestServiceNameViewModel);
            Assert.IsNotNull(requestServiceNameViewModel.OkCommand);
            Assert.IsNotNull(requestServiceNameViewModel.CancelCommand);
            Assert.AreEqual("", requestServiceNameViewModel.Name);
        }
Пример #13
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NameEmpty_ShouldHaveErrorMessage()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel        = new Mock <IEnvironmentViewModel>();
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual(Resource.Errors.ErrorResource.CannotBeNull, requestServiceNameViewModel.ErrorMessage);
            Assert.IsFalse(requestServiceNameViewModel.OkCommand.CanExecute(null));
        }
Пример #14
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NameContainsLeadingTrailingSpaces_ShouldHaveErrorMessage()
        {
            //------------Setup for test--------------------------
            const string expectedErrorMessage       = "'Name' contains leading or trailing whitespace characters.";
            var          mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel        = new Mock <IEnvironmentViewModel>();
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = " Save ";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual(expectedErrorMessage, requestServiceNameViewModel.ErrorMessage);
            Assert.IsFalse(requestServiceNameViewModel.OkCommand.CanExecute(null));
        }
Пример #15
0
        public void RequestServiceNameViewModel_CallDuplicateCommand_GivenNoItemPassed_ShouldSetCanExecuteFalse()
        {
            //---------------Set up test pack-------------------

            var envMock          = new Mock <IEnvironmentConnection>();
            var controller       = new Mock <ICommunicationController>();
            var envModel         = new Mock <IEnvironmentViewModel>();
            var selectedItemMock = new Mock <IExplorerViewModel>();
            var item             = new Mock <IExplorerTreeItem>();

            item.Setup(model => model.ResourceName).Returns("name");
            item.Setup(model => model.ResourceType).Returns("type");
            item.Setup(model => model.ResourceName).Returns("name");
            selectedItemMock.Setup(sitem => sitem.SelectedItem).Returns(item.Object);
            var serverRepo       = new Mock <IServerRepository>();
            var connectionObject = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var viewModel = RequestServiceNameViewModel.CreateAsync(envModel.Object, "", "").Result;

            controller.Setup(communicationController => communicationController.AddPayloadArgument("ResourceID", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("NewResourceName", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.AddPayloadArgument("FixRefs", It.IsAny <string>()));
            controller.Setup(communicationController => communicationController.ExecuteCommand <ExecuteMessage>(It.IsAny <IEnvironmentConnection>(), It.IsAny <Guid>()));
            var lazyCon = typeof(RequestServiceNameViewModel).GetField("_lazyCon", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            lazyCon.SetValue(viewModel, envMock.Object);
            var lazyComs = typeof(RequestServiceNameViewModel).GetField("_communicationController", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            lazyComs.SetValue(viewModel, controller.Object);
            var selectedItem = typeof(RequestServiceNameViewModel).GetProperty("SingleEnvironmentExplorerViewModel", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public);

            selectedItem.SetValue(viewModel, selectedItemMock.Object);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(viewModel);
            //---------------Execute Test ----------------------

            var canExecute = viewModel.DuplicateCommand.CanExecute(null);

            //---------------Test Result -----------------------
            Assert.IsFalse(canExecute);
        }
Пример #16
0
        public async Task RequestServiceNameViewModel_CancelCommand_Called_ShouldCloseView()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            mockRequestServiceNameView.Setup(view => view.RequestClose()).Verifiable();
            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.LoadDialog(It.IsAny <Guid>())).Returns(Task.FromResult(false));
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            //------------Execute Test---------------------------
            requestServiceNameViewModel.CancelCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsNull(requestServiceNameViewModel.SingleEnvironmentExplorerViewModel);
            mockRequestServiceNameView.Verify(view => view.RequestClose());
        }
Пример #17
0
        public async Task RequestServiceNameViewModel_ShowSaveDialog_NoItemSelected_ShouldReturnResourceNameNoPath()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();

            mockEnvironmentModel.Setup(model => model.LoadDialog(It.IsAny <Guid>())).Returns(Task.FromResult(true));
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.Name = "TestResource";
            //------------Execute Test---------------------------
            requestServiceNameViewModel.OkCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsNotNull(requestServiceNameViewModel.ResourceName);
            Assert.AreEqual("", requestServiceNameViewModel.ResourceName.Path);
            Assert.AreEqual("TestResource", requestServiceNameViewModel.ResourceName.Name);
        }
Пример #18
0
        public async Task RequestServiceNameViewModel_SetName_SingleEnvironmentModelEnvironmentsNull_ErrorMessageEmpty()
        {
            //------------Setup for test--------------------------
            var mockRequestServiceNameView = new Mock <IRequestServiceNameView>();

            mockRequestServiceNameView.Setup(view => view.RequestClose()).Verifiable();
            CustomContainer.RegisterInstancePerRequestType <IRequestServiceNameView>(() => mockRequestServiceNameView.Object);
            var mockEnvironmentModel = new Mock <IEnvironmentViewModel>();
            var serverRepo           = new Mock <IServerRepository>();
            var connectionObject     = new Mock <IEnvironmentConnection>();

            serverRepo.Setup(repository => repository.ActiveServer.Connection).Returns(connectionObject.Object);
            CustomContainer.Register(serverRepo.Object);
            var requestServiceNameViewModel = await RequestServiceNameViewModel.CreateAsync(mockEnvironmentModel.Object, "", "");

            requestServiceNameViewModel.ShowSaveDialog();
            requestServiceNameViewModel.SingleEnvironmentExplorerViewModel.Environments = new ObservableCollection <IEnvironmentViewModel>();
            //------------Execute Test---------------------------
            requestServiceNameViewModel.Name = "Test";
            //------------Assert Results-------------------------
            Assert.AreEqual("", requestServiceNameViewModel.ErrorMessage);
        }
Пример #19
0
        static async void ShowSaveDialog(IContextualResourceModel resourceModel, WebsiteCallbackHandler callbackHandler, Action loaded = null, bool loadingFromServer = true, string originalPath = "")
        {
            try
            {
                if (resourceModel == null)
                {
                    throw new ArgumentNullException(nameof(resourceModel));
                }
                var server = resourceModel.Environment;
                ServerRepository.Instance.ActiveServer = server ?? throw new ArgumentNullException("environment");

                if (server.Permissions == null)
                {
                    server.Permissions = new List <IWindowsGroupPermission>();
                    server.Permissions.AddRange(server.AuthorizationService.SecurityService.Permissions);
                }
                if (resourceModel.Category == null)
                {
                    resourceModel.Category = "";
                }

                var selectedPath = resourceModel.Category.Contains("Unassigned") || string.IsNullOrEmpty(resourceModel.Category) ? "" : resourceModel.Category;
                var lastIndexOf  = selectedPath.LastIndexOf("\\", StringComparison.Ordinal);
                if (lastIndexOf != -1)
                {
                    selectedPath = selectedPath.Substring(0, lastIndexOf);
                }
                selectedPath = selectedPath.Replace("\\", "\\\\");

                var mainViewModel        = CustomContainer.Get <IShellViewModel>();
                var environmentViewModel = mainViewModel?.ExplorerViewModel?.Environments?.FirstOrDefault(model => model.Server.EnvironmentID == resourceModel.Environment.EnvironmentID);
                if (environmentViewModel == null)
                {
                    return;
                }

                var header            = string.IsNullOrEmpty(resourceModel.Category) ? "Unsaved Item" : resourceModel.Category;
                var lastHeaderIndexOf = header.LastIndexOf("\\", StringComparison.Ordinal);
                if (lastHeaderIndexOf != -1)
                {
                    header = header.Substring(lastHeaderIndexOf, header.Length - lastHeaderIndexOf);
                    header = header.Replace("\\", "");
                }

                var requestViewModel = await RequestServiceNameViewModel.CreateAsync(environmentViewModel, selectedPath, header);

                var messageBoxResult = requestViewModel.ShowSaveDialog();
                if (messageBoxResult == MessageBoxResult.OK)
                {
                    var value           = new { resourceName = requestViewModel.ResourceName.Name, resourcePath = requestViewModel.ResourceName.Path, resourceLoadingFromServer = loadingFromServer, OriginalPath = originalPath };
                    var serializeObject = JsonConvert.SerializeObject(value);
                    callbackHandler.Save(serializeObject, server);
                }
                else
                {
                    if (!loadingFromServer)
                    {
                        mainViewModel.CloseResource(resourceModel, server.EnvironmentID);
                    }
                }
                loaded?.Invoke();
            }
            catch (Exception)
            {
                loaded?.Invoke();
                throw;
            }
        }