Exemplo n.º 1
0
        protected virtual Dictionary <string, object> CreateModel(WorkflowPipelineArgs args)
        {
            var modelArgs = new PopulateScribanMailActionModelArgs(args);

            PipelineManager.Run(PopulateModelPipelineName, modelArgs);
            return(modelArgs.GetModel());
        }
        public void GetModelByKey_ObjectNotPresent_ReturnsNull()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            // act
            var result = sut.GetModel("key");

            // assert
            Assert.IsNull(result);
        }
        public void GetModelByKey_KeyIsInvalid_ReturnsNull(string key)
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            // act
            var result = sut.GetModel(key);

            // assert
            Assert.IsNull(result);
        }
        public void GetModel_NothingSet_ReturnsEmptyDictionary()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            // act
            var result = sut.GetModel();

            // assert
            Assert.That(result, Is.Empty);
        }
        public void GetModelByKey_StringObjectIsPresent_ReturnsObject()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            sut.AddModel("key", "value");

            // act
            var result = sut.GetModel("key");

            // assert
            Assert.That(result, Is.EqualTo("value"));
        }
        public void GetModelByKey_ObjectIsPresent_ReturnsObject()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut   = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var value = new Tuple <string, int, DateTime>("item1", 42, DateTime.Today);

            sut.AddModel("key", value);

            // act
            var result = sut.GetModel("key");

            // assert
            Assert.That(result, Is.EqualTo(value));
        }
Exemplo n.º 7
0
        public void Process_WhenCalled_AddsDataItem()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddDataItem();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddDataItem.ModelKey);

            Assert.That(value, Is.SameAs(workflowPipelineArgs.DataItem));
        }
        public void Process_WhenCalled_AddsCurrentTimestamp()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddCurrentTimestamp();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddCurrentTimestamp.ModelKey);

            Assert.That(value, Is.EqualTo(DateTime.Now).Within(TimeSpan.FromSeconds(1)));
        }
Exemplo n.º 9
0
        public void Process_WhenCalled_AddsUser()
        {
            // arrange
            var user = User.FromName("sitecore\\user", false);
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddUser(user);

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddUser.ModelKey);

            Assert.That(value, Is.EqualTo(user));
        }
Exemplo n.º 10
0
        public void Process_EntryItemIsNotNull_AddsUpdatedByUser()
        {
            // arrange
            var(sut, dataItem) = CreateAddEntryModels();
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItem);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            args.EntryItem = new EntryItem(dataItem);

            // act
            sut.Process(args);

            // assert
            var updatedBy = args.GetModel(AddEntryModels.UpdatedByModelKey);

            Assert.That(((UserProfile)updatedBy).Name, Is.EqualTo(UserName));
        }
Exemplo n.º 11
0
        public void Process_EntryItemIsNotNull_AddsEntry()
        {
            // arrange
            var(sut, dataItem) = CreateAddEntryModels();
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItem);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            args.EntryItem = new EntryItem(dataItem);

            // act
            sut.Process(args);

            // assert
            var entry = args.GetModel(AddEntryModels.EntryModelKey);

            Assert.That(((EntryItem)entry).ID, Is.EqualTo(dataItem.ID));
        }
Exemplo n.º 12
0
        public void Process_CommentItemIsNotNull_AddsComment()
        {
            // arrange
            var dataItemMock         = ItemFactory.CreateItem();
            var sut                  = new AddComment();
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItemMock.Object);
            var args                 = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            args.CommentItem = new CommentItem(dataItemMock.Object);

            // act
            sut.Process(args);

            // assert
            var comment = args.GetModel(AddComment.ModelKey);

            Assert.That(((CommentItem)comment).ID, Is.EqualTo(dataItemMock.Object.ID));
        }
