Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Added unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvanhunen committed Sep 1, 2015
1 parent 5bd8cd0 commit 3a9446e
Show file tree
Hide file tree
Showing 11 changed files with 989 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -197,6 +197,9 @@ UpgradeLog*.htm
# Microsoft Fakes
FakesAssemblies/

# App.Config files
[Aa]pp.[Cc]onfig

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

Expand Down
26 changes: 26 additions & 0 deletions OfficeDevPnP.PowerShell.sln
Expand Up @@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "OfficeDevPnP.PowerShell.Setup", "Setup\OfficeDevPnP.PowerShell.Setup.wixproj", "{17C05F96-5D99-4367-AB05-7C07D2570F08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfficeDevPnP.PowerShell.Tests", "Tests\OfficeDevPnP.PowerShell.Tests.csproj", "{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,6 +120,30 @@ Global
{17C05F96-5D99-4367-AB05-7C07D2570F08}.Release15|Mixed Platforms.Build.0 = Release|x86
{17C05F96-5D99-4367-AB05-7C07D2570F08}.Release15|x86.ActiveCfg = Release|x86
{17C05F96-5D99-4367-AB05-7C07D2570F08}.Release15|x86.Build.0 = Release|x86
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|x86.ActiveCfg = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug|x86.Build.0 = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|Any CPU.ActiveCfg = Debug15|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|Any CPU.Build.0 = Debug15|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|Mixed Platforms.Build.0 = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|x86.ActiveCfg = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Debug15|x86.Build.0 = Debug|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|Any CPU.Build.0 = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|x86.ActiveCfg = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release|x86.Build.0 = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|Any CPU.ActiveCfg = Release15|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|Any CPU.Build.0 = Release15|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|Mixed Platforms.ActiveCfg = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|Mixed Platforms.Build.0 = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|x86.ActiveCfg = Release|Any CPU
{AD2E3CF9-65C7-40FD-9F52-CE8259031C6E}.Release15|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
54 changes: 54 additions & 0 deletions Tests/AdminTests.cs
@@ -0,0 +1,54 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Management.Automation.Runspaces;

namespace OfficeDevPnP.PowerShell.Tests
{
[TestClass]
public class GetTenantSiteTests
{
[TestMethod]
public void GetTenantSiteTest()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-SPOTenantSite");

Assert.IsTrue(results.Count > 0);
}
}

[TestMethod]
public void GetTimeZoneIdTest1()
{
using (var scope = new PSTestScope(false))
{
var results = scope.ExecuteCommand("Get-SPOTimeZoneId");
Assert.IsTrue(results.Count > 0);
}
}

[TestMethod]
public void GetTimeZoneIdTest2()
{
using (var scope = new PSTestScope(false))
{
var results = scope.ExecuteCommand("Get-SPOTimeZoneId", new CommandParameter("Match", "Stockholm"));

Assert.IsTrue(results.Count == 1);
}
}

[TestMethod]
public void GetWebTemplatesTest()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-SPOWebTemplates");

Assert.IsTrue(results.Count > 0);
Assert.IsTrue(results[0].BaseObject.GetType().Equals(typeof(Microsoft.Online.SharePoint.TenantAdministration.SPOTenantWebTemplate)));
}
}
}
}
82 changes: 82 additions & 0 deletions Tests/App.config.sample
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="pnp">
<section
name="tracing"
type="OfficeDevPnP.Core.Diagnostics.LogConfigurationTracingSection, OfficeDevPnP.Core"
allowLocation="true"
allowDefinition="Everywhere"
/>
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<pnp>
<tracing logLevel="Debug">
<logger type="OfficeDevPnP.Core.Diagnostics.TraceLogger, OfficeDevPnP.Core, Culture=neutral, PublicKeyToken=null" />
</tracing>
</pnp>
<appSettings>
<!-- For Office 365 MT sites are https://[tenant]-admin.sharepoint.com and https://[tenant].sharepoint.com/sites/dev, for on-premises
you can any Developer site collection (e.g https://sp.contoso.com/sites.dev). For tenant adminstration you'll need to specify the
site collection you've marked as tenant administrator. This site collection must be in the same web app as the Developer site. See
http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx
for more details on how to setup a tenant administration site in on-premises.
-->
<add key="SPOTenantUrl" value="https://[tenant]-admin.sharepoint.com" />
<add key="SPODevSiteUrl" value="https://[tenant].sharepoint.com/sites/dev" />

<add key="SPOCredentialManagerLabel" value=""/>
<!-- If the above value is specified, a lookup will be done to the Windows Credential
manager for a -Windows- Credential that maps to the label. If not specified, it assumes you want to specify on
of the below options. Value will be taken based on the what's entered in this order:
1. O365 username/pwd
2. On-premises username/pwd
3. App only (O365 & On-premises)
-->

<!-- Priority 1: For testing against Office 365 provide a username and password -->
<add key="SPOUserName" value="user@[tenant].onmicrosoft.com" />
<add key="SPOPassword" value="" />

<!-- Priority 2: For testing against on-premises provide a username, domain and password -->
<add key="OnPremUserName" value="user" />
<add key="OnPremDomain" value="domain" />
<add key="OnPremPassword" value="" />

<!-- Priority 3: For app only testing provide a realm, app id and app secret -->
<add key="Realm" value="a6623c9e-30c7-493b-87bc-d907df44a26e" />
<add key="AppId" value="b5bdf20c-2917-5178-3309-5deb57ee6c89" />
<add key="AppSecret" value="" />

<!-- Permission XML for app only test
<AppPermissionRequests AllowAppOnlyPolicy="true" >
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/taxonomy" Right="Write" />
<AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
</AppPermissionRequests>
-->

<!-- Support for Azure based testing -->
<add key="AzureStorageKey" value="" />

</appSettings>
<system.diagnostics>
<sharedListeners>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" />
</sharedListeners>
<sources>
<source name="OfficeDevPnP.Core" switchValue="Verbose" >
<listeners>
<add name="console" />
</listeners>
</source>
</sources>
<trace indentsize="0" autoflush="true">
<listeners>
<add name="console" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
40 changes: 40 additions & 0 deletions Tests/BaseTests.cs
@@ -0,0 +1,40 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Management.Automation.Runspaces;
using System.Management.Automation;
using System.Collections.ObjectModel;
using OfficeDevPnP.PowerShell.Commands.Base;
using OfficeDevPnP.PowerShell.Tests;
using System.Configuration;

namespace OfficeDevPnP.PowerShell.Tests
{
[TestClass]
public class BaseTests
{
[TestMethod]
public void ConnectSPOnlineTest1()
{
using (var scope = new PSTestScope(false))
{
var results = scope.ExecuteCommand("Connect-SPOnline", new CommandParameter("Url", ConfigurationManager.AppSettings["SPODevSiteUrl"]));
Assert.IsTrue(results.Count == 0);
}
}

[TestMethod]
public void ConnectSPOnlineTest2()
{
using (var scope = new PSTestScope(true))
{
var results = scope.ExecuteCommand("Get-SPOContext");

Assert.IsTrue(results.Count == 1);
Assert.IsTrue(results[0].BaseObject.GetType() == typeof(Microsoft.SharePoint.Client.ClientContext));

}
}


}
}

0 comments on commit 3a9446e

Please sign in to comment.