diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index d15fb69..1c9634a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,270 @@ -#OS junk files -[Tt]humbs.db -*.DS_Store - -#Visual Studio files -*.[Oo]bj -*.user -*.aps -*.pch -*.vspscc -*.vssscc -*_i.c -*_p.c -*.ncb -*.suo -*.tlb -*.tlh -*.bak -*.[Cc]ache -*.ilk -*.log -*.lib -*.sbr -*.sdf -*.opensdf -*.unsuccessfulbuild -ipch/ -obj/ -[Bb]in -[Dd]ebug*/ -[Rr]elease*/ -Ankh.NoLoad - -#Tooling -_ReSharper*/ -*.resharper -[Tt]est[Rr]esult* - -#Project files -[Bb]uild/ - -#Subversion files -.svn - -# Office Temp Files -~$* \ No newline at end of file + +# Created by https://www.gitignore.io/api/visualstudio,visualstudiocode,monodevelop + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# 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 + +# DNX +project.lock.json +artifacts/ + +*_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 +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# 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 add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# 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 database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# 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/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + + +### VisualStudioCode ### +.vscode + + + +### MonoDevelop ### +#User Specific +*.userprefs +*.usertasks + +#Mono Project Files +*.pidb +*.resources +test-results/ diff --git a/NGon.SampleApplication/NGon.SampleApplication.csproj b/NGon.SampleApplication/NGon.SampleApplication.csproj index 0d74bcd..c22db38 100644 --- a/NGon.SampleApplication/NGon.SampleApplication.csproj +++ b/NGon.SampleApplication/NGon.SampleApplication.csproj @@ -1,120 +1,139 @@ - - - - Debug - AnyCPU - - - 2.0 - {6B4601DB-23C8-497E-8545-CDB3075C40A2} - {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - NGon.SampleApplication - NGon.SampleApplication - v4.0 - false - false - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Global.asax - - - - - - - - Web.config - - - Web.config - - - - - - - - {59A8F487-179F-47AE-8631-0AAF99E89DE4} - NGon - - - - - - - - - - - - - - - - False - True - 38588 - / - - - False - False - - - False - - - - + + + + + Debug + AnyCPU + + + 2.0 + {6B4601DB-23C8-497E-8545-CDB3075C40A2} + {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + NGon.SampleApplication + NGon.SampleApplication + v4.5 + false + false + true + + + + + 4.0 + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\ + TRACE + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Global.asax + + + + + + + + Web.config + + + Web.config + + + + + + + + {59A8F487-179F-47AE-8631-0AAF99E89DE4} + NGon + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + + + + + False + True + 38588 + / + + + False + False + + + False + + + + \ No newline at end of file diff --git a/NGon.SampleApplication/Web.config b/NGon.SampleApplication/Web.config index 544f3db..45fe7fe 100644 --- a/NGon.SampleApplication/Web.config +++ b/NGon.SampleApplication/Web.config @@ -1,59 +1,67 @@ - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NGon.Tests/NGon.Tests.csproj b/NGon.Tests/NGon.Tests.csproj index 066ebee..207096f 100644 --- a/NGon.Tests/NGon.Tests.csproj +++ b/NGon.Tests/NGon.Tests.csproj @@ -1,77 +1,83 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {16AFD75A-1563-474C-90BB-6E1B9785EBA0} - Library - Properties - NGon.Tests - NGon.Tests - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll - - - ..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll - - - ..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll - - - ..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll - - - - - - - - - - - - - - - - - - - - - {59A8F487-179F-47AE-8631-0AAF99E89DE4} - NGon - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {16AFD75A-1563-474C-90BB-6E1B9785EBA0} + Library + Properties + NGon.Tests + NGon.Tests + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll + True + + + False + ..\packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll + + + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll + True + + + + + + + + + + + + + + + + + + {59A8F487-179F-47AE-8631-0AAF99E89DE4} + NGon + + + + + + + + + + \ No newline at end of file diff --git a/NGon.Tests/NGonTests.cs b/NGon.Tests/NGonTests.cs index 11d6885..f8daba6 100644 --- a/NGon.Tests/NGonTests.cs +++ b/NGon.Tests/NGonTests.cs @@ -1,135 +1,153 @@ -using System; -using System.Dynamic; -using System.IO; -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; -using Moq; -using NUnit.Framework; - -namespace NGon.Tests -{ - [TestFixture] - public class NGonTests - { - private ControllerBase _controller; - private HtmlHelper _helper; - private const string StartScriptTagFormat = @""; - - [SetUp] - public void Setup() - { - var controllerContext = new ControllerContext(new Mock().Object, new RouteData(), new Mock().Object); - controllerContext.Controller.ViewData = new ViewDataDictionary { { "NGon", new ExpandoObject() } }; - var viewContext = new ViewContext(controllerContext, new Mock().Object, controllerContext.Controller.ViewData, new TempDataDictionary(), new Mock().Object); - var mockViewDataContainer = new Mock(); - mockViewDataContainer.Setup(v => v.ViewData).Returns(controllerContext.Controller.ViewData); - _controller = controllerContext.Controller; - _helper = new HtmlHelper(viewContext, mockViewDataContainer.Object); - } - - [Test] - public void SimpleStringPropertyTest() - { - //arrange - _controller.ViewBag.NGon.Foo = "100"; - - //act - var result = _helper.IncludeNGon(); - - //assert - var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Foo=""100"";", EndScriptTag); - var actual = result.ToString(); - Assert.AreEqual(expected, actual); - } - - [Test] - public void SimpleIntPropertyTest() - { - //arrange - _controller.ViewBag.NGon.Foo = 100; - - //act - var result = _helper.IncludeNGon(); - - //assert - var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Foo=100;", EndScriptTag); - var actual = result.ToString(); - Assert.AreEqual(expected, actual); - } - - [Test] - public void PocoObjectJsonTest() - { - var person = new { FirstName = "John", LastName = "Doe", Age = 45 }; - - //arrange - _controller.ViewBag.NGon.Person = person; - - //act - var result = _helper.IncludeNGon(); - - //assert - var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Person={""FirstName"":""John"",""LastName"":""Doe"",""Age"":45};", EndScriptTag); - var actual = result.ToString(); - Assert.AreEqual(expected, actual); - } - - [Test] - public void NamespaceTest() - { - const string @namespace = "test"; - //arrange - _controller.ViewBag.NGon.Foo = 100; - - //act - var result = _helper.IncludeNGon(@namespace); - - //assert - var expected = String.Concat(String.Format(StartScriptTagFormat, @namespace), @namespace, @".Foo=100;", EndScriptTag); - var actual = result.ToString(); - Assert.AreEqual(expected, actual); - } - - [Test] - public void MissingNGonInViewBagThrowsException() - { - //arrange - _controller.ViewData.Clear(); - - //act - //assert - Assert.Throws(() => _helper.IncludeNGon()); - } - - [Test] - public void OutputScriptTagFalseOmitsScriptTag() - { - //arrange - _controller.ViewBag.NGon.Foo = 100; - - //act - var result = _helper.IncludeNGon(outputScriptTag: false); - - //assert - var expected = "window.ngon={};ngon.Foo=100;"; - var actual = result.ToString(); - Assert.AreEqual(expected, actual); - } - - [Test] - public void ExternalJsFileTrueOutputsExternalJSReference() - { - //arrange - _controller.ViewBag.NGon.Foo = 100; - - //act - var result = _helper.IncludeNGon(useExternalJSFile: true); - - //assert - var expected = ""; + + [SetUp] + public void Setup() + { + var controllerContext = new ControllerContext(new Mock().Object, new RouteData(), new Mock().Object); + controllerContext.Controller.ViewData = new ViewDataDictionary { { "NGon", new ExpandoObject() } }; + var viewContext = new ViewContext(controllerContext, new Mock().Object, controllerContext.Controller.ViewData, new TempDataDictionary(), new Mock().Object); + var mockViewDataContainer = new Mock(); + mockViewDataContainer.Setup(v => v.ViewData).Returns(controllerContext.Controller.ViewData); + _controller = controllerContext.Controller; + _helper = new HtmlHelper(viewContext, mockViewDataContainer.Object); + } + + [Test] + public void SimpleStringPropertyTest() + { + //arrange + _controller.ViewBag.NGon.Foo = "100"; + + //act + var result = _helper.IncludeNGon(); + + //assert + var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Foo=""100"";", EndScriptTag); + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void SimpleIntPropertyTest() + { + //arrange + _controller.ViewBag.NGon.Foo = 100; + + //act + var result = _helper.IncludeNGon(); + + //assert + var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Foo=100;", EndScriptTag); + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void PocoObjectJsonTest() + { + var person = new { FirstName = "John", LastName = "Doe", Age = 45 }; + + //arrange + _controller.ViewBag.NGon.Person = person; + + //act + var result = _helper.IncludeNGon(); + + //assert + var expected = String.Concat(String.Format(StartScriptTagFormat, "ngon"), @"ngon.Person={""FirstName"":""John"",""LastName"":""Doe"",""Age"":45};", EndScriptTag); + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void PocoObjectCustomizedJsonTest() + { + var person = new { FirstName = "Dollard", LastName = "Drunk", BirthDate = new DateTime(1946, 6, 14) }; + + //arrange + _controller.ViewBag.NGon.Person = person; + + //act + var result = _helper.IncludeNGon(converters: new IsoDateTimeConverter { DateTimeFormat = "dd-MMM-yyyy" }); + + //assert + var expected = $@"{string.Format(StartScriptTagFormat, "ngon")}ngon.Person={{""FirstName"":""Dollard"",""LastName"":""Drunk"",""BirthDate"":""14-Jun-1946""}};{EndScriptTag}"; + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void NamespaceTest() + { + const string @namespace = "test"; + //arrange + _controller.ViewBag.NGon.Foo = 100; + + //act + var result = _helper.IncludeNGon(@namespace); + + //assert + var expected = String.Concat(String.Format(StartScriptTagFormat, @namespace), @namespace, @".Foo=100;", EndScriptTag); + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void MissingNGonInViewBagThrowsException() + { + //arrange + _controller.ViewData.Clear(); + + //act + //assert + Assert.Throws(() => _helper.IncludeNGon()); + } + + [Test] + public void OutputScriptTagFalseOmitsScriptTag() + { + //arrange + _controller.ViewBag.NGon.Foo = 100; + + //act + var result = _helper.IncludeNGon(outputScriptTag: false); + + //assert + var expected = "window.ngon={};ngon.Foo=100;"; + var actual = result.ToString(); + Assert.AreEqual(expected, actual); + } + + [Test] + public void ExternalJsFileTrueOutputsExternalJSReference() + { + //arrange + _controller.ViewBag.NGon.Foo = 100; + + //act + var result = _helper.IncludeNGon(useExternalJSFile: true); + + //assert + var expected = "