Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DnnMvcModule/Components/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Dnn.Modules.DnnMvcModule.Components
{
interface IItemManager
public interface IItemManager
{
void CreateItem(Item t);
void DeleteItem(int itemId, int moduleId);
Expand Down
40 changes: 32 additions & 8 deletions src/DnnMvcModule/Controllers/ItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,46 @@ namespace Dnn.Modules.DnnMvcModule.Controllers
[DnnHandleError]
public class ItemController : DnnController
{
private int _moduleId = 0;

public ItemController(IItemManager mockManager, int moduleId)
{
ItemManager.SetTestableInstance(mockManager);
_moduleId = moduleId;
}

public ActionResult Delete(int itemId)
{
if (ModuleContext != null)
{
_moduleId = ModuleContext.ModuleId;
}
ItemManager.Instance.DeleteItem(itemId, ModuleContext.ModuleId);
return RedirectToDefaultRoute();
}

public ActionResult Edit(int itemId = -1)
{
DotNetNuke.Framework.JavaScriptLibraries.JavaScript.RequestRegistration(CommonJs.DnnPlugins);
try { DotNetNuke.Framework.JavaScriptLibraries.JavaScript.RequestRegistration(CommonJs.DnnPlugins); }
catch { }

if (PortalSettings != null)
{
var userlist = UserController.GetUsers(PortalSettings.PortalId);
var users = from user in userlist.Cast<UserInfo>().ToList()
select new SelectListItem { Text = user.DisplayName, Value = user.UserID.ToString() };

var userlist = UserController.GetUsers(PortalSettings.PortalId);
var users = from user in userlist.Cast<UserInfo>().ToList()
select new SelectListItem { Text = user.DisplayName, Value = user.UserID.ToString() };
ViewBag.Users = users;
}

ViewBag.Users = users;
if (ModuleContext != null)
{
_moduleId = ModuleContext.ModuleId;
}

var item = (itemId == -1)
? new Item { ModuleId = ModuleContext.ModuleId }
: ItemManager.Instance.GetItem(itemId, ModuleContext.ModuleId);
? new Item { ModuleId = _moduleId }
: ItemManager.Instance.GetItem(itemId, _moduleId);

return View(item);
}
Expand Down Expand Up @@ -68,7 +88,11 @@ public ActionResult Edit(Item item)
[ModuleAction(ControlKey = "Edit", TitleKey = "AddItem")]
public ActionResult Index()
{
var items = ItemManager.Instance.GetItems(ModuleContext.ModuleId);
if (ModuleContext != null)
{
_moduleId = ModuleContext.ModuleId;
}
var items = ItemManager.Instance.GetItems(_moduleId);
return View(items);
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/DnnMvcModule/DnnMvcModule.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DnnMvcModule", "DnnMvcModule.csproj", "{4130D773-4930-4C21-9BCF-0C5244F585D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DnnMvcModuleTests", "Tests\DnnMvcModuleTests.csproj", "{074D4D0C-7144-44D0-AE04-D7EB1A586950}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4130D773-4930-4C21-9BCF-0C5244F585D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4130D773-4930-4C21-9BCF-0C5244F585D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4130D773-4930-4C21-9BCF-0C5244F585D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4130D773-4930-4C21-9BCF-0C5244F585D0}.Release|Any CPU.Build.0 = Release|Any CPU
{074D4D0C-7144-44D0-AE04-D7EB1A586950}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{074D4D0C-7144-44D0-AE04-D7EB1A586950}.Debug|Any CPU.Build.0 = Debug|Any CPU
{074D4D0C-7144-44D0-AE04-D7EB1A586950}.Release|Any CPU.ActiveCfg = Release|Any CPU
{074D4D0C-7144-44D0-AE04-D7EB1A586950}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/DnnMvcModule/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DnnMvcModule")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
111 changes: 111 additions & 0 deletions src/DnnMvcModule/Tests/DnnMvcModuleTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{074D4D0C-7144-44D0-AE04-D7EB1A586950}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MyMvcModuleTests</RootNamespace>
<AssemblyName>MyMvcModuleTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DotNetNuke">
<HintPath>..\..\..\..\bin\DotNetNuke.dll</HintPath>
</Reference>
<Reference Include="DotNetNuke.Web.Mvc">
<HintPath>..\..\..\..\bin\DotNetNuke.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.5.23.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.5.23\lib\net45\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\bin\System.Web.Mvc.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="ItemControllerTests.cs" />
<Compile Include="Mocks\MockStores.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CompanyName_MyMvcModule.csproj">
<Project>{4130d773-4930-4c21-9bcf-0c5244f585d0}</Project>
<Name>CompanyName_MyMvcModule</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
29 changes: 29 additions & 0 deletions src/DnnMvcModule/Tests/ItemControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Web.Mvc;
using Dnn.Modules.CompanyName.MyMvcModule.Controllers;
using Dnn.Modules.CompanyName.MyMvcModule.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Dnn.Modules.DnnMvcModule.Testing.Mocks;

namespace Dnn.Modules.DnnMvcModule.Testing.UnitTests
{
[TestClass]
public class ItemControllerTests
{
[TestMethod]
public void Edit_CreateNewItem_ModuleIdAssignedinModel()
{
// 1 - Arrange
int moduleId = 2;
var mockData = MockStores.MockItemManager();
var modTwoItemCntrl = new ItemController(mockData.Object, moduleId); // Create controller for module Id 2

// 2 - Act
var actionResult = (ViewResult)modTwoItemCntrl.Edit(); // Call edit view with no item Id (Add New)

// 3 - Assert
var itemModel = (Item)actionResult.Model;
Assert.IsTrue(itemModel != null && itemModel.ModuleId == moduleId);
}
}
}
53 changes: 53 additions & 0 deletions src/DnnMvcModule/Tests/Mocks/MockStores.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using Dnn.Modules.DnnMvcModule.MyMvcModule.Components;
using Dnn.Modules.DnnMvcModule.MyMvcModule.Models;
using Moq;

namespace Dnn.Modules.DnnMvcModule.Testing.Mocks
{
class MockStores
{
public static Mock<IItemManager> MockItemManager()
{
var allItems = new List<Item>();
var mock = new Mock<IItemManager>();

// void CreateItem(Item t);
mock.Setup(x => x.CreateItem(It.IsAny<Item>()))
.Callback((Item i) =>
{
allItems.Add(i);
});
// void DeleteItem(int itemId, int moduleId);
mock.Setup(x => x.DeleteItem(It.IsAny<int>(), It.IsAny<int>()))
.Callback((int id, int mid) =>
{
var remItem = allItems.FirstOrDefault(i => i.ItemId == id && i.ModuleId == mid);
allItems.Remove(remItem);
});
// void DeleteItem(Item t);
mock.Setup(x => x.DeleteItem(It.IsAny<Item>()))
.Callback((Item di) =>
{
var remItem = allItems.FirstOrDefault(i => i.ItemId == di.ItemId);
allItems.Remove(remItem);
});
// IEnumerable<Item> GetItems(int moduleId);
mock.Setup(x => x.GetItems(It.IsAny<int>()))
.Returns((int mid) => allItems.Where(x => x.ModuleId == mid));
// Item GetItem(int itemId, int moduleId);
mock.Setup(x => x.GetItem(It.IsAny<int>(), It.IsAny<int>()))
.Returns((int id, int mid) => allItems.FirstOrDefault(i => i.ItemId == id && i.ModuleId == mid));
// void UpdateItem(Item t);
mock.Setup(x => x.UpdateItem(It.IsAny<Item>()))
.Callback((Item i) =>
{
allItems.Add(i);
});

return mock;
}

}
}
36 changes: 36 additions & 0 deletions src/DnnMvcModule/Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DnnMvcModule Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DnnMvcModuleTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("074d4d0c-7144-44d0-ae04-d7eb1a586950")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
5 changes: 5 additions & 0 deletions src/DnnMvcModule/Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Moq" version="4.5.23" targetFramework="net452" />
</packages>
26 changes: 26 additions & 0 deletions src/package/DnnMvcModule.vstemplate
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>DNN MVC Module</Name>
<Description>A Visual Studio template for DotNetNuke 8 Module Development using the new MVC module type.</Description>
<Icon>__TemplateIcon.ico</Icon>
<ProjectType>CSharp</ProjectType>
<CreateNewFolder>false</CreateNewFolder>
<DefaultName>DNNModule</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
</TemplateData>
<TemplateContent>
<CustomParameters>
<CustomParameter Name="$rootnamespace$" Value="Dnn.Modules."/>
<CustomParameter Name="$devenvironmenturl$" Value="dnndev.me" />
<CustomParameter Name="$year$" Value="2016" />
</CustomParameters>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$" CopyParameters="true">
Module\MvcModule.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Tests" CopyParameters="true">
Module\Tests\Tests.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
Loading