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 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);
        }
        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 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);
        }
Example #5
0
        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 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 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 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);
 }
Example #10
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 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);
             });
 }
Example #12
0
        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);
        }
Example #13
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 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);
        }
Example #18
0
        public void UnselectMethodTest()
        {
            var spreadsheetMock = new SpreadsheetView();
            var privateAccessor = new PrivateAccessor(spreadsheetMock);

            //Load data            
            Mock.NonPublic.Arrange(typeof(CellBase), "SetEditorParams").IgnoreInstance().DoNothing();
            spreadsheetMock.ItemsSource = new List<TestData> { new TestData { Text = "text 1" }, new TestData { Text = "another text" } };
            spreadsheetMock.OnApplyTemplate();
            var item1 = spreadsheetMock.ItemsCollection[0];
            var item2 = spreadsheetMock.ItemsCollection[1];

            //Call ItemContainerGenerator overrides
            var container = privateAccessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;
            Assert.IsNotNull(container);
            spreadsheetMock.ItemContainerStyle = new Style(typeof(SpreadsheetItemContainer));
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container, item1);
            privateAccessor.CallMethod("PrepareContainerForItemOverride", (SpreadsheetItemContainer)null, item2);

            //Unselect cells from local spreadsheet
            Mock.Arrange(() => spreadsheetMock.Unselect(Arg.IsAny<CellBase>(), Arg.IsAny<SpreadsheetView>()));
            Mock.Arrange(() => container.Unselect(Arg.IsAny<CellBase>())).IgnoreInstance().OccursOnce();
            var cell = Mock.Create<CellBase>(Constructor.Mocked, Behavior.Loose);
            spreadsheetMock.Unselect(cell);
            Mock.Assert(container);

            //Create child spreadsheets
            var childSpreadsheet1 = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => childSpreadsheet1.IsVisible).Returns(true);
            var childSpreadsheet2 = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => childSpreadsheet2.IsVisible).Returns(false);
            var childSpreadsheet3 = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => childSpreadsheet3.IsVisible).Returns(true);

            //Add child spreadsheets
            var childSpreadsheets = privateAccessor.GetField("_childSpreadsheets") as List<SpreadsheetView>;
            childSpreadsheets.Add(childSpreadsheet1);
            childSpreadsheets.Add(childSpreadsheet2);
            childSpreadsheets.Add(childSpreadsheet3);

            //Call method with child spreadsheets and with caller (the second argument)
            Mock.Arrange(() => spreadsheetMock.Unselect(Arg.IsAny<CellBase>(), Arg.IsAny<SpreadsheetView>())).CallOriginal();
            spreadsheetMock.Unselect(cell, childSpreadsheet1);
            Mock.Assert(() => childSpreadsheet1.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Never());
            Mock.Assert(() => childSpreadsheet2.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Never());
            Mock.Assert(() => childSpreadsheet3.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Once());

            //Call method with child spreadsheets
            Mock.Arrange(() => container.Unselect(Arg.IsAny<CellBase>())).IgnoreInstance().Occurs(2);
            spreadsheetMock.Unselect(cell);
            Mock.Assert(() => childSpreadsheet1.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Once());
            Mock.Assert(() => childSpreadsheet2.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Never());
            Mock.Assert(() => childSpreadsheet3.Unselect(cell, Arg.IsAny<SpreadsheetView>()), Occurs.Exactly(2));
        }