Exemplo n.º 13
0
        public void Process_WhenCalled_AddsSite()
        {
            // arrange
            var siteInfo = new SiteInfo(new StringDictionary());
            var site     = new SiteContext(siteInfo);

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddSite(site);

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddSite.ModelKey);

            Assert.That(value, Is.EqualTo(site));
        }
        public void Process_ItemHasWorkflowHistory_AddsWorkflowHistory()
        {
            // arrange
            var dataItemMock   = ItemFactory.CreateItem();
            var workflowEvents = AddItemHistory(dataItemMock, new[] { ID.NewID, ID.NewID });

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItemMock.Object);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddWorkflowHistory();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddWorkflowHistory.ModelKey);

            Assert.That((WorkflowEvent[])value, Is.EquivalentTo(workflowEvents));
        }
        public void Process_ItemHasNoWorkflowHistory_HistoryObjectIsEmpty()
        {
            // arrange
            var dataItemMock = ItemFactory.CreateItem();

            AddItemHistory(dataItemMock, new ID[0]);

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItemMock.Object);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddWorkflowHistory();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddWorkflowHistory.ModelKey);

            Assert.That((WorkflowEvent[])value, Is.Empty);
        }
Exemplo n.º 16
0
        public void Process_WhenCalled_AddsActionDefinitionItem()
        {
            // arrange
            var actionItem           = ItemFactory.CreateItem();
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();

            workflowPipelineArgs.ProcessorItem = actionItem.Object;

            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddActionItem();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddActionItem.ModelKey);

            Assert.That(((ProcessorItem)value).ID, Is.EqualTo(actionItem.Object.ID));
        }
        public void Process_NextStatePresent_AddsState()
        {
            // arrange
            var actionItem = CreateWorkflowItems();

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();

            workflowPipelineArgs.ProcessorItem = new ProcessorItem(actionItem);

            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddNextWorkflowState();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddNextWorkflowState.ModelKey);

            Assert.That(value, Is.EqualTo("next state"));
        }
        public void Process_ItemHasNoWorkflow_HistoryObjectIsEmpty()
        {
            // arrange
            var dataItemMock = ItemFactory.CreateItem();
            var itemState    = new Mock <ItemState>(dataItemMock.Object);

            dataItemMock.Setup(x => x.State).Returns(itemState.Object);

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItemMock.Object);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddWorkflowHistory();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddWorkflowHistory.ModelKey);

            Assert.That((WorkflowEvent[])value, Is.Empty);
        }
        public void GetModel_ObjectsSet_ReturnsDictionary()
        {
            // arrange
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();
            var sut = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            sut.AddModel("key1", "value1");
            sut.AddModel("key2", "value2");

            // act
            var result = sut.GetModel();

            // assert
            Assert.That(result, Is.EquivalentTo(
                            new Dictionary <string, object>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            }
                            ));
        }
Exemplo n.º 20
0
        public void Process_BlogPresent_AddsBlog()
        {
            // arrange
            var blogItem = ItemFactory.CreateItem();
            var settings = Mock.Of <IWeBlogSettings>();

            var blogManager = Mock.Of <IBlogManager>(x =>
                                                     x.GetCurrentBlog(It.IsAny <Item>()) == new BlogHomeItem(blogItem.Object)
                                                     );

            var sut = new AddBlog(blogManager);
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(blogItem.Object);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddBlog.ModelKey);

            Assert.That(((BlogHomeItem)value).ID, Is.EqualTo(blogItem.Object.ID));
        }
        public void Process_NoNextState_AddsEmptyString()
        {
            // arrange
            var commandItem = ItemFactory.CreateItem();
            var actionItem  = ItemFactory.CreateItem();

            actionItem.Setup(x => x.Parent).Returns(commandItem.Object);

            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs();

            workflowPipelineArgs.ProcessorItem = actionItem.Object;

            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);
            var sut  = new AddNextWorkflowState();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddNextWorkflowState.ModelKey);

            Assert.That(value, Is.Empty);
        }
Exemplo n.º 22
0
        public void Process_WhenCalled_AddsState()
        {
            // arrange
            var dataItem             = ItemFactory.CreateItem();
            var workflowPipelineArgs = WorkflowPipelineArgsFactory.CreateWorkflowPipelineArgs(dataItem.Object);
            var args = new PopulateScribanMailActionModelArgs(workflowPipelineArgs);

            var workflowState = new WorkflowState(ID.NewID.ToString(), "state", "icon", true);
            var itemState     = new Mock <ItemState>(dataItem.Object);

            itemState.Setup(x => x.GetWorkflowState()).Returns(workflowState);

            dataItem.Setup(x => x.State).Returns(itemState.Object);

            var sut = new AddWorkflowState();

            // act
            sut.Process(args);

            // assert
            var value = args.GetModel(AddWorkflowState.ModelKey);

            Assert.That(value, Is.SameAs(workflowState));
        }