Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for JS Syntax Errors #2

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f3c20cd
Moved nuget resources around and added template for intellisense
stevegreatrex Nov 7, 2012
0039585
Added NullPathUtility and updated nuget package to install .tt
stevegreatrex Nov 7, 2012
8583e5b
Added test for null path utility
stevegreatrex Nov 7, 2012
68731fa
Added new nuget package and .tt file
stevegreatrex Nov 7, 2012
fe7a65c
Merge remote-tracking branch 'origin/Intellisense'
stevegreatrex Nov 7, 2012
5f82312
Added init script to automatically run text transforms on build
stevegreatrex Nov 7, 2012
8090f22
Added automatic T4 Transforms
stevegreatrex Nov 7, 2012
0762ff5
Added new package for proxyapi intellisense
stevegreatrex Nov 7, 2012
5ac31d8
Added function parameters to generated JS
stevegreatrex Nov 8, 2012
2ea1de9
Updated nuget packages
stevegreatrex Nov 8, 2012
c1ede89
Updated package AGAIN
stevegreatrex Nov 8, 2012
e1c787a
Enabled auto-update of dependent nuget packages
stevegreatrex Nov 8, 2012
871cc68
Combined 2 reflection classes into one
stevegreatrex Nov 8, 2012
1009f98
Added configuration dependency to dependencyresolver
stevegreatrex Nov 8, 2012
5cdc96e
Added sensible resolution of defaults
stevegreatrex Nov 8, 2012
4d803c5
Removed MEF implementation
stevegreatrex Nov 8, 2012
d5e0907
NuGet build for ProxyApi
stevegreatrex Nov 10, 2012
ce2b63d
NuSpec for .Intellisense
stevegreatrex Nov 10, 2012
7c4b107
Added nuspec to solution
stevegreatrex Nov 10, 2012
64c5dfb
Added package building to build process
stevegreatrex Nov 10, 2012
83a09a1
Removed generated packages
stevegreatrex Nov 10, 2012
e13f75d
Published and updated packages
stevegreatrex Nov 10, 2012
6ce93be
Fixed encoding issue in powershell
stevegreatrex Nov 16, 2012
16152ae
Updated package for intellisense
stevegreatrex Nov 17, 2012
cf523ec
Added readme
stevegreatrex Nov 17, 2012
d9efcb8
Added instructions and intellisense link
stevegreatrex Nov 17, 2012
1e088c7
Fixed line breaks
stevegreatrex Nov 17, 2012
43c2b80
readme updates
stevegreatrex Nov 17, 2012
5775e4b
Added basic sample project
stevegreatrex Jan 18, 2013
0abc924
Excluded abstract classes from generation
stevegreatrex May 4, 2013
6b602a5
Published new package
stevegreatrex May 4, 2013
dfe24e4
Updated nuget package
stevegreatrex May 24, 2013
19b5839
Added support for [ActionName] attribute
stevegreatrex May 24, 2013
295ea87
Fixed apparent problem with published nuget package
stevegreatrex May 24, 2013
3fd3efd
Fixing JS syntax errors caused by T4 template
marlon-tucker Jun 19, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
150 changes: 150 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<ResolveReferencesDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(ResolveReferencesDependsOn);
</ResolveReferencesDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>

<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EnvKey ParameterType="System.String" Required="true" />
<EnvValue ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
}
catch {
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
Binary file removed ProxyApi.0.1.1.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.2.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.3.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.4.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.5.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.6.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.7.nupkg
Binary file not shown.
Binary file removed ProxyApi.0.1.nupkg
Binary file not shown.
3 changes: 3 additions & 0 deletions ProxyApi.Tests.Integration/IntegrationTestApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ public void SendDataWithPut(int id, [FromBody]dynamic data)

public void Delete(int id)
{}

public void WithoutParameters()
{}
}
}
3 changes: 3 additions & 0 deletions ProxyApi.Tests.Integration/IntegrationTestMvcController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ public void SendDataWithPut(int id, [System.Web.Http.FromBody]dynamic data)

public void Delete(int id)
{}

public void WithoutParameters()
{}
}
}
3 changes: 3 additions & 0 deletions ProxyApi.Tests.Integration/ProxyApi.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -101,6 +103,7 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
9 changes: 5 additions & 4 deletions ProxyApi.Tests.Integration/TestGeneratedJavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public void Setup()

private IProxyGenerator CreateProxyGenerator()
{
return new ProxyGenerator(
new ControllerTypesProvider(
var controllerElementsProvider = new ControllerElementsProvider(
new AppDomainAssemblyProvider(),
ProxyGeneratorConfiguration.Default),
ProxyGeneratorConfiguration.Default);
return new ProxyGenerator(
controllerElementsProvider,
new ControllerDefinitionFactory(
new ActionMethodsProvider(ProxyGeneratorConfiguration.Default),
controllerElementsProvider,
new ActionMethodDefinitionFactory(new PassThroughPathUtility())));
}

Expand Down
49 changes: 49 additions & 0 deletions ProxyApi.Tests/Factories/TestActionMethodDefinitionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,44 @@ public void Create_Sets_URL_For_Api_Controllers()
Assert.AreEqual("/url", definition.Url, "The URL should be populated");
}