Example #19
0
        public void GetEditedCellsMethodTest()
        {
            //Mock spreadsheet
            var spreadsheetMock = new SpreadsheetView();
            var privateAccessor = new PrivateAccessor(spreadsheetMock);

            //Load data            
            Mock.NonPublic.Arrange(typeof(CellBase), "SetEditorParams").IgnoreInstance().DoNothing();
            spreadsheetMock.ItemsSource = new List<TestData> { new TestData { Text = "text 1" }, new TestData { Text = "another text" } };
            spreadsheetMock.OnApplyTemplate();
            var item1 = spreadsheetMock.ItemsCollection[0];
            var item2 = spreadsheetMock.ItemsCollection[1];

            //Call ItemContainerGenerator overrides
            var container = privateAccessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;
            Assert.IsNotNull(container);
            spreadsheetMock.ItemContainerStyle = new Style(typeof(SpreadsheetItemContainer));
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container, item1);
            privateAccessor.CallMethod("PrepareContainerForItemOverride", (SpreadsheetItemContainer)null, item2);

            //Assert _containersDict field
            var containersDict = privateAccessor.GetField("_containersDict") as Dictionary<IWrap, SpreadsheetItemContainer>;
            Assert.IsNotNull(containersDict);
            Assert.AreEqual(containersDict.Count, 2);
            Assert.IsTrue(containersDict.ContainsKey(item1));
            Assert.AreEqual(containersDict[item1], container);
            Assert.IsTrue(containersDict.ContainsKey(item2));
            Assert.IsNull(containersDict[item2]);

            //Assert cells
            Assert.IsNotNull(container.Cells);
            Assert.AreEqual(container.Cells.Count, 3);

            //Assert GetEditedCells call with only container from one of two elements and with no child spreadsheets
            var cell = container.Cells[1];
            Mock.Arrange(() => cell.IsEditMode).Returns(true);
            var editedCells = spreadsheetMock.GetEditedCells();
            Assert.AreEqual(editedCells.Count(), 1);
            Assert.AreEqual(editedCells[0], container.Cells[1]);

            //Add child spreadsheet
            var childSpreadsheet = new SpreadsheetView();
            var accessor = new PrivateAccessor(childSpreadsheet);
            childSpreadsheet.ItemsSource = new List<TestData> { new TestData { Text = "child item 1" }, new TestData { Text = "child item 2" } };
            childSpreadsheet.OnApplyTemplate();
            var item3 = childSpreadsheet.ItemsCollection[0];
            var item4 = childSpreadsheet.ItemsCollection[1];
            var childcontainer1 = accessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;
            var childcontainer2 = accessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;
            childSpreadsheet.ItemContainerStyle = new Style(typeof(SpreadsheetItemContainer));
            accessor.CallMethod("PrepareContainerForItemOverride", childcontainer1, item3);
            accessor.CallMethod("PrepareContainerForItemOverride", childcontainer2, item4);
            var cell2 = childcontainer1.Cells[1];
            Mock.Arrange(() => cell2.IsEditMode).Returns(true);
            var cell3 = childcontainer2.Cells[2];
            Mock.Arrange(() => cell3.IsEditMode).Returns(true);

            ((List<SpreadsheetView>)privateAccessor.GetField("_childSpreadsheets")).Add(childSpreadsheet);

            //Assert GetEditedCells call involving invisible child spreadsheet
            Mock.Arrange(() => childSpreadsheet.IsVisible).Returns(false);
            editedCells = spreadsheetMock.GetEditedCells();
            Assert.AreEqual(editedCells.Count(), 1);
            Assert.AreEqual(editedCells[0], container.Cells[1]);

            //Assert GetEditedCells call involving visible child spreadsheet
            Mock.Arrange(() => childSpreadsheet.IsVisible).Returns(true);
            editedCells = spreadsheetMock.GetEditedCells();
            Assert.AreEqual(editedCells.Count(), 3);
            Assert.AreEqual(editedCells[0], childcontainer1.Cells[1]);
            Assert.AreEqual(editedCells[1], childcontainer2.Cells[2]);
            Assert.AreEqual(editedCells[2], container.Cells[1]);
        }
Example #20
0
        public void OnItemsChangedItemReplaceTest()
        {
            var spreadsheet = new SpreadsheetView();
            var privateAccessor = new PrivateAccessor(spreadsheet);            

            //Create data
            var oldItem = ItemWrap.BuildNew(new TestData());
            var newItem = ItemWrap.BuildNew(new TestData());
            var oldContainer = new SpreadsheetItemContainer(spreadsheet);
            var newContainer = new SpreadsheetItemContainer(spreadsheet);

            //Prepare event arguments and container dictionary
            var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newItem, oldItem, 0);
            var containerDict = privateAccessor.GetField("_containersDict") as Dictionary<IWrap, SpreadsheetItemContainer>;
            containerDict.Add(oldItem, oldContainer);

            //Arrange methods
            Mock.Arrange(() => spreadsheet.ItemContainerGenerator.ContainerFromItem(newItem)).Returns(newContainer);
            Mock.NonPublic.Arrange(spreadsheet, "BindContainerToItem", newContainer, newItem).CallOriginal();

            //Call OnItemsChanged and Assert results
            privateAccessor.CallMethod("OnItemsChanged", args);
            Assert.AreEqual(containerDict.Count, 1);
            Assert.AreEqual(containerDict.First().Key, newItem);
            Assert.AreEqual(containerDict[newItem], newContainer);
            Mock.NonPublic.Assert(spreadsheet, "BindContainerToItem", Occurs.Once(), newContainer, newItem);
            Assert.IsTrue(oldContainer.IsDisposed);
        }
