public void ProcessRequest_InvalidItemName_ReturnsEmptyResult(string itemName) { // arrange var blogManager = Mock.Of <IBlogManager>(); var itemManager = Mock.Of <BaseItemManager>(); var sut = new NewEntry(blogManager, itemManager, Mock.Of <IBlogSettingsResolver>()); sut.RequestContext = new ItemContext { Argument = itemName }; // act var result = sut.ProcessRequest(); // assert Assert.That(result.Value, Is.Null); }
public void ProcessRequest_ContextItemUnderBlog_CreatesEntryItem() { // arrange var entryTemplateId = ID.NewID; var contextItem = ItemFactory.CreateItem().Object; var blogItem = ItemFactory.CreateItem().Object; var weblogSettings = Mock.Of <IWeBlogSettings>(x => x.EntryTemplateIds == new[] { entryTemplateId }); var blogManager = Mock.Of <IBlogManager>(x => x.GetCurrentBlog(contextItem) == (BlogHomeItem)blogItem ); var newItem = ItemFactory.CreateItem().Object; var itemManager = new Mock <BaseItemManager>(); itemManager.Setup(x => x.AddFromTemplate("entry", entryTemplateId, blogItem)).Returns(newItem).Verifiable(); var settingsResolver = Mock.Of <IBlogSettingsResolver>(x => x.Resolve(It.IsAny <BlogHomeItem>()) == new BlogSettings(weblogSettings)); var sut = new NewEntry(blogManager, itemManager.Object, settingsResolver); var context = new ItemContext { Argument = "entry" }; context.PopulateContextData(contextItem, Mock.Of <RenderingParametersResolver>()); sut.RequestContext = context; // act var result = sut.ProcessRequest(); // assert itemManager.Verify(); var id = GetItemIdFromAnonymousResult(result.Value); Assert.That(id, Is.EqualTo(newItem.ID.Guid)); }
public void ProcessRequest_ContextItemNotUnderBlog_DoesNotCreateAnyItems() { // arrange var contextItem = ItemFactory.CreateItem().Object; var blogManager = Mock.Of <IBlogManager>(); var itemManager = new Mock <BaseItemManager>(); var sut = new NewEntry(blogManager, itemManager.Object, Mock.Of <IBlogSettingsResolver>()); var context = new ItemContext { Argument = "entry" }; context.PopulateContextData(contextItem, Mock.Of <RenderingParametersResolver>()); sut.RequestContext = context; // act var result = sut.ProcessRequest(); // assert itemManager.Verify(x => x.AddFromTemplate(It.IsAny <string>(), It.IsAny <ID>(), It.IsAny <Item>()), Times.Never); }