Ejemplo n.º 1
0
        public void GetDueDateTest()
        {
            var actionHelper = CreateActionHelper();
            const string dueDateFieldName = "DueDate";

            var dueDate = actionHelper.GetDueDate(Mock.Create<IApprovalActionDefinition>(), Mock.Create<IEditableRoot>());

            Assert.AreEqual(DateTime.MinValue, dueDate);

            var itemMock = new DynamicMock();

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);
            
            itemMock.DueDate = new DateTime(2012, 1, 16);

            var actionMock = Mock.Create<IAssignmentActionDefinition>();

            Mock.Arrange(() => actionMock.DueDateFieldName).Returns(dueDateFieldName);

            dueDate = actionHelper.GetDueDate(actionMock, itemMock);

            Assert.AreEqual(itemMock.DueDate, dueDate);

            itemMock.DueDate = null;

            dueDate = actionHelper.GetDueDate(actionMock, itemMock);

            Assert.AreEqual(DateTime.MinValue, dueDate);
        }
Ejemplo n.º 2
0
        public void CreateActionItemInfoTest()
        {
            const int ActionItemId = 123;
            var actionGuid = new Guid("03C09D58-F670-41C2-8E69-750F0A5CB2DF");
            const string Process = "test process";
            const int ItemId = 555;
            const int PersonId = 111;
            const bool IsActionNew = true;
            const int ItemStateId = 2;
            const string ApprovalFieldName = "approvalFieldName";
            const string ActionName = "Action Name";
            const string GroupName = "Group Name";
            const string FirstName = "First Name";
            const string LastName = "Last Name";
            var dueDate = new DateTime(2012, 1, 16);
            var expectedSubject = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", FirstName, dueDate, "<Blocked Content>");
            var expectedMessage = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", FirstName, dueDate, "&lt;Blocked Content&gt;");

            var actionHelper = CreateActionHelper();
            var actionItemMock = Mock.Create<IActionItemInfo>();

            Mock.Arrange(() => actionItemMock.Id).Returns(ActionItemId);
            Mock.Arrange(() => actionItemMock.ActionGuid).Returns(actionGuid.ToString());
            Mock.Arrange(() => actionItemMock.Process).Returns(Process);
            Mock.Arrange(() => actionItemMock.ItemId).Returns(ItemId);
            Mock.Arrange(() => actionItemMock.PersonId).Returns(PersonId);
            Mock.Arrange(() => actionItemMock.IsActionNew).Returns(IsActionNew);
            Mock.Arrange(() => actionItemMock.ItemStateId).Returns(ItemStateId);

            var actionDefinitionMock = Mock.Create<IApprovalActionDefinition>();

            Mock.Arrange(() => actionDefinitionMock.ApprovalFieldName).Returns(ApprovalFieldName);
            Mock.Arrange(() => actionDefinitionMock.Guid).Returns(actionGuid);
            Mock.Arrange(() => actionDefinitionMock.Name).Returns(ActionName);
            Mock.Arrange(() => actionDefinitionMock.GroupName).Returns(GroupName);
            Mock.Arrange(() => actionDefinitionMock.GetSubject(Arg.IsAny<IEditableRoot>())).Returns(expectedSubject);
            Mock.Arrange(() => actionDefinitionMock.GetMessageForDashboard(Arg.IsAny<IEditableRoot>())).Returns(expectedMessage);

            var actionManagerMock = Mock.Create<IActionManager>();
            Mock.Arrange(() => actionManagerMock.ActionDefinitions).ReturnsCollection(new List<IActionDefinition> { actionDefinitionMock });
            Mock.Arrange(() => _dtm.GetActionManager(Process)).Returns(actionManagerMock);

            var itemMock = new DynamicMock { DueDate = dueDate, FirstName = FirstName, LastName = LastName, ActionManager = actionManagerMock };

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);

            var actionItemInfo = actionHelper.CreateActionItemInfo(actionItemMock, itemMock);

            Assert.AreEqual(ActionItemId, actionItemInfo.Id);
            Assert.AreEqual(actionGuid.ToString(), actionItemInfo.ActionGuid);
            Assert.AreEqual(ActionName, actionItemInfo.Name);
            Assert.AreEqual(expectedSubject, actionItemInfo.Subject);
            Assert.AreEqual(expectedMessage, actionItemInfo.Message);
            Assert.AreEqual(ActionTypes.Approval, actionItemInfo.ActionType);
            Assert.AreEqual(GroupName, actionItemInfo.GroupName);
            Assert.AreEqual(DateTime.MinValue, actionItemInfo.DueDate);
            Assert.AreEqual(IsActionNew, actionItemInfo.IsActionNew);
            Assert.AreEqual(Process, actionItemInfo.ProcessName);
            Assert.AreEqual(ItemId, actionItemInfo.ItemId);
        }