Example #21
0
        public void OnItemsChangedItemRemoveTest()
        {
            var spreadsheet = new SpreadsheetView();
            var privateAccessor = new PrivateAccessor(spreadsheet);

            //Initialize ItemCollection
            Mock.NonPublic.Arrange(spreadsheet, "OnItemsChanged", ArgExpr.IsAny<NotifyCollectionChangedEventArgs>()).DoNothing();
            var list = new List<TestData>
            {
                new TestData {Text = "fff", FractionalNumber = 0},
                new TestData {Text = "item", FractionalNumber = 55},
                new TestData {Text = "last item", FractionalNumber = -5}
            };
            spreadsheet.ItemsSource = list;
            spreadsheet.OnApplyTemplate();
            Assert.IsNotNull(spreadsheet.ItemsCollection);
            Mock.Reset();

            var item1 = spreadsheet.ItemsCollection[0];
            var item2 = spreadsheet.ItemsCollection[1];
            var item3 = spreadsheet.ItemsCollection[2];

            //Bind item1 to container
            var container = new SpreadsheetItemContainer(spreadsheet);
            Mock.NonPublic.Arrange(container, "InitializeCellsWithValues");
            privateAccessor.CallMethod("BindContainerToItem", container, item1);
            privateAccessor.CallMethod("BindContainerToItem", container, item3);

            //Assert dictionary with containers
            var containerDict = privateAccessor.GetField("_containersDict") as Dictionary<IWrap, SpreadsheetItemContainer>;
            Assert.IsNotNull(containerDict);
            Assert.AreEqual(containerDict.Count, 2);
            containerDict.Add(item2, null);
            Assert.AreEqual(containerDict.Count, 3);

            //Remove second item from collection (when container is null)
            Mock.Arrange(() => containerDict.Remove(item2)).CallOriginal();
            spreadsheet.ItemsCollection.Remove(item2);
            Mock.Assert(() => containerDict.Remove(item2), Occurs.Once());
            Assert.AreEqual(containerDict.Count, 2);

            //Remove first item from collection (when container is disposed)
            Mock.Arrange(() => container.IsDisposed).Returns(true);
            spreadsheet.ItemsCollection.Remove(item1);            
            Mock.Assert(() => containerDict.Remove(item1), Occurs.Once());
            Assert.AreEqual(containerDict.Count, 1);

            //Remove item and dispose container            
            Mock.Arrange(() => container.IsDisposed).Returns(false);            
            spreadsheet.ItemsCollection.Remove(item3);
            Mock.Assert(() => containerDict.Remove(item3), Occurs.Exactly(2));
            Assert.AreEqual(containerDict.Count, 0);
            Mock.Reset();
            Assert.IsTrue(container.IsDisposed);
        }
