public void Execute_WhenCalledWithEmptyList_Throw()
        {
            var rule = new ChecklistDisplayFieldsShouldBeUniqueRule(ChecklistFieldsStepEdit.DisplayFieldsProperty);
            var context = Mock.Create<RuleContext>(Constructor.Mocked, Behavior.CallOriginal);
            
            
            var mock1 = Mock.Create<ChecklistDisplayFieldEdit>();
            Mock.Arrange(() => mock1.SystemName).Returns("s1");
            var mock2 = Mock.Create<ChecklistDisplayFieldEdit>();
            Mock.Arrange(() => mock2.SystemName).Returns("s1");
            var list = new List<ChecklistDisplayFieldEdit>{mock1, mock2};

            Mock.Arrange(() => context.InputPropertyValues).Returns(new Dictionary<IPropertyInfo, object> { { ChecklistFieldsStepEdit.DisplayFieldsProperty, list }});
            var checklistFieldsStepEditMock = Mock.Create<ChecklistFieldsStepEdit>();
            Mock.Arrange(() => checklistFieldsStepEditMock.GetParent<FieldEdit>()).Returns(new FieldEdit());
            Mock.Arrange(() => context.Target).Returns(checklistFieldsStepEditMock);

            var ruleWasThrown = false;
            Mock.Arrange(() => context.AddErrorResult(Arg.AnyString)).DoInstead(() => ruleWasThrown = true);
            

            // act
            var privateAccessor = new PrivateAccessor(rule);
            privateAccessor.CallMethod("Execute", new object[] { context });

            //Assert
            Assert.IsTrue(ruleWasThrown);
        }
        public void Execute()
        {
            // arrange
            var rule = new ScheduleFrequencyPatternRule(null, null);

            var context = Mock.Create<RuleContext>(Constructor.Mocked, Behavior.CallOriginal);
            Mock.Arrange(() => context.InputPropertyValues)
                .Returns(new Dictionary<IPropertyInfo, object> { { ProcessScheduleEdit.HighlightScheduleFrequencyPatternProperty, 0 }, { ProcessScheduleEdit.ScheduleFrequencyPatternIdProperty, 0 } });

            var ruleWasThrown = false;
            Mock.Arrange(() => context.AddErrorResult(Arg.IsAny<IPropertyInfo>(), Arg.AnyString)).DoInstead(() => ruleWasThrown = true);

            // act
            var privateAccessor = new PrivateAccessor(rule);
            privateAccessor.CallMethod("Execute", new object[] { context });

            // assert
            Assert.IsTrue(ruleWasThrown);

            // arrange
            ruleWasThrown = false;
            Mock.Arrange(() => context.InputPropertyValues)
                .Returns(new Dictionary<IPropertyInfo, object> { { ProcessScheduleEdit.HighlightScheduleFrequencyPatternProperty, 0 }, { ProcessScheduleEdit.ScheduleFrequencyPatternIdProperty, 1 } });

            // act
            privateAccessor.CallMethod("Execute", new object[] { context });

            // assert
            Assert.IsFalse(ruleWasThrown);
        }
        public void TestOnStepAsyncAtCancel()
        {
            GeneralThreadAffineContext.Run(
                async () =>
                {
                    Mock.Arrange(() => Application.Current.Dispatcher.InvokeAsync(null))
                        .IgnoreArguments()
                        .DoNothing();

                    var managementMock = Mock.Create<CollectionsManagementViewModel>(Behavior.CallOriginal);
                    var editQueueMock = Mock.Create<EditQueueViewModel>(
                        Behavior.CallOriginal, managementMock);

                    Mock.NonPublic.Arrange<Task>(editQueueMock, "UnLockAsync").Returns(Task.Run(() => { }));
                    Mock.Arrange(() => editQueueMock.SelectedQueue).Returns(new QueueDetailsModel());
                    Mock.Arrange(
                        () => managementMock.OnStepAsync(CollectionsManagementViewModel.EnumSteps.SelectQueue))
                        .Returns(Task.Run(() => { }));

                    var mainView = new PrivateAccessor(editQueueMock);
                    mainView.SetProperty("IsCheckedOut", true);
                    await editQueueMock.OnStepAsync(EditQueueViewModel.EnumSteps.Cancel);

                    bool isCheckedOutOnMainViewModel = mainView.GetProperty("IsCheckedOut") is bool && (bool)mainView.GetProperty("IsCheckedOut");

                    Assert.IsFalse(isCheckedOutOnMainViewModel);
                });
        }
        public void CheckPropertiesInitialValuesTest()
        {
            //Mock spreadsheet
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => spreadsheetMock.GetTopLevelSpreadsheet()).CallOriginal();

            //Call constructor
            var container = new SpreadsheetItemContainer(spreadsheetMock);
            var privateAccessor = new PrivateAccessor(container);

            //Assert fields
            Assert.IsNotNull(privateAccessor.GetField("_topLevelSpreadsheet"));
            Assert.AreEqual(privateAccessor.GetField("_topLevelSpreadsheet"), spreadsheetMock);
            Assert.IsNotNull(privateAccessor.GetField("_owner"));
            Assert.AreEqual(privateAccessor.GetField("_owner"), spreadsheetMock);
            Assert.IsNull(privateAccessor.GetField("_item"));
            Assert.IsFalse((bool)privateAccessor.GetField("_disposed"));

            //Assert properties
            Assert.IsFalse(container.IsOdd);
            Assert.IsFalse(container.IsDisposed);
            Assert.AreEqual(container.Owner, spreadsheetMock);
            Assert.AreEqual(container.TopLevelSpreadsheet, spreadsheetMock);
            Assert.IsNull(container.Item);
            Assert.IsNotNull(container.Cells);
            Assert.IsFalse(container.Cells.Any());
            Assert.IsFalse(container.IsAlternate);
            Assert.IsFalse(container.IsSelected);
        }
        public void CanSortOrGroupLayout()
        {
            // arrange
            var vm = new ProcessLayoutsViewModel();

            var model = Mock.Create<ProcessEdit>(Behavior.Loose);
            model.SystemName = Constants.CalendarProcessName;

            Mock.Arrange(() => vm.Model).Returns(model);

            // act
            var privateAccessor = new PrivateAccessor(vm);
            var result = (bool)privateAccessor.CallMethod("CanSortOrGroupLayout", new object[] { null });

            // assert
            Assert.IsFalse(result);

            // arrage
            model.SystemName = "eCar_p";

            // act
            result = (bool)privateAccessor.CallMethod("CanSortOrGroupLayout", new object[] { null });

            // assert
            Assert.IsTrue(result);
        }
