Skip to content

Instantly share code, notes, and snippets.

View nathanwoulfe's full-sized avatar

Nathan Woulfe nathanwoulfe

View GitHub Profile
@nathanwoulfe
nathanwoulfe / RunTests.ps1
Created June 8, 2019 00:24
Powershell script to run VS tests and output coverage reports
"install tools:"
&dotnet tool install dotnet-reportgenerator-globaltool --tool-path . --version 4.0.12
&dotnet tool install coverlet.console --tool-path . --version 1.4.1
"`nmake reports dir:"
md .\reports -Force
"`nrun tests:"
$unitTestFile = gci -Recurse | ?{ $_.FullName -like "*bin\*Plumber.Testing.dll" }
Write-Host "`$unitTestFile value: $unitTestFile"
@nathanwoulfe
nathanwoulfe / Appveyor.yml
Created June 8, 2019 00:31
Appveyor config for Umbraco CI
# version format
version: 1.0.0.{build}
image: Visual Studio 2017
cache:
- packages -> **\packages.config
- c:\projects\plumber8\plumber.web\node_modules -> **\packages.json
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX will only be used for Release builds
@nathanwoulfe
nathanwoulfe / azure-pipelines.yml
Created June 8, 2019 00:32
DevOps pipeline config for Umbraco package CI
trigger:
- master
- refs/tags/v*
pool:
vmImage: 'windows-latest'
variables:
solution: '**/Plumber8.sln'
buildPlatform: 'Any CPU'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.WebApi;
@nathanwoulfe
nathanwoulfe / angularjs-events.js
Created February 6, 2020 01:52
Log all events in an AngularJs application
angular.module('myModule', [])
.config(['$provide', $provide => {
$provide.decorator("$rootScope", function ($delegate) {
var Scope = $delegate.constructor;
var origBroadcast = Scope.prototype.$broadcast;
var origEmit = Scope.prototype.$emit;
Scope.prototype.$broadcast = function () {
console.log("$broadcast was called on $scope " + Scope.$id + " with arguments:", arguments);
return origBroadcast.apply(this, arguments);
@nathanwoulfe
nathanwoulfe / render-macros.cs
Last active March 2, 2020 23:02
Processing Umbraco macros
///
/// Extension on UmbracoHelper to return a processed macro as a string...
///
public static IHtmlString RenderMacroScript(this UmbracoHelper helper, string language, string fileLocation, IDictionary<string, object> parameters)
{
var ctrl = new umbraco.presentation.templateControls.Macro
{
Language = language,
FileLocation = fileLocation,
};
@nathanwoulfe
nathanwoulfe / compile.js
Created May 18, 2020 23:24
Compiling HTML into the Umbraco 8 backoffice
// in u7 we could grab scope off any element via angular.element('selector').scope()
// not the case in u8, since debugInfoEnabled has been set to false (which is a good thing)
// this is happening in the context of a content app controller
// but could be refactored to working with an interceptor
export class AppController {
constructor($scope, $compile, $element) {
// from the content app scope, find the content form scope
@nathanwoulfe
nathanwoulfe / nested-form.js
Created June 13, 2020 07:12
How clean are my children?
this.workflowResource.saveNodeConfig(this.node.id, this.approvalPath, this.variant)
.then(() => {
this.notificationsService.success('SUCCESS', 'Workflow configuration updated');
this.$rootScope.$broadcast('configUpdated');
this.$scope.contentFlowForm.$setPristine();
// shouldn't need to do this...
// check that all child forms of the contentForm are pristine, then reset contentForm
let parentPristine = this.$scope.contentFlowForm.$$parentForm.$$controls
.filter(c => Object.prototype.hasOwnProperty.call(c, '$submitted'))
@nathanwoulfe
nathanwoulfe / test-content-event-component.cs
Created November 24, 2020 23:01
Minimal component for testing
using System;
using System.Linq;
using System.Web.Http.Filters;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace Foo.Bar.AppCode
{
@nathanwoulfe
nathanwoulfe / test.cs
Created April 12, 2021 23:57
Mock IUmbracoContextFactory
private readonly IUmbracoContextFactory _context;
private readonly string _pluginPath;
public LicensingService(ILogger logger, IUmbracoContextFactory context) : base(logger)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_pluginPath = $"{IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/')}/plumber/";
}
public Tuple<string, string> GetLicenseAndKey() {