// Part 1 - The Controller Site
// Installed pacakages are DotnetOpenAuth.Aspnet, Microsoft.AspNet.WebPages.OAuth
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DotNetOpenAuth.AspNet.Clients;
using Microsoft.Web.WebPages.OAuth;
namespace MvcApplication2.Controllers
{
public class HomeController : Controller
{
private static Dictionary<string, AuthenticationClientData> _authenticationClients = new Dictionary<string, AuthenticationClientData>(StringComparer.OrdinalIgnoreCase);
public ActionResult Index()
{
var client = new GoogleOpenIdClient();
var clientData = new AuthenticationClientData(client,
"Google", new Dictionary<string, object>());
if (_authenticationClients.Any(q => q.Key == client.ProviderName) == false)
_authenticationClients.Add(client.ProviderName, clientData);
return Content("Success");
}
}
}
// Part 2 - The Test Site
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MvcApplication2.Controllers;
namespace MvcApplication2.Tests
{
[TestClass]
public class ControllerTest
{
[TestMethod()]
public void should_return_not_empty_content()
{
var controller = new HomeController();
var result = controller.Index() as ContentResult;
Assert.IsNotNull(result.Content);
}
}
}