public void GetSettingsShouldGenerateCampaingUrlWithScCampParameter()
        {
            // Arrange
            A.CallTo(() => _linkManager.GetItemUrl(A<Item>.Ignored, A<UrlOptions>.Ignored))
                .Returns("http://host/path?sneaky=parameter");

            A.CallTo(() => _pageContext.Item)
                .Returns(new TestItem());

            var rendering = new Sitecore.Mvc.Presentation.Rendering();
            rendering.Parameters["Goal"] = "TestGoal";
            rendering.Parameters["EventName"] = "TestEvent";
            var campaignId = ID.NewID;
            rendering.Parameters["Campaign"] = campaignId.ToString();
            A.CallTo(() => _renderingContext.Rendering)
                .Returns<Sitecore.Mvc.Presentation.Rendering>(rendering);

            // Act
            var settings = _settingsProvider.GetSettings();

            NameValueCollection query = null;
            Uri uri = null;
            if (Uri.TryCreate(settings.CampaignQueryString, UriKind.RelativeOrAbsolute, out uri))
            {
                query = HttpUtility.ParseQueryString(uri.Query);
            }

            // Assert
            Assert.NotNull(uri);
            Assert.NotNull(query);
            Assert.Contains<string>("sc_camp", query.AllKeys);
            Assert.True(ShortID.IsShortID(query["sc_camp"]), "sc_camp must be a ShortID");
            Assert.Equal<ID>(ShortID.Parse(query["sc_camp"]).ToID(), campaignId);
        }
        public void GenericConnectorShouldReturnViewResult()
        {
            //Arrange
            var rendering = new Sitecore.Mvc.Presentation.Rendering();
            rendering.Parameters["NetworkName"] = "SocialNetworkName";
            A.CallTo(() => renderingContext.Rendering)
                .Returns<Sitecore.Mvc.Presentation.Rendering>(rendering);

            var user = new TestUser(true);
            A.CallTo(() => authenticationManager.GetActiveUser())
                .Returns<User>(user);

            //Act
            var result = controller.GenericConnector() as ViewResult;

            //Assert
            Assert.NotNull(result);
        }
        public void GetSettingsShouldGenerateValidCampaingUrl()
        {
            // Arrange
            A.CallTo(() => _linkManager.GetItemUrl(A<Item>.Ignored, A<UrlOptions>.Ignored))
                .Returns("http://host/path?sneaky=parameter");

            A.CallTo(() => _pageContext.Item)
                .Returns(new TestItem());

            var rendering = new Sitecore.Mvc.Presentation.Rendering();
            rendering.Parameters["Goal"] = "TestGoal";
            rendering.Parameters["EventName"] = "TestEvent";
            rendering.Parameters["Campaign"] = ID.NewID.ToString();
            A.CallTo(() => _renderingContext.Rendering)
                .Returns<Sitecore.Mvc.Presentation.Rendering>(rendering);

            // Act
            var settings = _settingsProvider.GetSettings();

            // Assert
            Assert.True(Uri.IsWellFormedUriString(settings.CampaignQueryString, UriKind.RelativeOrAbsolute));
        }
        public void TwitterTweetShouldPopulateViewbag()
        {
            //Arrange
            var rendering = new Sitecore.Mvc.Presentation.Rendering();
            rendering.Parameters["NetworkName"] = "SocialNetworkName";
            A.CallTo(() => renderingContext.Rendering)
                .Returns<Sitecore.Mvc.Presentation.Rendering>(rendering);

            var user = new TestUser(true);
            A.CallTo(() => authenticationManager.GetActiveUser())
                .Returns<User>(user);

            var testItem = new TestItem();
            A.CallTo(() => pageContext.Item)
                .Returns(testItem);

            //Act
            var result = controller.TwitterTweet() as ViewResult;

            //Assert
            Assert.NotNull(result.ViewBag.ItemId);
            Assert.NotNull(result.ViewBag.EventName);
            Assert.NotNull(result.ViewBag.EventUrl); ;
            Assert.NotNull(result.ViewBag.GoalName);
            Assert.NotNull(result.ViewBag.CampaignQueryString);
            Assert.NotNull(result.ViewBag.SharePageUrl);
        }
        public void FacebookLikeShouldReturnViewResult()
        {
            //Arrange
            var rendering = new Sitecore.Mvc.Presentation.Rendering();
            rendering.Parameters["NetworkName"] = "SocialNetworkName";
            A.CallTo(() => renderingContext.Rendering)
                .Returns<Sitecore.Mvc.Presentation.Rendering>(rendering);

            var user = new TestUser(true);
            A.CallTo(() => authenticationManager.GetActiveUser()).Returns<User>(user);

            A.CallTo(() => linkManager.GetDefaultUrlOptions())
                .Returns(new Sitecore.Links.UrlOptions());
            A.CallTo(() => linkManager.GetItemUrl(A<Item>.Ignored))
                .Returns("http://host/path");

            A.CallTo(() => pageContext.Item)
                .Returns(new TestItem());


            //Act
            var result = controller.FacebookLike() as ViewResult;

            //Assert
            Assert.NotNull(result);
        }