Exemple #6
0
        public void Ctor()
        {
            // arrange
            Mock.SetupStatic(typeof(Ioc));

            // act
            var handler = new DocHandler();

            // assert
            var privateAccessor = new PrivateAccessor(handler);
            Assert.IsNull(privateAccessor.GetField("_fileProcessorUri"));
            Assert.IsNull(privateAccessor.GetField("_tempDocumentUnc"));

            // arrange
            Mock.Arrange(() => SystemOptionsInfo.GetSystemOptionsInfo()).Returns(new SystemOptionsInfo
                {
                    FileProcessorURI = "http://*****:*****@"D:\Projects\Cebos\release-2.2\Cebos.Veyron.Web\FileStorage"
                });

            // act
            handler = new DocHandler();

            // assert
            privateAccessor = new PrivateAccessor(handler);
            Assert.AreEqual("http://*****:*****@"D:\Projects\Cebos\release-2.2\Cebos.Veyron.Web\FileStorage", privateAccessor.GetField("_tempDocumentUnc"));
        }
        public void WhenCalledConvert_CreatesNewViewOrReturnsCachedOneIfAny()
        {
            var converter = new EditorSelector();
            var privateAccessor = new PrivateAccessor(converter);

            EditorSelector.ResetComposedConverter();

            var view = new UserControl();
            const string fieldType = "testFieldType";

            converter.EditorFactories = new[]
                                            {
                                                new ExportFactory<UserControl, IExportAsControlForTypeMetadata>(
                                                    () => new Tuple<UserControl, Action>(view, () => { }),
                                                    new ExportAsControlForTypeAttribute(fieldType))
                                            };

            var fieldItemMock = Mock.Create<IFieldItem>(Behavior.CallOriginal);

            Mock.Arrange(() => fieldItemMock.FieldType).Returns(fieldType);
            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(true);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(true);
            Mock.Arrange(() => fieldItemMock.IsInformationOnly).Returns(false);

            var returnedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof (object)), new object(), null);

            Assert.AreEqual(view.GetType(), returnedView.GetType());
            Assert.AreSame(fieldItemMock, returnedView.DataContext);
            Assert.IsTrue(returnedView.IsEnabled);

            //check that view was cached in RegisteredViews table
            UserControl cachedView;
            var registeredViews = privateAccessor.GetField("RegisteredViews") as ConditionalWeakTable<IFieldItem, UserControl>;
            Assert.IsNotNull(registeredViews);
            Assert.IsTrue(registeredViews.TryGetValue(fieldItemMock, out cachedView));

            //remove cached view to ensure that converter will create a new one
            registeredViews.Remove(fieldItemMock);

            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(false);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(false);

            returnedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof(object)), new object(), null);

            Assert.AreEqual(view.GetType(), returnedView.GetType());
            Assert.AreSame(fieldItemMock, returnedView.DataContext);
            Assert.IsFalse(returnedView.IsEnabled);

            //now converter should return the cached view
            Mock.Arrange(() => fieldItemMock.CanEdit).Returns(true);
            Mock.Arrange(() => fieldItemMock.CanView()).Returns(true);

            var returnedCachedView = (UserControl)converter.Convert(fieldItemMock, new TypeDelegator(typeof(object)), new object(), null);

            Assert.IsTrue(ReferenceEquals(returnedView, returnedCachedView));
            Assert.AreSame(fieldItemMock, returnedCachedView.DataContext);
            Assert.IsFalse(returnedCachedView.IsEnabled);
        }
        public void PrivateAccessor_ShouldCallPrivateMethod()
        {
            // ACT
            // Wrapping the instance holding the private method.
            var inst = new PrivateAccessor(new ClassWithNonPublicMembers());
            // Calling the non-public method by giving its exact name.
            var actual = inst.CallMethod("MePrivate");

            // ASSERT
            Assert.AreEqual(1000, actual);
        }
        public void IsDeletingCommand()
        {
            // arrange
            var command = Mock.Create<InsertImageToRichtextCommand>(Constructor.Mocked, Behavior.CallOriginal);

            // act
            var result = new PrivateAccessor(command).GetProperty("IsDeletingCommand");

            // assert
            Assert.IsTrue((bool)result);
        }
        public void PrivateAccessor_ShouldGetSetProperty()
        {
            // ACT
            // Wrapping the instance holding the private property.
            var inst = new PrivateAccessor(new ClassWithNonPublicMembers());
            // Setting the value of the private property.
            inst.SetProperty("Prop", 555);

            // ASSERT - Asserting with getting the value of the private property.
            Assert.AreEqual(555, inst.GetProperty("Prop"));
        } 
        public void OnMouseLeftButtonUp_NodesShouldBeConnectedFromSourceToDestination()
        {
            var thumbMock = Mock.Create<ConnectorThumb>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(thumbMock);

            //Arrange
            Mock.NonPublic.Arrange(thumbMock, "OnMouseLeftButtonUp", ArgExpr.IsAny<MouseButtonEventArgs>()).CallOriginal();

            var dcMock = Mock.Create<ExpressionConnectorViewModel>();
            Mock.Arrange(() => dcMock.ConnectorType).Returns(ConnectorType.In);
            Mock.Arrange(() => dcMock.Item.CreateConnection(Arg.IsAny<IDiagramItem>(), Arg.IsAny<IDiagramItem>()))
                .Returns(Mock.Create<ExpressionConnection>(Constructor.Mocked, Behavior.Loose));
            Mock.Arrange(() => thumbMock.DataContext).Returns(dcMock);

            var panelMock = Mock.Create<DiagramPanel>(Constructor.Mocked);
            Mock.Arrange(() => DiagramPanel.GetParentPanel<DiagramPanel>(thumbMock)).Returns(panelMock);

            var panelDcMock = Mock.Create<DiagramViewModel>();
            Mock.Arrange(() => panelDcMock.Items).Returns(new Collection<IDiagramItemViewModel>());
            Mock.Arrange(() => panelMock.DataContext).Returns(panelDcMock);

            var connectionEndMock = Mock.Create<ExpressionConnectorViewModel>();
            Mock.Arrange(() => connectionEndMock.CreateConnectionTo(Arg.IsAny<IDiagramItemViewModel>())).CallOriginal();
            Mock.Arrange(() => connectionEndMock.CanConnectTo(Arg.IsAny<IDiagramItemViewModel>(), Arg.IsAny<ICollection<IDiagramItemViewModel>>())).Returns(ConnectivityState.Allow);
            Mock.Arrange(() => panelMock.GetViewModelByLocation<IDiagramItemViewModel>(Arg.IsAny<Point>())).Returns(connectionEndMock);

            privateAccessor.SetField("_isDragging", true);

            //Act
            privateAccessor.CallMethod("OnMouseLeftButtonUp", Mock.Create<MouseButtonEventArgs>());

            //Assert
            IConnectionViewModel newConnection = null;

            try
            {
                newConnection = panelDcMock.Items.ToList()[0] as IConnectionViewModel;
            }
            catch (Exception)
            {                
                Assert.Fail("No connections where created");
                return;
            }

            Assert.AreEqual(1, panelDcMock.Items.Count);

            if (newConnection != null)
            {
                Assert.AreEqual(connectionEndMock, newConnection.Source);
                Assert.AreEqual(dcMock, newConnection.Destination);
            }
            else
                Assert.Fail("Type of the object does not inherit IConnectionViewModel");
        }
        public void GetTitleTests()
        {
            // arrange
            var vm = NewAccountListViewModel();

            // act
            var privateAccessor = new PrivateAccessor(vm);
            var result = privateAccessor.CallMethod("GetTitle");

            // assert
            Assert.AreEqual("Account Management", result);
        }
        public void Child_Update_test()
        {
            // Arrange
            var mockedClass = Mock.Create<ConnectionSetupEdit>(Behavior.CallOriginal);
            var setup = Mock.Create<IConnectionsSetupDAL>();

            Mock.Arrange(() => setup.UpdateConnectionSetup(Arg.IsAny<ConnectionSettingsDto>())).DoNothing();
            Mock.Arrange(() => mockedClass.ConnectionsSetupDAL).Returns(setup);
            // Act
            var inst = new PrivateAccessor(mockedClass);
            inst.CallMethod("Child_Update");
        }
        public void TestFieldDefaultValues()
        {
            var vm = new GageRRFieldViewModel();
            var privateAccessor = new PrivateAccessor(vm);

            Assert.IsNull(privateAccessor.GetField("_detailsViewModel"));
            Assert.IsNull(privateAccessor.GetField("_settingsPropertyName"));
            Assert.IsNull(privateAccessor.GetField("_sourceProcessName"));

            Assert.IsNull(privateAccessor.GetField("_msaResults"));
            Assert.IsNull(privateAccessor.GetField("_dataGroupingItem"));
            Assert.IsNull(privateAccessor.GetField("_showItemSelectorCommand"));
        }
 public void TestFunctionGetCategoryTask()
 {
     Mock.Arrange(() => Application.Current.Dispatcher.InvokeAsync(null))
         .IgnoreArguments().DoNothing();
     var viewModel = Mock.Create<QueueNoteTaskViewModel>(Behavior.CallOriginal);
     Mock.Arrange(() => QueueAssignmentFunctions.GetCategoryTaskActivity())
         .Returns(FakeData.FakeSelectList());
     Mock.SetupStatic(typeof(CollectionsQueueSettingsFunctions), StaticConstructor.Mocked);
     Mock.Arrange(() => CollectionsQueueSettingsFunctions.ReadCollectionSystemDefaultAsync())
         .Returns(FakeData.FakesCollectionDefault());
     var inst = new PrivateAccessor(viewModel);
     inst.CallMethod("GetCategoryTask");
     Assert.IsNotNull(viewModel.ListCategory);
 }
        public void ConstructorTest()
        {
            var stepEditMock = Mock.Create<GageRROptionsStepEdit>(Constructor.Mocked, Behavior.Loose);
            stepEditMock.SampleFilterDefinition = "FilterDefinition";            

            var vm = new GageRROptionsStepViewModel(stepEditMock, null, null);
            Assert.IsNotNull(vm.AvailableProcesses);
            Assert.IsNotNull(vm.SelectedProcessAvailableFields);
            Assert.IsNotNull(vm.AnswerProcessAvailableFields);
            Assert.AreEqual(vm.FilterDefinition, "FilterDefinition");

            var privateAccessor = new PrivateAccessor(vm);
            Assert.IsTrue((bool)privateAccessor.GetField("_isLoading"));
        }
        public void IsDropDownOpen_WhenSetToTrue_CreatesSelectorView()
        {
            //Arrange
            var crossRef = new FieldSingleCrossRef();

            //Act
            crossRef.IsDropDownOpen = true;

            //Assert
            var inst = new PrivateAccessor(crossRef);
            var d = inst.GetField("selectorView");

            Assert.IsNotNull(d);
        }
        public void AssignItemsSourceFirstTest()
        {
            var spreadsheet = new SpreadsheetView();
            var spreadsheetData = new List<TestData>
            {
                new TestData{Text = "string1", FractionalNumber = 10.0},
                new TestData{Text = "string2", FractionalNumber = 20.0},
                new TestData{Text = "test text", FractionalNumber = 30.2}
            };

            var privateAccessor = new PrivateAccessor(spreadsheet);

            //By default ItemsSource of SpreadsheetView is null
            Assert.IsNull(spreadsheet.ItemsSource);

            Mock.NonPublic.Arrange<SpreadsheetView>("OnItemsSourceChanged", ArgExpr.IsAny<DependencyObject>(), ArgExpr.IsAny<DependencyPropertyChangedEventArgs>())
                          .CallOriginal()
                          .MustBeCalled();
            spreadsheet.ItemsSource = spreadsheetData;
            Assert.AreEqual(spreadsheet.ItemsSource, spreadsheetData);
            Mock.NonPublic.Assert<SpreadsheetView>("OnItemsSourceChanged", ArgExpr.IsAny<DependencyObject>(), ArgExpr.IsAny<DependencyPropertyChangedEventArgs>());

            //FillItemsSource must be called from OnApplyTemplate if it hasn't been invoked yet 
            Mock.NonPublic.Assert(spreadsheet, "FillItemsSource", Occurs.Never(), ArgExpr.IsAny<IEnumerable>());
            Assert.IsFalse((bool)privateAccessor.GetField("_templateApplied"));

            //We've set SpreadsheetView.ItemsSource but ItemsControl.ItemsSource is still null
            var itemsControl = spreadsheet as ItemsControl;
            Assert.IsNull(itemsControl.ItemsSource);

            //Invoke OnApplyTemplate manually
            spreadsheet.OnApplyTemplate();
            Mock.NonPublic.Assert(spreadsheet, "FillItemsSource", Occurs.Once(), ArgExpr.IsAny<IEnumerable>());
            Assert.IsTrue((bool)privateAccessor.GetField("_templateApplied"));

            //FillItemsSource calls PopulateColumns
            Mock.NonPublic.Assert(spreadsheet, "PopulateColumns", Occurs.Once(), ArgExpr.IsAny<SpreadsheetElementCollection>());

            //Now ItemsControl.ItemsSource has value as well
            Assert.IsNotNull(itemsControl.ItemsSource);
            Assert.AreEqual(itemsControl.ItemsSource.GetType(), typeof(SpreadsheetElementCollection));

            //SpreadsheetView.ItemsCollection has only getter which retrieves data from ItemsControl.ItemsSource and casts it to SpreadsheetElementCollection
            Assert.AreEqual(itemsControl.ItemsSource, spreadsheet.ItemsCollection);

            //Assure that all our elements are there
            Assert.AreEqual(((IList)spreadsheet.ItemsSource).Count, spreadsheetData.Count);
            Assert.AreEqual(((IList)itemsControl.ItemsSource).Count, spreadsheetData.Count);
        }
        public void Execute()
        {
            // arrange
            var rule = new RichTextMaxLengthRule(null, 0);
            var privateAccessor = new PrivateAccessor(rule);

            // act
            try
            {
                privateAccessor.CallMethod("Execute", new object[] { null });
            }
            catch (Exception ex)
            {
                // assert
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }

            // arrange
            var property = Mock.Create<IPropertyInfo>(Behavior.RecursiveLoose);

            var context = Mock.Create<RuleContext>(Constructor.Mocked, Behavior.CallOriginal);
            Mock.Arrange(() => context.InputPropertyValues).Returns(new Dictionary<IPropertyInfo, object>
                {
                    { property, string.Empty }
                });

            rule.PrimaryProperty = property;

            var ruleWasThrown = false;
            Mock.Arrange(() => context.AddErrorResult(Arg.IsAny<IPropertyInfo>(), Arg.AnyString)).DoInstead(() => ruleWasThrown = true);

            // act
            privateAccessor.CallMethod("Execute", new object[] { context });

            // assert
            Assert.IsFalse(ruleWasThrown);

            // arrange
            Mock.Arrange(() => context.InputPropertyValues).Returns(new Dictionary<IPropertyInfo, object>
                {
                    { property, "Hello World!" + Constants.InvokeRichTextMaxLengthRule }
                });

            // act
            privateAccessor.CallMethod("Execute", new object[] { context });

            // assert
            Assert.IsTrue(ruleWasThrown);
        }
        public void InvokeConstructorTest()
        {
            //Mock spreadsheet
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => spreadsheetMock.GetTopLevelSpreadsheet()).CallOriginal();

            //Call constructor
            var container = new SpreadsheetItemContainer(spreadsheetMock);
            var privateAccessor = new PrivateAccessor(container);

            //Assert fields and properties
            Assert.AreEqual(privateAccessor.GetField("_owner"), spreadsheetMock);
            Assert.AreEqual(container.TopLevelSpreadsheet, spreadsheetMock);
            Assert.IsNotNull(container.Cells);
        }