Example #22
0
        public void PrepareContainerForItemOverrideTest()
        {
            //Mock spreadsheet derived class
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked, Behavior.Loose);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);

            //Mock container and item
            var container = Mock.Create<SpreadsheetItemContainer>(Constructor.Mocked, Behavior.Loose);
            var item = ItemWrap.BuildNew(new TestData());

            //Arrange spreadsheet methods
            Mock.NonPublic.Arrange(spreadsheetMock, "PrepareContainerForItemOverride", ArgExpr.IsAny<DependencyObject>(), ArgExpr.IsAny<object>()).CallOriginal();

            //Arrange container methods
            Mock.Arrange(() => container.SetValue(Arg.IsAny<DependencyProperty>(), Arg.IsAny<object>()));

            //Call method to assert some invocations
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container, item);
            Mock.Assert(() => container.SetValue(Arg.IsAny<DependencyProperty>(), Arg.IsAny<object>()), Occurs.Never());
            Mock.NonPublic.Assert(spreadsheetMock, "BindContainerToItem", Occurs.Never(), ArgExpr.IsAny<SpreadsheetItemContainer>(), ArgExpr.IsAny<IWrap>());
            Mock.NonPublic.Assert(spreadsheetMock, "PopulateCells", Occurs.Never(), ArgExpr.IsAny<SpreadsheetItemContainer>(), ArgExpr.IsAny<IWrap>());

            spreadsheetMock.ItemContainerStyle = new Style(typeof(SpreadsheetItemContainer));
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container, item);
            Mock.Assert(() => container.SetValue(Arg.IsAny<DependencyProperty>(), Arg.IsAny<object>()), Occurs.Once());
            Mock.NonPublic.Assert(spreadsheetMock, "BindContainerToItem", Occurs.Once(), ArgExpr.IsAny<SpreadsheetItemContainer>(), ArgExpr.IsAny<IWrap>());
            Mock.NonPublic.Assert(spreadsheetMock, "PopulateCells", Occurs.Once(), ArgExpr.IsAny<SpreadsheetItemContainer>(), ArgExpr.IsAny<IWrap>());
        }
Example #23
0
        public void GetContainerForItemOverrideTest()
        {
            //Mock spreadsheet derived class
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);
            Mock.NonPublic.Arrange<DependencyObject>(spreadsheetMock, "GetContainerForItemOverride").CallOriginal();

            //Get new container
            var obj = privateAccessor.CallMethod("GetContainerForItemOverride") as DependencyObject;
            Assert.IsNotNull(obj);

            //Assert spreadsheet as container's owner
            var container = obj as SpreadsheetItemContainer;
            Assert.IsNotNull(container);
            Assert.IsNotNull(container.Owner);
            Assert.AreEqual(container.Owner.GetHashCode(), spreadsheetMock.GetHashCode());
        }
Example #24
0
        public void IsItemItsOwnContainerOverrideTest()
        {
            //Mock spreadsheet derived class
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);
            Mock.NonPublic.Arrange<bool>(spreadsheetMock, "IsItemItsOwnContainerOverride", ArgExpr.IsAny<object>()).CallOriginal();

            //Parameter is not of SpreadsheetItemContainer type
            var result = (bool)privateAccessor.CallMethod("IsItemItsOwnContainerOverride", new object());
            Assert.IsFalse(result);

            //Parameter is of SpreadsheetItemContainer type
            result = (bool)privateAccessor.CallMethod("IsItemItsOwnContainerOverride", new SpreadsheetItemContainer(spreadsheetMock));
            Assert.IsTrue(result);
        }
Example #25
0
        public void OnKeyDownTest()
        {
            //Create spreadsheet mock
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);
            Mock.NonPublic.Arrange(spreadsheetMock, "OnKeyDown", ArgExpr.IsAny<KeyEventArgs>()).CallOriginal();

            var args = Mock.Create<KeyEventArgs>();            
            args.Handled = false;

            //Tab to next cell
            Mock.Arrange(() => args.Key).Returns(Key.Tab);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.None);
            Mock.Arrange(() => spreadsheetMock.TabToNext()).Returns(true);
            privateAccessor.CallMethod("OnKeyDown", args);
            Mock.Assert(() => spreadsheetMock.TabToNext());
            Assert.IsTrue(args.Handled);

            //Tab to next cell (tab out of spreadsheet)
            args.Handled = false;
            Mock.Arrange(() => spreadsheetMock.TabToNext()).Returns(false);
            privateAccessor.CallMethod("OnKeyDown", args);
            Mock.Assert(() => spreadsheetMock.TabToNext());
            Assert.IsFalse(args.Handled);

            //Tab to previous cell
            args.Handled = false;
            Mock.Arrange(() => args.Key).Returns(Key.Tab);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.Shift);
            Mock.Arrange(() => spreadsheetMock.TabToPrevious()).Returns(true);
            privateAccessor.CallMethod("OnKeyDown", args);
            Mock.Assert(() => spreadsheetMock.TabToPrevious());
            Assert.IsTrue(args.Handled);

            //Tab to previous cell (tab out of spreadsheet)
            args.Handled = false;
            Mock.Arrange(() => spreadsheetMock.TabToPrevious()).Returns(false);
            privateAccessor.CallMethod("OnKeyDown", args);
            Mock.Assert(() => spreadsheetMock.TabToPrevious());
            Assert.IsFalse(args.Handled);

            //Bring out cell from edit mode
            Mock.Arrange(() => args.Key).Returns(Key.Escape);
            var cell1 = Mock.Create<Cell>(Constructor.Mocked);
            var cell2 = Mock.Create<StackCell>(Constructor.Mocked);
            Mock.Arrange(() => spreadsheetMock.GetSelectedCells()).Returns(new CellBase[] { cell1, cell2 });
            privateAccessor.CallMethod("OnKeyDown", args);
            Mock.Assert(() => cell1.SwitchEditMode(false), Occurs.Once());
            Mock.Assert(() => cell1.SwitchEditMode(false), Occurs.Once());
        }