Ejemplo n.º 3
0
        public void ReplaceFileTest()
        {
            // Arrange.
            const string Template = "Prefix {File} suffix.";

            var file = Mock.Create<IFileProcess>(Behavior.Loose);
            Mock.Arrange(() => file.OriginalFileName).Returns("Test File <&>.txt");
            Mock.Arrange(() => file.FileName).Returns("abc.txt");

            var item = new DynamicMock { File = file };
            item.SetCanReadProperty(ReflectionHelper.GetPropertyName<DynamicMock>(x => x.File), true);

            Mock.Arrange(() => _fileHelper.GetFullNavigateUrl("abc.txt")).Returns("http://localhost/DocHandler.ashx?FileName=abc.txt");
            var actionHelper = CreateActionHelper();

            // Act.
            var textResult = actionHelper.ReplaceFieldsWithValues(Template, item);
            var htmlResult = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            // Assert.
            Assert.AreEqual("Prefix Test File <&>.txt suffix.", textResult);
            Assert.AreEqual(
                "Prefix <a href=\"http://localhost/DocHandler.ashx?FileName=abc.txt\" target=\"_blank\">Test File &lt;&amp;&gt;.txt</a> suffix.",
                htmlResult);
        }
Ejemplo n.º 4
0
        public void WhenSingleCrossReferenceIsBlocked_PrintBlockedContentMessage()
        {
            const string Template = "Test {CRField} Test";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} Test", "&lt;Blocked Content&gt;");

            var item = new DynamicMock();

            item.SetCanReadProperty("CRField", false);
            item.SetCanReadProperty("CRFieldMember", false);
            item.CRField = 3;

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void WhenSingleCrossReferenceFieldIsNull_UseEmptyString()
        {
            const string Template = "Test {CRField} Test";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test  Test");

            var item = new DynamicMock();

            item.SetCanReadProperty("CRField", true);
            item.SetCanReadProperty("CRFieldMember", true);
            item.CRField = null;

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void ReplaceSingleCrossReferenceFieldFromBaseProcess()
        {
            // Arrange.
            const string BaseProcessName = "BaseProcess";
            const string DerivedProcessName = "DerivedProcess";
            const string Template = "Test {CRField} Test";
            const string DisplayText = "683A5DEA-08F7-4741-A58B-432F81650152";
            const string Expected = "Test 683A5DEA-08F7-4741-A58B-432F81650152 Test";
            const int CRId = 11;

            var crItem = new CrossReferenceItem { __DisplayName = DisplayText };

            Mock.Arrange(() => _dtm.GetCrossReferenceItem(BaseProcessName, "CRField", CRId)).Returns(crItem);

            var actionHelper = CreateActionHelper();

            var baseEdit = new DynamicMock { ProcessName = BaseProcessName };
            baseEdit.SetCanReadProperty("CRField", true);
            baseEdit.CRField = CRId;
            var item = new DerivedDynamicMock { ProcessName = DerivedProcessName, BaseEdit = baseEdit };

            // Act.
            var result = actionHelper.ReplaceFieldsWithValues(Template, item, false);

            // Assert.
            Assert.AreEqual(Expected, result);
        }
Ejemplo n.º 7
0
        public void ReplaceFieldsWithValuesCanReplaceSingleCrossReferenceFields()
        {
            const string ProcessName = "processName";
            const string CRText = "test";
            const int CRNumber = 123;
            const int CRId = 11;
            const string Template = "Test {CRField} Test";

            var crDate = new DateTime(2012, 6, 5);
            var crDisplayText = string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}", CRText, CRNumber, crDate);
            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} Test", crDisplayText);
            var crItem = new DynamicCrossReferenceMock
                {
                    Id = CRId,
                    TextField = CRText,
                    NumericField = CRNumber,
                    DateField = crDate,
                    DisplayText = crDisplayText
                };

            var item = new DynamicMock {ProcessName = ProcessName};

            item.SetCanReadProperty("CRField", true);
            item.CRField = CRId;

            Mock.Arrange(() => _dtm.GetCrossReferenceItem(ProcessName, "CRField", CRId)).Returns(crItem);

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void ReplaceFieldsWithValuesTest()
        {
            var actionHelper = CreateActionHelper();
            const string Template = "Test {FirstName} {LastName} {DueDate} {FirstName}";

            var itemMock = new DynamicMock();

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);

            itemMock.DueDate = new DateTime(2012, 1, 16);
            itemMock.FirstName = "First Name";
            itemMock.LastName = "Last Name";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", itemMock.FirstName, itemMock.DueDate, "&lt;Blocked Content&gt;");

            var actual = actionHelper.ReplaceFieldsWithValues(Template, itemMock, true);

            Assert.AreEqual(expected, actual);
        }