Excluding files in assembly from being moled - moles

I am using moles to generate mock classes for the legacy code my team uses. Is it possible to exclude certain classes in the assembly from being moled? I am getting a lot of errors for some autogenerated classes we have in the legacy code which I want to exclude from being moled.

To include and exclude types from stub/mole generation, you need to modify the .moles file for your assembly. Although the section "Type Filtering" of the reference manual describes only the StubGeneration element, there is also the MoleGeneration element which works similarly but manages mole generation.
To exclude a type from stub and mole generation specify the type name in a Remove element so that the .moles file for your assembly looks like this:
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" Diagnostic="true">
<Assembly Name="your_assembly" />
<StubGeneration>
<Types>
<Remove FullName="Your.Type.Full.Name!" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Remove FullName="Your.Type.Full.Name!" />
</Types>
</MoleGeneration>
</Moles>
Here's how to enable stub and mole generation only for one class Your.Type.Full.Name:
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" Diagnostic="true">
<Assembly Name="your_assembly" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Your.Type.Full.Name!" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName="Your.Type.Full.Name!" />
</Types>
</MoleGeneration>
</Moles>

Related

IIS 10 - web.config - how to enable default document without script access

We have a folder which contains only static html and images etc. No scripts should be allowed to execute from within this folder. However we would still like to be able to use html default documents.
What is the correct way to configure this?
This is the web.config file...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read"/>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
If I attempt to access http://mysite/mystaticfolder/ it fails with the error...
HTTP Error 403.1 - Forbidden
However the URL http://mysite/mystaticfolder/default.html works fine.
Surely it shouldn't be nescessary to allow dynamic scripts, just to be able to serve static html default documents?
In case it helps anyone, I've been able to solve it with the following...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read">
<clear/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule" resourceType="Either" requireAccess="Read" />
</handlers>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I'm not entirely sure though why this doesn't work by default though.

Nuget Package Manager combining local and external servers

Hoping for a little help here. I've a custom built dll which has a dependency on EntityFramework. I've deployed the custom build dll to our local nuget server. However I have not deployed EntityFramework. That is available on the external nugget servers.
When I attempt to install my custom build dll using the Nuget Solution Manager, I get the following error:
Attempting to resolve dependencies for package 'CustomBuilt.dll.2016.10.10.6' with DependencyBehavior 'Lowest'
Unable to resolve dependency 'EntityFramework.dll'. Source(s) used: 'LocalServer', 'NugetAlt1', 'NugetAltHttps', 'nuget.org', 'Microsoft and .NET'.
The url's for external Servers are:
NugetAlt1: http://packages.nuget.org/v1/FeedService.svc/
NugetAltHttps: https://www.nuget.org/api/v2/
nuget.org: https://api.nuget.org/v3/index.json
Microsoft and .Net: https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/
I am using VS2015. I've also tried with VS2013.
Also I've added a nuget.config file to the solution. Still getting the error:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="LocalServer" value="http://localserver:8089/nuget" />
<add key="NugetAlt1" value="http://packages.nuget.org/v1/FeedService.svc/" />
<add key="NugetAltHttps" value="https://www.nuget.org/api/v2/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
</configuration>
Any thoughts/ideas?
Kind Regards,
Fiona
I finally found it.. The problem was in the nuspec file that I was using to generate the package. The id of my dependencies was incorrect.
I specified the following:
<dependencies>
<dependency id = "EntityFramework.dll" version = "6.0.0.0" />
</dependencies>
This is incorrect. The package name of EF is EntityFramework not EntityFramework.dll
This is how it should be specified:
<dependencies>
<dependency id = "EntityFramework" version = "6.0.0.0" />
</dependencies>

NuGet Package transform a config transform file

Is there a way to make a NuGet package transform a config transform file? For example, when I want my NuGet package to edit a web.config file, I create a web.config.install.xdt file. But what if I want my NuGet package to edit a web.config.debug file?
I tried making a web.config.debug.install.xdt file, but ran into one issue: I cannnot get the transformation to insert attributes that are themselves attributes of xdt transformation. Something like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt1="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel >
<client xdt1:Transform="Insert">
<endpoint address="http://blah.blah" binding="basicHttpBinding" contract="Test.Contract"
name="TestWs" xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</client>
</system.serviceModel>
</configuration>
(I tried changing the namespace of xdt, but that didn't help either.)
Although this isn't perhaps the best answer, it did get the job done for me when I found myself in this situation:
Use the "old" method of doing transforms, not the xdt way.
https://docs.nuget.org/create/Transforming-Configuration-Files-Using-dotTransform-Files.md
This seems to work well, just make sure the appropriate xmlns attribute is in the .transform file.
For example, if you wanted to transform your web.qa.config file that currently looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Tier" value="qa" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
You could add an element:
<add key="RedirectUri" value="yourRedirectUriForQA" xdt:Transform="Replace" />
By adding the following web.qa.config.transform file to your Nuget package:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="RedirectUri" value="yourRedirectUriForQA" xdt:Transform="Replace" />
</appSettings>
</configuration>
Just make sure also to add it to the .nuspec file so it gets picked up when packaged.

nlog files with a date

In a C# 2008 application, I want to write the NLog error log files out so that the files have a date on them. In the example listed below, you can see that I have 3 log files. Can you tell me how place a month-day-year format on these files?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="C:\Logs\NlogOutput.log" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
Use something like this for your fileName parameter:
fileName="${basedir}/${shortdate}.log"
Generally speaking, you can use most NLog LayoutRenderers to help compose your filename.

Orchard, WebForms and iFrames

I am trying to embed an iFrame into a Orchard CMS section (same domain - controls live in a subdirectory off the main Orchard installation). I found two threads on here that talk about the issue I'm having (see here and here), but I'm still running into issues. The pages I am trying to load in the iFrame are standard WebForms and require both WebResource.axd and ScriptResource.axd. I managed to get WebResource.axd working, but ScriptResource is returning a 500 Internal Server Error (according to Chrome), but I can't figure out what's causing the 500 or what the real error is. The relevant entry from my web.config is below - any suggestions?
<handlers accessPolicy="Script">
<!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents -->
<clear />
<!-- Custom Controls -->
<add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
<add name="WebResource" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" preCondition="integratedMode" />
<add name="ScriptResource" path="ScriptResource.axd" verb="GET" type="System.Web.Handlers.ScriptResourceHandler" preCondition="integratedMode" />
<!-- Everything below added from Orchard -->
<!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. -->
<!--<add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script" />-->
<!-- WebApi -->
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Combining Bertrand's suggestion and a lot of playing around, I ended up finding a solution to this.
First, the custom stuff will need to be in a subfolder and inside IIS you can switch that subfolder over to an application (not a virtual directory). For a little extra peace of mind, I also gave it a dedicated app pool so if something did get weird with it the main site wouldn't go down.
The next parts involve a couple of steps - mostly because of that <clear /> entry in system.webServer/handlers. Removing this in the parent app breaks Orchard, but having it in broke my child app since it inherits all the settings from the parent. To get around this, my child app had to have the following system.webServer configuration:
<system.webServer>
<handlers>
<remove name="NotFound" />
<add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
<add name="WebResource" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" preCondition="integratedMode" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<modules>
<remove name="WarmupHttpModule" />
</modules>
</system.webServer>
I used the SO link referenced here to find the "real" ScriptResource.axd reference that was needed and it looks like everything is working.