public void GetPageModel_PassInDocTypeAlias_CurrentPageNotExist_ShouldGetFirstNodeOfDocTypeAliasAndReturnPageModelWithInfoOfThatNode()
        {
            // Arrange
            const string docTypeAlias = "testAlias";

            var applicationService = new ApplicationService(QueryFactoryMock.Object, UmbracoContextFactoryMock.Object,
                                                            UmbracoHelperFactoryMock.Object, PublishedContentExtensionsWrapperFactoryMock.Object);

            var nodeMock = new Mock <INode>();

            nodeMock.Setup(x => x.NodeTypeAlias).Returns(docTypeAlias);
            QueryFactoryMock.Setup(x => x.GetCurrentNode()).Returns((INode)null);
            QueryFactoryMock.Setup(x => x.GetFirstNodeOfType(docTypeAlias)).Returns(nodeMock.Object);

            var stubModel = new StubModel();

            PublishedContentExtensionsWrapperMock.Setup(x => x.As <StubModel>(nodeMock.Object.Id)).Returns(stubModel);

            // Act
            var result = applicationService.GetPageModel <StubModel>(docTypeAlias);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(stubModel, result);
        }
        public void GetPageModel_PassInDocumentTypeAlias_PageNodeNotExist_ThrowNullException()
        {
            // Arrange
            const string docTypeAlias = "testAlias";

            var applicationService = new ApplicationService(QueryFactoryMock.Object, UmbracoContextFactoryMock.Object,
                                                            UmbracoHelperFactoryMock.Object, PublishedContentExtensionsWrapperFactoryMock.Object);

            QueryFactoryMock.Setup(x => x.GetCurrentNode()).Returns((INode)null);
            QueryFactoryMock.Setup(x => x.GetFirstNodeOfType(docTypeAlias)).Returns((INode)null);

            // Assert
            Assert.Throws <NullReferenceException>(() => applicationService.GetPageModel <StubModel>(docTypeAlias));
        }
        public void GetNode_PassInDocumentTypeAlias_NodeExists_ReturnsNode()
        {
            // Arrange
            const string docTypeAlias       = "testAlias";
            var          applicationService = new ApplicationService(QueryFactoryMock.Object, UmbracoContextFactoryMock.Object,
                                                                     UmbracoHelperFactoryMock.Object, PublishedContentExtensionsWrapperFactoryMock.Object);

            var mockNewsletterFolderNode = new Mock <INode>();

            QueryFactoryMock.Setup(x => x.GetFirstNodeOfType(docTypeAlias)).Returns(mockNewsletterFolderNode.Object);

            // Act
            var result = applicationService.GetNode(docTypeAlias);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(mockNewsletterFolderNode.Object, result);
        }
        public override void SetUpConfig()
        {
            _getByIdQueryMock  = new Mock <GetByIdQuery>();
            _getAllQueryMock   = new Mock <GetAllQuery>();
            _createCommandMock = new Mock <CreateCommand>();
            _updateCommandMock = new Mock <UpdateCommand>();
            _deleteCommandMock = new Mock <DeleteCommand>();

            QueryFactoryMock.Setup(query => query.CreateQuery <GetByIdQuery>()).Returns(_getByIdQueryMock.Object);
            QueryFactoryMock.Setup(query => query.CreateQuery <GetAllQuery>()).Returns(_getAllQueryMock.Object);
            CommandFactoryMock.Setup(command => command.CreateCommand <CreateCommand>()).Returns(_createCommandMock.Object);
            CommandFactoryMock.Setup(command => command.CreateCommand <UpdateCommand>()).Returns(_updateCommandMock.Object);
            CommandFactoryMock.Setup(command => command.CreateCommand <DeleteCommand>()).Returns(_deleteCommandMock.Object);

            _controller = new VehiclesController(
                QueryFactoryMock.Object,
                CommandFactoryMock.Object);
        }