Example #26
0
        public void OnKeyUpTest()
        {
            //Create spreadsheet mock and avoid KeyNavigationByDemand of being calculated
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);
            Mock.NonPublic.Arrange(spreadsheetMock, "OnKeyUp", ArgExpr.IsAny<KeyEventArgs>()).CallOriginal();
            Mock.Arrange(() => spreadsheetMock.KeyNavigationByDemand(Arg.IsAny<Key>(), false));

            //Fire KeyUp event with null argument
            var args = Mock.Create<KeyEventArgs>(Behavior.Loose);
            privateAccessor.CallMethod("OnKeyUp", (KeyEventArgs)null);
            Mock.Assert(() => spreadsheetMock.KeyNavigationByDemand(Arg.IsAny<Key>(), false), Occurs.Never());
            Assert.IsFalse(args.Handled);

            //Event args is not null and KeyNavigationByDemand method should be invoked
            privateAccessor.CallMethod("OnKeyUp", args);
            Mock.Assert(() => spreadsheetMock.KeyNavigationByDemand(Arg.IsAny<Key>(), false), Occurs.Once());
            Assert.IsTrue(args.Handled);

            //Don't call KeyNavigationByDemand if the key is Tab
            args.Handled = false;
            Mock.Arrange(() => args.Key).Returns(Key.Tab);
            privateAccessor.CallMethod("OnKeyUp", args);
            Mock.Assert(() => spreadsheetMock.KeyNavigationByDemand(Arg.IsAny<Key>(), false), Occurs.Once());
            Assert.IsTrue(args.Handled);

            //Or if Escape
            args.Handled = false;
            Mock.Arrange(() => args.Key).Returns(Key.Escape);
            privateAccessor.CallMethod("OnKeyUp", args);
            Mock.Assert(() => spreadsheetMock.KeyNavigationByDemand(Arg.IsAny<Key>(), false), Occurs.Once());
            Assert.IsTrue(args.Handled);
        }
Example #27
0
        public void SelectCellMethodTest()
        {
            //Mock spreadsheet
            var spreadsheetMock = Mock.Create<SpreadsheetView>(Constructor.Mocked);
            var privateAccessor = new PrivateAccessor(spreadsheetMock);

            //Container is null
            Mock.NonPublic.Arrange(spreadsheetMock, "SelectCell", ArgExpr.IsAny<IWrap>(), ArgExpr.IsAny<int>()).CallOriginal();
            Mock.Arrange(() => spreadsheetMock.GetContainerFromItem(Arg.IsAny<IWrap>())).Returns((SpreadsheetItemContainer)null);
            var info = privateAccessor.CallMethod("SelectCell", Arg.IsAny<IWrap>(), Arg.IsAny<int>()) as NavigationInfo;
            Assert.IsNotNull(info);
            Assert.AreEqual(info.ActionState, MoveStates.Fail);

            //Container is not null
            var container = Mock.Create<SpreadsheetItemContainer>(Constructor.Mocked);
            Mock.Arrange(() => container.SelectByIndex(3, Arg.IsAny<NavigationInfo>())).Returns(new NavigationInfo(CommandType.MoveDown, MoveStates.Ok)).MustBeCalled();
            Mock.Arrange(() => spreadsheetMock.GetContainerFromItem(Arg.IsAny<IWrap>())).Returns(container);
            info = privateAccessor.CallMethod("SelectCell", Arg.IsAny<IWrap>(), 3) as NavigationInfo;
            Assert.IsNotNull(info);
            Assert.AreEqual(info.Command, CommandType.MoveDown);
            Assert.AreEqual(info.ActionState, MoveStates.Ok);
            Mock.Assert(container);
        }
