SharePoint Dragons

Nikander & Margriet on SharePoint

Microsoft Fakes: building a shim for the SharePoint 2013 SSOM

We were building a mail class used by SharePoint solutions that leverages the SmtpClient class because SPUtility.SendEmail() is too limited in some ways:

  1. It doesn’t send attachments.
  2. It contains a max of 2048 chars per line, although this can be circumvented by adding line breaks (‘\n’).

More about those limitations over here: http://sharepointdragons.com/2012/05/21/sputility-sendemail-limit/

However, we did want to use the SSOM to determine the SMTP server that should send the e-mail messages for us. We could do it like so:

System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(objWeb.Site.WebApplication.OutboundMailServiceInstance.Server.Address);

But in this case, we went for this solution:

SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;

This resulted in the following method implementation in our custom SharePoint library is a class called Manager:

public string GetSmtpServer()
{
return Microsoft.SharePoint.Administration.SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
}

Very simple. Then, we decided we needed to add some unit testing. If you have VS.NET Ultimate, you can consider using Microsoft.SharePoint.Emulators. We gave it a spin and weren’t that happy with it. At some point, we had to uninstall the package, switch the project to x86, install the emulator again, and switch back to x64, and more stuff like that. But apparently it can be done, according to: http://writeabout.net/2014/06/21/spemulators-available-on-nuget/ , so don’t let us stop you from checking it out!

Then, we were considering other Mocking frameworks (Typemock Isolator, JustMock, Microsoft Fakes) and decided to go with Fakes because of monetary reasons. We then added a unit test project ( VS.NET 2012 > Add > New Project > Unit Test Project), added a reference to our custom SharePoint libary, right-clicked it and chose Add Fakes Assembly.

If you want to know more about Fakes, check out http://msdn.microsoft.com/en-us/library/hh549176.aspx . Basically, it allows you to replace methods and properties during run time with your own implementation.

Because our custom SharePoint library uses the SPS 2013 SSOM it’s built for 64 bit, which required us to change the unit test project to 64 bit too (right-click unit test project > Properties > Build > Platform target: x64). That is not all, you also need to set the Test processor architecture to 64 bit, like so: VS.NET 2012 > TEST > Test Settings > Default Processor Architecture > X64.

When that is done, the unit test project is able to call the SharePoint custom library and we were able to create a shim for our GetSMTPServer() method., which goes something like this:

[TestMethod]
public void GetSmtpServerReturnsFakeName()
{
using (ShimsContext.Create())
{
MyLib.Fakes.ShimManager.AllInstances.GetSmtpServer = (@this) => { return ”mySMTPServer”; };
Manager man = new Manager();

// returns mySMTPServer
string smtpServer = man.GetSmtpServer();
}
}

Smartphone simulators

To test the mobile view functionality in SharePoint 2013, we needed some smartphone emulators. Here’s what we came up with…

This web-based iPhone simulator is quite nice: http://iphone4simulator.com/

For the iPhone, there’s also a commercial product which is easy to use and has a trial version. It can be found at http://www.electricplum.com/studio.aspx

For the Windows Phone, you need to download the SDK at http://dev.windows.com/en-us/develop/download-phone-sdk , which uses Visual Studio (2012) and the presence of Hyper-V. This emulator itself can’t run on a virtual machine (although we’ve seen posts that say VMWare 9 can do it).

For Android, check out http://developer.android.com/sdk/index.html

Browser shots

Great URL for browser compatibility testing: http://browsershots.org/.

Project Adam

Project Adam is a new deep-learning system modeled after the human brain that has greater image classification accuracy and is 50 times faster than other systems in the industry. Watch this video: http://research.microsoft.com/apps/video/default.aspx?id=220709. You should also take a look at: http://research.microsoft.com/en-us/news/features/dnnvision-071414.aspx.

SSIS Package In Visual Studio 2012: Designer View suddenly gone

Have you ever experienced that the Designer View of an SSIS package in Visual Studio is suddenly completely empty while all the underlying XML is all gone? It had us puzzled, but it was solved by closing all packages in VS (just click the X’s) and then re-opening the package.

Apparently the UI of SSIS is not all fine and dandy, we found this post to be of interest too: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/3dc85f3c-59b7-4671-9894-e12ef2680d27/ssis-package-when-opened-in-designer-shows-nothing-because-it-is-scrolled-to-bottom-right-where?forum=sqlintegrationservices.

SPServices

An interesting library based on jQuery that makes working with SharePoint’s web services easier: http://spservices.codeplex.com/.

Wiki World Cup

Trying to follow the success of the Dutch soccer team, Margriet’s latest TechNet Wiki blog post proposes a new team line-up: http://blogs.technet.com/b/wikininjas/archive/2014/06/29/wiki-world-cup.aspx

Kill table lock

Found a table that was locked during an ETL process. Retrieved the culprit session via:

select * from sys.dm_exec_requests cross apply sys.dm_exec_sql_text([sql_handle]) where blocking_session_id = 0

Then, killed it like this:

KILL([session id])

And the ETL process is free to try again!

Setting another application pool for PowerPivot using PowerShell

The title says it all:

# Change application pool for specific service application
$appPool = Get-SPServiceApplicationPool | where { $_.Name -eq “SharePoint – PowerPivot Application Pool” }

$serviceApp = Get-SPServiceApplication -Name “ODH PowerPivot Service Application”
$serviceApp.ApplicationPool = $appPool
$serviceApp.Update()

Setting up a sharepoint 2013 dev environment

We’ve updated the Reporting Services (SSRS) section of this TechNet Wiki article: http://social.technet.microsoft.com/wiki/contents/articles/15289.sharepoint-2013-creating-a-development-environment.aspx , so check it out!

Follow

Get every new post delivered to your Inbox.

Join 642 other followers