CommentApiControllerTests.cs :  » Bloggers » SubText » UnitTests » Subtext » SubtextWeb » Controllers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » UnitTests » Subtext » SubtextWeb » Controllers » CommentApiControllerTests.cs
using System;
using System.Xml;
using MbUnit.Framework;
using Moq;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Services;
using Subtext.Web.Controllers;

namespace UnitTests.Subtext.SubtextWeb.Controllers{
    [TestFixture]
    public class CommentApiControllerTests
    {
        [Test]
        public void CtorSetsCommentService()
        {
            // arrange
            ICommentService service = new Mock<ICommentService>().Object;
            ISubtextContext subtextContext = new Mock<ISubtextContext>().Object;

            // act
            var controller = new CommentApiController(subtextContext, service);

            // assert
            Assert.AreSame(service, controller.CommentService);
        }

        [Test]
        public void CreateWithNullXmlThrowsInvalidOperationException()
        {
            // arrange
            ICommentService service = new Mock<ICommentService>().Object;
            ISubtextContext subtextContext = new Mock<ISubtextContext>().Object;
            var controller = new CommentApiController(subtextContext, service);

            // act, assert
            UnitTestHelper.AssertThrowsArgumentNullException(() => controller.Create(1, null));
        }

        [Test]
        public void CreatePassesFeedbackItemToService()
        {
            // arrange
            var service = new Mock<ICommentService>();
            var subtextContext = new Mock<ISubtextContext>();

            FeedbackItem comment = null;
            service.Setup(s => s.Create(It.IsAny<FeedbackItem>(), It.IsAny<bool>())).Callback<FeedbackItem, bool>((f, b) => comment = f);
            var controller = new CommentApiController(subtextContext.Object, service.Object);
            string xmlText =
                @"<?xml version=""1.0""?>
                            <item>
                                <title>Haack's Wild Ride</title>
                                <description>This tests the CommentAPI</description>
                                <author>Me</author>
                                <link>http://subtextproject.com/</link>
                            </item>";
            var doc = new XmlDocument();
            doc.LoadXml(xmlText);

            // act
            controller.Create(123, doc);

            // assert
            Assert.IsNotNull(comment);
            Assert.AreEqual("Haack's Wild Ride", comment.Title);
            Assert.AreEqual("This tests the CommentAPI", comment.Body);
            Assert.AreEqual("Me", comment.Author);
            Assert.AreEqual("http://subtextproject.com/", comment.SourceUrl.ToString());
        }

        [Test]
        public void CreateMissingAuthorDoesNotThrowException()
        {
            // arrange
            var service = new Mock<ICommentService>();
            var subtextContext = new Mock<ISubtextContext>();

            FeedbackItem comment = null;
            service.Setup(s => s.Create(It.IsAny<FeedbackItem>(), It.IsAny<bool>())).Callback<FeedbackItem, bool>((f, b) => comment = f);
            var controller = new CommentApiController(subtextContext.Object, service.Object);
            const string xmlText = @"<?xml version=""1.0""?>
                            <item>
                                <title>Haack's Wild Ride</title>
                                <description>This tests the CommentAPI</description>
                                <link>http://subtextproject.com/</link>
                            </item>";
            var doc = new XmlDocument();
            doc.LoadXml(xmlText);

            // act
            controller.Create(123, doc);

            // assert
            Assert.IsNotNull(comment);
            Assert.AreEqual("Haack's Wild Ride", comment.Title);
            Assert.AreEqual("This tests the CommentAPI", comment.Body);
            Assert.AreEqual(string.Empty, comment.Author);
            Assert.AreEqual("http://subtextproject.com/", comment.SourceUrl.ToString());
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.