Exemple #21
0
        public void FlushQueueTest()
        {
            var hid = Mock.Create<Hid>(Behavior.CallOriginal);
            const string Method = "FlushQueue";
            var iscalled = false;

            Mock.NonPublic.Arrange(hid, Method, ArgExpr.IsAny<IntPtr>()).DoInstead(
                () =>
                {
                    iscalled = true;
                });

            var inst = new PrivateAccessor(hid);
            inst.CallMethod(Method, new IntPtr());

            Assert.IsTrue(iscalled);
        }
        public void GiveFeedbackHandler_Cursors_NoneTest()
        {
            var mainMenu = new MainMenuMetroView();

            var arg = Mock.Create<GiveFeedbackEventArgs>(Behavior.RecursiveLoose);
            arg.SetCursor(Cursors.None);


            Mock.Arrange(() => arg.Effects).Returns(DragDropEffects.None);

            // act
            var privateAccessor = new PrivateAccessor(mainMenu);

            privateAccessor.CallMethod("GiveFeedbackHandler", new object[] { null, arg });

            Assert.IsTrue(arg.Handled);
            Assert.IsTrue(arg.Effects == DragDropEffects.None);
        }
 public void TestGetClientFinancialAsync_OnstepAsync_EnumStepsStart()
 {
     GeneralThreadAffineContext.Run(
         async () =>
             {
                 Mock.Arrange(() => Application.Current.Dispatcher.InvokeAsync(null))
                     .IgnoreArguments()
                     .DoNothing();
                 var viewModel = Mock.Create<CollectionsManagementViewModel>(Behavior.CallOriginal);
                 viewModel.ClientFinancials = FakeData.FakeDropdownLists();
                 Mock.SetupStatic(typeof(QueueManagmentFunctions), StaticConstructor.Mocked);
                 Mock.Arrange(() => QueueManagmentFunctions.GetClientFinancialsAsync())
                     .Returns(FakeData.FakeSystemConstant());
                 var inst = new PrivateAccessor(viewModel);
                 await Task.WhenAll(inst.CallMethod("GetClientFinancialAsync") as Task);
                 Assert.AreEqual(3, viewModel.ClientFinancials.Count);
             });
 }
        public void IsSelectedPropertyTests()
        {
            var tvrs = new TreeViewRequiredStepEdit { DisplayFields = new TreeViewDisplayFields() };
            var tree = new TreeViewRequiredStepViewModel(tvrs, new StepInfo(), new ProcessFieldViewModel(new FieldEdit(), new ProcessSectionViewModel(new SectionEdit())));

            // Arrange
            var mockedClass = Mock.Create<TreeViewDisplayFieldViewModel>(Behavior.Loose);

            Mock.NonPublic.Arrange<ITreeViewRequiredStepViewModel>(mockedClass, "ParentStepViewModel").Returns(tree);

            // Act
            var inst = new PrivateAccessor(mockedClass);
            inst.SetProperty("IsSelected", true);

            var vm = inst.GetProperty("ParentStepViewModel");
            // Assert
            Assert.IsNotNull(vm);
        }