/// <summary>
/// Ensures that Create uses the explicitly-set ActionName in the URL
/// </summary>
[TestMethod]
public void Create_Sets_URL_Named_WebApi_Actions()
{
_pathUtility.Setup(p => p.ToAbsolute("~/api/proxy/controller/ExplicitWebApiName"))
.Returns("/url");

var method = GetMethodInfo("NamedWebApiMethod");
var definition = this.TestSubject.Create(new ControllerDefinition()
{
UrlName = "controller",
Type = ControllerType.WebApi
}, method);

Assert.AreEqual("/url", definition.Url, "The URL should be populated");
}

/// <summary>
/// Ensures that Create uses the explicitly-set ActionName in the URL
/// </summary>
[TestMethod]
public void Create_Sets_URL_Named_Mvc_Actions()
{
_pathUtility.Setup(p => p.ToAbsolute("~/api/proxy/controller/ExplicitMvcName"))
.Returns("/url");

var method = GetMethodInfo("NamedMvcMethod");
var definition = this.TestSubject.Create(new ControllerDefinition()
{
UrlName = "controller",
Type = ControllerType.WebApi
}, method);

Assert.AreEqual("/url", definition.Url, "The URL should be populated");
}

/// <summary>
/// Ensures that Create sets URL
/// </summary>
Expand Down Expand Up @@ -172,6 +210,8 @@ public void Create_Populates_Parameters_Correctly()
CheckMethodParameters("DeleteWithExplicitBody", "one");
CheckMethodParameters("DeleteWithExplicitBodyAndUrlParameters", "two", "one");
CheckMethodParameters("DeleteWithUrlParameters", null, "one", "two");

CheckMethodParameters("PostWithExplicitUrl", null, "one");
}

#endregion
Expand Down Expand Up @@ -228,13 +268,22 @@ public void DeleteWithExplicitBody([FromBody]object one){}
public void DeleteWithExplicitBodyAndUrlParameters(object one, [FromBody]object two){}
public void DeleteWithUrlParameters(object one, object two){ }


public void PostWithExplicitUrl([FromUri]object one){}

#endregion

#region Name Checks

[ProxyName("userSpecifiedName")]
public void NamedMethod(){}

[System.Web.Http.ActionNameAttribute("ExplicitWebApiName")]
public void NamedWebApiMethod() { }

[System.Web.Mvc.ActionNameAttribute("ExplicitMvcName")]
public void NamedMvcMethod() { }

#endregion
}

Expand Down
4 changes: 2 additions & 2 deletions ProxyApi.Tests/Factories/TestControllerDefinitionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ProxyApi.Tests.Factories
[TestClass]
public class TestControllerDefinitionFactory : FixtureBase<ControllerDefinitionFactory>
{
private Mock<IActionMethodsProvider> _actionProvider;
private Mock<IControllerElementsProvider> _actionProvider;
private Mock<IActionMethodDefinitionFactory> _actionFactory;

#region Setup
Expand All @@ -28,7 +28,7 @@ public class TestControllerDefinitionFactory : FixtureBase<ControllerDefinitionF
/// </summary>
public override ControllerDefinitionFactory CreateTestSubject()
{
_actionProvider = this.MockRepository.Create<IActionMethodsProvider>();
_actionProvider = this.MockRepository.Create<IControllerElementsProvider>();
_actionFactory = this.MockRepository.Create<IActionMethodDefinitionFactory>();

return new ControllerDefinitionFactory(_actionProvider.Object, _actionFactory.Object);
Expand Down
8 changes: 6 additions & 2 deletions ProxyApi.Tests/ProxyApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -65,14 +67,15 @@
<Compile Include="Factories\TestControllerDefinitionFactory.cs" />
<Compile Include="FixtureBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflection\TestActionMethodsProvider.cs" />
<Compile Include="Reflection\TestAppDomainAssemblyProvider.cs" />
<Compile Include="Reflection\TestReflectionExtensions.cs" />
<Compile Include="Reflection\TestControllerTypesProvider.cs" />
<Compile Include="Reflection\TestControllerElementsProvider.cs" />
<Compile Include="SampleAbstractApiController.cs" />
<Compile Include="SampleApiController.cs" />
<Compile Include="SampleExcludedController.cs" />
<Compile Include="SampleMvcController.cs" />
<Compile Include="Templates\TestProxyTemplate.cs" />
<Compile Include="TestNullPathUtility.cs" />
<Compile Include="TestProxyDependencyResolver.cs" />
<Compile Include="TestProxyGenerator.cs" />
<Compile Include="TestProxyGeneratorConfiguration.cs" />
Expand Down Expand Up @@ -110,6 +113,7 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
Loading