Example #28
0
        public void AlternateRowsMethodTest()
        {
            //Create spreadsheet and load data
            var spreadsheet = new SpreadsheetView();
            var privateAccessor = new PrivateAccessor(spreadsheet);
            var itemList = new List<TestData>
            {
                new TestData(),
                new TestData()     
            };
            spreadsheet.ItemsSource = itemList;
            spreadsheet.OnApplyTemplate();
            Mock.NonPublic.Arrange(typeof(SpreadsheetView), "PopulateCells", ArgExpr.IsAny<SpreadsheetItemContainer>(), ArgExpr.IsAny<IWrap>()).DoNothing();

            //Get item wrappers
            var item1 = spreadsheet.ItemsCollection[0];
            var item2 = spreadsheet.ItemsCollection[1];

            //Call ItemContainerGenerator overrides 
            Mock.NonPublic.Arrange(typeof(CellBase), "SetEditorParams").IgnoreInstance().DoNothing();
            spreadsheet.ItemContainerStyle = new Style(typeof(SpreadsheetItemContainer));
            var container1 = privateAccessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;            
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container1, item1);
            var container2 = privateAccessor.CallMethod("GetContainerForItemOverride") as SpreadsheetItemContainer;            
            privateAccessor.CallMethod("PrepareContainerForItemOverride", container2, item2);

            //Mock SetIsAlternate method for all SpreadsheetItemContainer instances
            var containerMock = Mock.Create<SpreadsheetItemContainer>(Constructor.Mocked);
            Mock.Arrange(() => containerMock.SetIsAlternate()).IgnoreInstance();            

            //Make spreadsheet invisible
            Mock.Arrange(() => spreadsheet.IsVisible).Returns(false);
            Mock.Arrange(() => spreadsheet.Items).CallOriginal().OccursNever();
            spreadsheet.AlternateRows();
            Mock.Assert(spreadsheet);

            //Test AlternateRows method in normal conditions
            Mock.Arrange(() => spreadsheet.IsVisible).Returns(true);
            Mock.Arrange(() => spreadsheet.Items).CallOriginal().MustBeCalled();
            spreadsheet.AlternateRows();
            var containersDict = privateAccessor.GetField("_containersDict") as Dictionary<IWrap, SpreadsheetItemContainer>;
            Mock.Assert(() => containersDict[item1].SetIsAlternate(), Occurs.Once());
            Mock.Assert(() => containersDict[item2].SetIsAlternate(), Occurs.Once());
            Mock.Assert(spreadsheet);
        }
        public void OnRefreshed()
        {
            // arrange
            var vm = new FrequencyPatternDetailsViewModel();

            var unitOfWork = Mock.Create<IUnitOfWork<IFrequencyPattern>>(Behavior.Loose);
            var model = Mock.Create<IFrequencyPattern>(Behavior.Loose);
            Mock.Arrange(() => model.IsNew).Returns(true);
            Mock.Arrange(() => unitOfWork.Model).Returns(model);

            var dataportalResult = new DataPortalResult<IUnitOfWork<IFrequencyPattern>>(unitOfWork, null, null);

            var shell = Mock.Create<IShell>(Behavior.CallOriginal);
            var baseMethodWasCalled = false;
            Mock.Arrange(() => shell.ShowStatus(Arg.IsAny<Status>(), false)).DoInstead(() => baseMethodWasCalled = true);
            vm.WindowManager = new Lazy<IShell>(() => shell);

            // act
            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.CallMethod("OnRefreshed", new object[] { null, dataportalResult });
            
            // assert
            Assert.AreEqual(model, vm.Model);
            Assert.AreEqual(FrequencyPatternType.Daily.ToString(), model.PatternType);

            // daily
            Assert.AreEqual(DailyPatternVariant.NumberOfDays.ToString(), model.DailyPatternOption);
            Assert.AreEqual(1, model.DailyPatternDaysToRecur);

            // weekly
            Assert.AreEqual(1, model.WeeklyPatternWeeksToRecur);
            Assert.AreEqual(false, model.IsSundaySelected);
            Assert.AreEqual(false, model.IsMondaySelected);
            Assert.AreEqual(false, model.IsTuesdaySelected);
            Assert.AreEqual(false, model.IsWednesdaySelected);
            Assert.AreEqual(false, model.IsThursdaySelected);
            Assert.AreEqual(false, model.IsFridaySelected);
            Assert.AreEqual(false, model.IsSaturdaySelected);

            // monthly
            Assert.AreEqual(MonthlyPatternVariant.DayByDate.ToString(), model.MonPatOption);
            Assert.AreEqual(1, model.MonPatRecurDate);
            Assert.AreEqual(1, model.MonPatByDateOptionMonthsToRec);
            Assert.AreEqual(TimeIntervalPosition.First.ToString(), model.MonPatTimeIntervalPosition);
            Assert.AreEqual(1, model.MonPatByPositionOptionMonToRec);
            Assert.AreEqual(1, model.MonPatMonthsToRec);
            Assert.AreEqual(DayofWeek.Saturday.ToString(), model.MonPatDayOfWeek);

            // yearly
            Assert.AreEqual(1, model.YearPatYearsToRec);
            Assert.AreEqual(YearlyPatternVariant.DayByDate.ToString(), model.YearPatOption);
            Assert.AreEqual(Month.January.ToString(), model.YearPatByDateOptionSelectMon);
            Assert.AreEqual(1, model.YearPatDayOfSelectMon);
            Assert.AreEqual(TimeIntervalPosition.First.ToString(), model.YearPatTimeIntervalPosition);
            Assert.AreEqual(DayofWeek.Saturday.ToString(), model.YearPatDayOfWeek);
            Assert.AreEqual(Month.January.ToString(), model.YearPatByNameOptionSelectMon);

            Assert.IsTrue(baseMethodWasCalled);

            // arrange
            baseMethodWasCalled = false;
            dataportalResult = new DataPortalResult<IUnitOfWork<IFrequencyPattern>>(null, new Exception(), null);

            var loggerWasCalled = false;
            var logger = new ClientLogger();
            Mock.Arrange(() => logger.Log(LogSeverity.Error, typeof(FrequencyPatternDetailsViewModel).ToString(), Arg.IsAny<Exception>())).DoInstead(() => loggerWasCalled = true);

            vm.Logger = logger;

            var popupMock = PopupMock.Create().NotifyFailureMustBeCalled(Arg.IsAny<Exception>());
            vm.ThePopupFactory = popupMock.TheLazyPopupFactory;

            // act
            privateAccessor.CallMethod("OnRefreshed", new object[] { null, dataportalResult });

            // assert
            Assert.IsTrue(loggerWasCalled);
            popupMock.AssertNotifyFailureCalled();
            Assert.IsTrue(baseMethodWasCalled);
        }
        public void GetTitle()
        {
            // arrange
            var vm = new FrequencyPatternDetailsViewModel();

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

            // assert
            Assert.AreEqual("Loading...", result);

            // arrange
            var fp = Mock.Create<IFrequencyPattern>(Behavior.CallOriginal);
            Mock.Arrange(() => fp.ProcessDisplayName).Returns("Frequency Pattern");
            Mock.Arrange(() => fp.IsNew).Returns(true);
            Mock.Arrange(() => vm.Model).Returns(fp);

            // act
            result = privateAccessor.CallMethod("GetTitle");

            // assert
            Assert.AreEqual("Details: Frequency Pattern (new)", result);

            // arrange
            Mock.Arrange(() => fp.Id).Returns(1);
            Mock.Arrange(() => fp.IsNew).Returns(false);

            // act
            result = privateAccessor.CallMethod("GetTitle");

            // assert
            Assert.AreEqual("Details: Frequency Pattern (1)", result);
        }