Exemple #25
0
        public void DisplayExceptionTest()
        {
            var hid = Mock.Create<Hid>(Behavior.CallOriginal);
            const string Method = "DisplayException";

            var iscalled = false;

            Mock.NonPublic.Arrange(hid, Method, new[] { ArgExpr.IsAny<string>(), ArgExpr.IsAny<Exception>() }).DoInstead(
                () =>
                {
                    iscalled = true;
                });

            var inst = new PrivateAccessor(hid);

            inst.CallMethod(Method, new object[] { "test", new Exception("test") });

            Assert.IsTrue(iscalled);
        }
        public void SupportedExtensions()
        {
            // arrange
            var command = Mock.Create<InsertImageToRichtextCommand>(Constructor.Mocked, Behavior.CallOriginal);
            var list = new List<string>
            {
                ".bmp",
                ".jpg",
                ".jpeg",
                ".png"
            };

            // act
            var privateAccessor = new PrivateAccessor(command);
            var result = privateAccessor.GetField("SupportedExtensions");

            // assert
            CollectionAssert.AreEqual(list, (ICollection)result);
        }
        public void Execute_WhenCalledWithEmptyList_AddsErrorResult()
        {
            // arrange
            var rule = new ApprovalLevelsRequiredRule(ApprovalOptionsStepEdit.LevelDefinitionsProperty);

            var context = Mock.Create<RuleContext>(Constructor.Mocked, Behavior.CallOriginal);
            Mock.Arrange(() => context.InputPropertyValues)
                .Returns(new Dictionary<IPropertyInfo, object> { { ApprovalOptionsStepEdit.LevelDefinitionsProperty, new List<string>{}}});
            var ruleWasThrown = false;
            Mock.Arrange(() => context.AddErrorResult(Arg.AnyString)).DoInstead(() => ruleWasThrown = true);


            //Act
            var privateAccessor = new PrivateAccessor(rule);
            privateAccessor.CallMethod("Execute", new object[] { context });

            // assert
            Assert.IsTrue(ruleWasThrown);
        }
        public void AddDestinationVersionFieldsTest()
        {
            // Arrange.
            var vm = new ExpressionDesignerWindowViewModelBase();
            var accessor = new PrivateAccessor(vm);

            var processInfo = Mock.Create<PublishedProcessInfo>();
            Mock.Arrange(() => processInfo.ProcessOption).Returns(ProcessOption.VersionEnabled);

            var destination = new DestinationFieldList();

            // Act.
            accessor.CallMethod("AddVersionFields", processInfo, destination);

            // Assert.
            Assert.AreEqual(3, destination.Fields.Count);

            var versionNumber = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionNumber);
            var versionDate = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionDate);
            var versionMasterId = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionMasterId);

            Assert.IsNotNull(versionNumber);
            Debug.Assert(versionNumber != null, "versionNumber != null");
            Assert.AreEqual(NodeDataType.String, versionNumber.DataType);
            Assert.AreEqual(Constants.VersionNumberName, versionNumber.Name);
            Assert.AreEqual(Constants.VersionNumber, versionNumber.InnerName);
            Assert.AreEqual(Constants.VersionNumber, versionNumber.SystemName);

            Assert.IsNotNull(versionDate);
            Debug.Assert(versionDate != null, "versionDate != null");
            Assert.AreEqual(NodeDataType.DateTime, versionDate.DataType);
            Assert.AreEqual("Version Date", versionDate.Name);
            Assert.AreEqual(Constants.VersionDate, versionDate.InnerName);
            Assert.AreEqual(Constants.VersionDate, versionDate.SystemName);

            Assert.IsNotNull(versionMasterId);
            Debug.Assert(versionMasterId != null, "versionMasterId != null");
            Assert.AreEqual(NodeDataType.Int, versionMasterId.DataType);
            Assert.AreEqual("Version Master Id", versionMasterId.Name);
            Assert.AreEqual(Constants.VersionMasterId, versionMasterId.InnerName);
            Assert.AreEqual(Constants.VersionMasterId, versionMasterId.SystemName);
        }
        public void TestCollectionQueue_QueueNameAndAssignment_NotEmpty()
        {
            Mock.Arrange(() => Application.Current.Dispatcher.InvokeAsync(null))
                .IgnoreArguments()
                .DoNothing();
            var viewModel = Mock.Create<EditQueueViewModel>(
                Behavior.CallOriginal,
                new CollectionsManagementViewModel());
            viewModel.SelectedQueue = FakeData.FakeQueueDetailModel();
            Mock.Arrange(() => viewModel.SelectedQueue.CollectionQueue).Returns(FakeData.FakeCollectionQueue());

            Mock.Arrange(() => viewModel.HasErrors).Returns(true);

            var inst = new PrivateAccessor(viewModel);
            inst.CallMethod("Validate");

            var vali = new PrivateAccessor(viewModel);
            var faile = vali.GetField("_Failures") as List<ValidationFailure>;

            Assert.IsNotNull(faile);
            Assert.AreEqual(2, faile.Count);
        }
        public void RefreshTests()
        {
            // arrange
            var vm = new SelectPersonViewModel();

            var getFilterWasCalled = false;
            Mock.NonPublic.Arrange<MobileObservableCollection<IFilterDescriptor>>(vm, "GetFilter").DoInstead(() => getFilterWasCalled = true);

            var dynamicTypeManager = Mock.Create<IDynamicTypeManager>(Behavior.CallOriginal);

            Mock.Arrange(() => dynamicTypeManager.GetCustomType(Constants.AccountProcessName, "LinkablePersonList", true))
                .DoInstead(() => Assert.IsTrue(vm.IsBusy))
                    .Returns(typeof(object));

            vm.TheDynamicTypeManager = dynamicTypeManager;

            var account = Mock.Create<IAccount>(Behavior.Loose);
            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_selectedAccount", account);

            var basePersonList = Mock.Create<IList>(Behavior.Loose);

            Mock.Arrange(() => MethodCaller.CallFactoryMethod(Arg.IsAny<Type>(), "Get__AccountLinkablePersonListAsync", Arg.AnyInt, Arg.IsAny<int?>(), Arg.IsAny<PagedCriteria>()))
                .Returns(() =>
                    {
                        var tcs = new TaskCompletionSource<IList>();
                        tcs.SetResult(basePersonList);
                        return tcs.Task;
                    });

            // act
            privateAccessor.CallMethod("Refresh");

            // assert
            Assert.IsTrue(getFilterWasCalled);
            Assert.AreEqual(basePersonList, vm.PersonList);
            Assert.IsFalse(vm.IsBusy);
        }