init commit
This commit is contained in:
186
.gitignore
vendored
Normal file
186
.gitignore
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
build/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# Roslyn cache directories
|
||||
*.ide/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
#NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding addin-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
## TODO: Comment the next line if you want to checkin your
|
||||
## web deploy settings but do note that will include unencrypted
|
||||
## passwords
|
||||
*.pubxml
|
||||
|
||||
# NuGet Packages
|
||||
packages/*
|
||||
*.nupkg
|
||||
## TODO: If the tool you use requires repositories.config
|
||||
## uncomment the next line
|
||||
#!packages/repositories.config
|
||||
|
||||
# Enable "build/" folder in the NuGet Packages folder since
|
||||
# NuGet packages use it for MSBuild targets.
|
||||
# This line needs to be after the ignore of the build folder
|
||||
# (and the packages folder if the line above has been uncommented)
|
||||
!packages/build/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
*.DotSettings
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
4
.nuget/packages.config
Normal file
4
.nuget/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit.Runners" version="2.6.3" />
|
||||
</packages>
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class BaseAttribute
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public static void ConfirmEmptyBundleName()
|
||||
{
|
||||
var ts = new DefaultBundleAttribute("", "tst", ContentType.JavaScript, AsyncLoading.Async, "dsds");
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public static void ConfirmNullBundleName()
|
||||
{
|
||||
var ts = new DefaultBundleAttribute(null, "tst", ContentType.JavaScript, AsyncLoading.Async, "dsds");
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public static void ConfirmEmptyOutputURI()
|
||||
{
|
||||
var ts = new DefaultBundleAttribute("tst", "", ContentType.JavaScript, AsyncLoading.Async, "dsds");
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public static void ConfirmNullOutputURI()
|
||||
{
|
||||
var ts = new DefaultBundleAttribute("tst", null, ContentType.JavaScript, AsyncLoading.Async, "dsds");
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public static void ConfirmEmptyFilePath()
|
||||
{
|
||||
var ts = new DefaultBundleAttribute("tst", "ds", ContentType.JavaScript, AsyncLoading.Async, new string[]{});
|
||||
}
|
||||
[Test]
|
||||
public static void ConfirmBundleNameApplied()
|
||||
{
|
||||
var td = "tst";
|
||||
var ts = new DefaultBundleAttribute(td, "ds", ContentType.JavaScript, AsyncLoading.Async, new string[] { "tst"});
|
||||
Assert.IsTrue(string.Equals(ts.BundleName,td));
|
||||
}
|
||||
[Test]
|
||||
public static void ConfirmBundleOutputURIApplied()
|
||||
{
|
||||
var td = "tst";
|
||||
var ts = new DefaultBundleAttribute("TST", td, ContentType.JavaScript, AsyncLoading.Async, new string[] { "tst" });
|
||||
Assert.IsTrue(string.Equals(ts.OutputUri, td));
|
||||
}
|
||||
[Test]
|
||||
public static void ConfirmBundleFileURIApplied()
|
||||
{
|
||||
var td = "tst";
|
||||
var ts = new DefaultBundleAttribute("TST", "TDS", ContentType.JavaScript, AsyncLoading.Async, new[] { td });
|
||||
Assert.IsTrue(string.Equals(ts.Fileuri.FirstOrDefault(), td));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using NUnit.Framework;
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class CssBundleTest
|
||||
{
|
||||
[Test]
|
||||
public void CreateCssBundle()
|
||||
{
|
||||
var td = new CssBundleAttribute("test bundle", "~/d", "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using NUnit.Framework;
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class JavaScriptBundleTest
|
||||
{
|
||||
[Test]
|
||||
public void CreateJavaScriptBundleAttribute()
|
||||
{
|
||||
var td = new JavaScriptBundleAttribute("test bundle", "~/d",AsyncLoading.Async, "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class BundlerTestAssemblyLoading
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException(typeof(TypeAccessException))]
|
||||
public void LoadFromAssembly()
|
||||
{
|
||||
new Bundler(false).ForceFactoryReloadFromAssembly();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
132
src/tparnell.ContentBundling.UnitTest/BundlerTests.cs
Normal file
132
src/tparnell.ContentBundling.UnitTest/BundlerTests.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
using tparnell.ContentBundling.Exceptions;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest
|
||||
{
|
||||
[TestFixture]
|
||||
[JavaScriptBundle("awesome", "/", AsyncLoading.Async,"/")]
|
||||
public class BundlerTests
|
||||
{
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
Bundler.BundleFactory = null;
|
||||
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(NoBundleFactoryException))]
|
||||
public void ConfirmThrownException()
|
||||
{
|
||||
|
||||
var td = new Bundler(false);
|
||||
|
||||
try
|
||||
{
|
||||
var ts = Task.Run(() => td.Bundle());
|
||||
ts.Wait();
|
||||
}
|
||||
catch (AggregateException e)
|
||||
{
|
||||
|
||||
throw e.InnerException;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
[Test]
|
||||
public void ConfirmBundleCollectionCreation()
|
||||
{
|
||||
|
||||
var td = new Bundler(false);
|
||||
Assert.IsNotNull(Bundler.BundlesCreated);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakeSureBundlesCreatedIsNotNull()
|
||||
{
|
||||
|
||||
if(Bundler.BundlesCreated == null) Assert.Fail();
|
||||
}
|
||||
[Test]
|
||||
public void SetPath()
|
||||
{
|
||||
var path = "awesomepath";
|
||||
var td = new Bundler(false).SetPath(path);
|
||||
Assert.IsTrue(string.Equals(path, Bundler.RootPath));
|
||||
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void PassNullFactory()
|
||||
{
|
||||
|
||||
var td = new Bundler(null,true);
|
||||
|
||||
}
|
||||
[Test]
|
||||
public void ConfirmOverriddenFactory()
|
||||
{
|
||||
var refer = new Mock<IBundlesFactory>().Object;
|
||||
var td = new Bundler(new Mock<IBundlesFactory>().Object, false);
|
||||
var ts = new Bundler(refer, true);
|
||||
Assert.IsTrue(refer == Bundler.BundleFactory);
|
||||
|
||||
}
|
||||
[Test]
|
||||
public void ConfirmOverriddenFactoryFailed()
|
||||
{
|
||||
var refer = new Mock<IBundlesFactory>().Object;
|
||||
var td = new Bundler(new Mock<IBundlesFactory>().Object, false);
|
||||
var ts = new Bundler(refer, false);
|
||||
Assert.IsFalse(refer == Bundler.BundleFactory);
|
||||
|
||||
}
|
||||
[Test]
|
||||
public void ConfirmFactoryIsNotOverridentFromAssembly()
|
||||
{
|
||||
var refer = new Mock<IBundlesFactory>().Object;
|
||||
var ts = new Bundler(refer, true);
|
||||
var td = new Bundler(true);
|
||||
Assert.IsTrue(refer == Bundler.BundleFactory);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BundleIt()
|
||||
{
|
||||
var refer = new Mock<IBundlesFactory>();
|
||||
refer.Setup(x => x.BundleContent(It.IsAny<IBundleAttribute>(), It.IsAny<bool>()));
|
||||
var ts = new Bundler(refer.Object);
|
||||
var tsk = Task.Run(()=>ts.BundleAsync());
|
||||
tsk.Wait();
|
||||
refer.Verify();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ForceDebug()
|
||||
{
|
||||
new Bundler(new Mock<IBundlesFactory>().Object, true);
|
||||
var ts = Task.Run(async () => { await new Bundler().ForceDebugAsync(); });
|
||||
ts.Wait();
|
||||
Assert.IsTrue(Bundler.IsForceDebug);
|
||||
var bs = Task.Run(async () => { await new Bundler().ClearForceDebugAsync(); });
|
||||
bs.Wait();
|
||||
|
||||
}
|
||||
[Test]
|
||||
public void ClearDebug()
|
||||
{
|
||||
new Bundler(new Mock<IBundlesFactory>().Object, true);
|
||||
var td = Task.Run(async () => { await new Bundler().ClearForceDebugAsync(); });
|
||||
td.Wait();
|
||||
Assert.IsTrue(!Bundler.IsForceDebug );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using NUnit.Framework;
|
||||
using tparnell.ContentBundling.Exceptions;
|
||||
|
||||
namespace tparnell.ContentBundling.UnitTest.Exception
|
||||
{
|
||||
[TestFixture]
|
||||
public class NoBundleFactoryExceptionTest
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException(typeof(NoBundleFactoryException))]
|
||||
public void CallException()
|
||||
{
|
||||
throw new NoBundleFactoryException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(NoBundleFactoryException))]
|
||||
public void CallExceptionWithMessage()
|
||||
{
|
||||
throw new NoBundleFactoryException("Test Message");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(NoBundleFactoryException))]
|
||||
public void CallExceptionWithMessageAndInnerException()
|
||||
{
|
||||
throw new NoBundleFactoryException("Test Message", new NoBundleFactoryException());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("tparnell.ContentBundling.UnitTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("tparnell.ContentBundling.UnitTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[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("e2d3d7ff-0779-451e-af0a-6c5f681dd8f7")]
|
||||
|
||||
// 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
src/tparnell.ContentBundling.UnitTest/packages.config
Normal file
5
src/tparnell.ContentBundling.UnitTest/packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>tparnell.ContentBundling.UnitTest</RootNamespace>
|
||||
<AssemblyName>tparnell.ContentBundling.UnitTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</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="Moq">
|
||||
<HintPath>..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\BaseAttribute.cs" />
|
||||
<Compile Include="BundlerTestAssemblyLoading.cs" />
|
||||
<Compile Include="BundlerTests.cs" />
|
||||
<Compile Include="Attributes\CssBundleTest.cs" />
|
||||
<Compile Include="Exception\NoBundleFactoryExceptionTest.cs" />
|
||||
<Compile Include="Attributes\JavaScriptBundleTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\tparnell.ContentBundling\tparnell.ContentBundling.csproj">
|
||||
<Project>{eca4d0fd-3f56-4b8b-b9de-e671e38e351c}</Project>
|
||||
<Name>tparnell.ContentBundling</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<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>
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public sealed class CssBundleAttribute : DefaultBundleAttribute
|
||||
{
|
||||
public CssBundleAttribute(string bundleName, string outputUri, params string[] fileuri)
|
||||
: base(bundleName, outputUri, ContentType.Css, AsyncLoading.Default, fileuri)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class DefaultBundleAttribute: Attribute, IBundleAttribute
|
||||
{
|
||||
public string BundleName { get; private set; }
|
||||
public string OutputUri { get; private set; }
|
||||
public ContentType Contenttype { get; private set; }
|
||||
public IEnumerable<string> Fileuri { get; private set; }
|
||||
public AsyncLoading Async { get; private set; }
|
||||
|
||||
public DefaultBundleAttribute(string bundleName, string outputUri, ContentType contenttype, AsyncLoading async, params string[] fileuri)
|
||||
{
|
||||
if(String.IsNullOrWhiteSpace(bundleName)) throw new ArgumentNullException("bundleName");
|
||||
if (String.IsNullOrWhiteSpace(outputUri)) throw new ArgumentNullException("outputUri");
|
||||
if (fileuri.Length < 1) throw new ArgumentNullException("fileuri");
|
||||
BundleName = bundleName;
|
||||
OutputUri = outputUri;
|
||||
Contenttype = contenttype;
|
||||
Fileuri = fileuri;
|
||||
Async = async;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs
Normal file
14
src/tparnell.ContentBundling/Attributes/IBundleAttribute.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.Attributes
|
||||
{
|
||||
public interface IBundleAttribute
|
||||
{
|
||||
string BundleName { get; }
|
||||
string OutputUri { get; }
|
||||
ContentType Contenttype { get; }
|
||||
IEnumerable<string> Fileuri { get; }
|
||||
AsyncLoading Async { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using tparnell.ContentBundling.Enum;
|
||||
|
||||
namespace tparnell.ContentBundling.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public sealed class JavaScriptBundleAttribute : DefaultBundleAttribute
|
||||
{
|
||||
public JavaScriptBundleAttribute(string bundleName, string outputUri, AsyncLoading async , params string[] fileuri)
|
||||
: base(bundleName, outputUri, ContentType.JavaScript, async, fileuri)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
104
src/tparnell.ContentBundling/Bundler.cs
Normal file
104
src/tparnell.ContentBundling/Bundler.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
using tparnell.ContentBundling.Exceptions;
|
||||
|
||||
namespace tparnell.ContentBundling
|
||||
{
|
||||
public partial class Bundler
|
||||
{
|
||||
public static bool IsForceDebug { get; private set; }
|
||||
public static ConcurrentBag<string> BundlesCreated { get; private set; }
|
||||
public static string RootPath { get; set; }
|
||||
public static IBundlesFactory BundleFactory { get; set; }
|
||||
//empty constructor so we allways have a constructor that is paramterless
|
||||
public Bundler(bool loadFactoryFromAssembly = true, bool overrideExisting = false)
|
||||
{
|
||||
if (BundleFactory != null && !overrideExisting) return;
|
||||
if (loadFactoryFromAssembly) ForceFactoryReloadFromAssembly();
|
||||
}
|
||||
public Bundler(IBundlesFactory factory, bool replaceExisting = true)
|
||||
{
|
||||
if(factory == null) throw new ArgumentNullException("factory");
|
||||
if (BundleFactory != null && !replaceExisting) return;
|
||||
BundleFactory = factory;
|
||||
}
|
||||
|
||||
|
||||
static Bundler()
|
||||
{
|
||||
if (BundlesCreated == null) BundlesCreated = new ConcurrentBag<string>();
|
||||
|
||||
}
|
||||
|
||||
public void ForceFactoryReloadFromAssembly()
|
||||
{
|
||||
var assems = AppDomain.CurrentDomain.GetAssemblies();
|
||||
var types = assems.SelectMany(s => s.GetTypes()).FirstOrDefault(p => typeof(IBundlesFactory).IsAssignableFrom(p) && p.IsClass && !p.IsInterface);
|
||||
if (types == null) throw new TypeAccessException();
|
||||
//lame excuse for dependancy injection, but for now it works
|
||||
BundleFactory = (IBundlesFactory)Activator.CreateInstance(types);
|
||||
|
||||
}
|
||||
|
||||
public Bundler Bundle()
|
||||
{
|
||||
if (BundleFactory == null) throw new NoBundleFactoryException();
|
||||
var assems = AppDomain.CurrentDomain.GetAssemblies().Where(w => w.GetReferencedAssemblies().Any(r => r.Name.StartsWith("tparnell.ContentBundling", StringComparison.OrdinalIgnoreCase)));
|
||||
//boy do I hate myself for doing this....Basically scan through loaded assemblies looking for bundles that should be built on app startup
|
||||
assems.AsParallel().ForAll(x => x.GetTypes().ToList().Where(ds => (ds.GetCustomAttributes(typeof(IBundleAttribute), true)).Any()).AsParallel().ForAll(
|
||||
dx =>
|
||||
{
|
||||
Environment.CurrentDirectory = string.IsNullOrEmpty(RootPath) ? Environment.CurrentDirectory : RootPath;
|
||||
var bundles = dx.GetCustomAttributes(typeof(IBundleAttribute), true).Select(a => (IBundleAttribute)a);
|
||||
foreach (var bund in bundles)
|
||||
{
|
||||
var bundlename = bund != null ? bund.BundleName : "Unknown Bundle";
|
||||
BundlesCreated.Add(bundlename);
|
||||
BundleFactory.BundleContent(bund, IsForceDebug);
|
||||
}
|
||||
}));
|
||||
return this;
|
||||
}
|
||||
|
||||
#region RepositoryThings
|
||||
|
||||
public Bundler SetPath(string path)
|
||||
{
|
||||
RootPath = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force Debug
|
||||
/// </summary>
|
||||
/// <returns>Self</returns>
|
||||
public Bundler ForceDebug()
|
||||
{
|
||||
IsForceDebug = true;
|
||||
PurgeBundles();
|
||||
return Bundle();
|
||||
}
|
||||
/// <summary>
|
||||
/// Clear force debug
|
||||
/// </summary>
|
||||
/// <returns>self</returns>
|
||||
public Bundler ClearForceDebug()
|
||||
{
|
||||
IsForceDebug = false;
|
||||
PurgeBundles();
|
||||
return Bundle();
|
||||
}
|
||||
|
||||
public Bundler PurgeBundles()
|
||||
{
|
||||
BundlesCreated = new ConcurrentBag<string>();
|
||||
BundleFactory.RebuildCache();
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
31
src/tparnell.ContentBundling/BundlerAsync.cs
Normal file
31
src/tparnell.ContentBundling/BundlerAsync.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace tparnell.ContentBundling
|
||||
{
|
||||
public partial class Bundler
|
||||
{
|
||||
|
||||
public async Task<Bundler> BundleAsync()
|
||||
{
|
||||
return await Task.Run(() => Bundle());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force Debug
|
||||
/// </summary>
|
||||
/// <returns>Self</returns>
|
||||
public async Task<Bundler> ForceDebugAsync()
|
||||
{
|
||||
return await Task.Run(() => ForceDebug());
|
||||
}
|
||||
/// <summary>
|
||||
/// Clear force debug
|
||||
/// </summary>
|
||||
/// <returns>self</returns>
|
||||
public async Task<Bundler> ClearForceDebugAsync()
|
||||
{
|
||||
return await Task.Run(() => ClearForceDebug());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
10
src/tparnell.ContentBundling/Enum/AsyncLoading.cs
Normal file
10
src/tparnell.ContentBundling/Enum/AsyncLoading.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace tparnell.ContentBundling.Enum
|
||||
{
|
||||
public enum AsyncLoading
|
||||
{
|
||||
None,
|
||||
Defer,
|
||||
Async,
|
||||
Default
|
||||
}
|
||||
}
|
||||
8
src/tparnell.ContentBundling/Enum/ContentType.cs
Normal file
8
src/tparnell.ContentBundling/Enum/ContentType.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace tparnell.ContentBundling.Enum
|
||||
{
|
||||
public enum ContentType
|
||||
{
|
||||
JavaScript,
|
||||
Css
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace tparnell.ContentBundling.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class NoBundleFactoryException : Exception
|
||||
{
|
||||
public NoBundleFactoryException()
|
||||
:base("No Bundle Factory Loaded"){}
|
||||
|
||||
|
||||
public NoBundleFactoryException(string message):base(message){}
|
||||
|
||||
public NoBundleFactoryException(string message, Exception innerException)
|
||||
:base(message,innerException){}
|
||||
}
|
||||
}
|
||||
10
src/tparnell.ContentBundling/IBundlesFactory.cs
Normal file
10
src/tparnell.ContentBundling/IBundlesFactory.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using tparnell.ContentBundling.Attributes;
|
||||
|
||||
namespace tparnell.ContentBundling
|
||||
{
|
||||
public interface IBundlesFactory
|
||||
{
|
||||
void BundleContent(IBundleAttribute bundle, bool debug = false);
|
||||
void RebuildCache();
|
||||
}
|
||||
}
|
||||
36
src/tparnell.ContentBundling/Properties/AssemblyInfo.cs
Normal file
36
src/tparnell.ContentBundling/Properties/AssemblyInfo.cs
Normal file
@@ -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("tparnell.ContentBundling")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("tparnell.ContentBundling")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[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("d3a41748-a805-4e56-b65c-d63452456abc")]
|
||||
|
||||
// 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")]
|
||||
65
src/tparnell.ContentBundling/tparnell.ContentBundling.csproj
Normal file
65
src/tparnell.ContentBundling/tparnell.ContentBundling.csproj
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>tparnell.ContentBundling</RootNamespace>
|
||||
<AssemblyName>tparnell.ContentBundling</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</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>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</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>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BundlerAsync.cs" />
|
||||
<Compile Include="Enum\AsyncLoading.cs" />
|
||||
<Compile Include="Bundler.cs" />
|
||||
<Compile Include="Enum\ContentType.cs" />
|
||||
<Compile Include="Attributes\CssBundleAttribute.cs" />
|
||||
<Compile Include="Attributes\DefaultBundleAttribute.cs" />
|
||||
<Compile Include="Exceptions\NoBundleFactoryException.cs" />
|
||||
<Compile Include="Attributes\IBundleAttribute.cs" />
|
||||
<Compile Include="Attributes\JavaScriptBundleAttribute.cs" />
|
||||
<Compile Include="IBundlesFactory.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<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>
|
||||
42
tparnell.ContentBundling.sln
Normal file
42
tparnell.ContentBundling.sln
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tparnell.ContentBundling", "src\tparnell.ContentBundling\tparnell.ContentBundling.csproj", "{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tparnell.ContentBundling.UnitTest", "src\tparnell.ContentBundling.UnitTest\tparnell.ContentBundling.UnitTest.csproj", "{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{950EC3D1-E8C6-4B2A-9377-290824082C76}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.nuget\packages.config = .nuget\packages.config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
NET4.0|Any CPU = NET4.0|Any CPU
|
||||
NET4.5|Any CPU = NET4.5|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.0|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.0|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.5|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.NET4.5|Any CPU.Build.0 = Release|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ECA4D0FD-3F56-4B8B-B9DE-E671E38E351C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.0|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.0|Any CPU.Build.0 = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.5|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.NET4.5|Any CPU.Build.0 = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85532C8E-1BFD-40B8-8E3A-1F7D46D24ED8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user