• Document Toolkit April 2016 Update

    Announcing the April 2016 update of Document Toolkit for Silverlight. This maintenance release includes fixes for issues reported by customers. For detailed information see the release notes.


    Read More >>
  • XAML Spy 3 January 2016 Update

    Announcing the immediate availability of the January 2016 Update of XAML Spy 3. XAML Spy Express, the free edition of XAML Spy, has been activated in this release, and provides a full-blown visual inspector for free. 


    Read More >>
  • Intense Toolkit updated

    Announcing a massive update of Intense Toolkit. Intense Toolkit is a set of controls, templates, and tools for building Universal Windows Platform apps on Windows 10. The project is completely open source, offering a great start for creating stunning Windows 10 apps. 


    Read More >>
  • XAML Spy 3 Preview 1

    First Floor Software is excited to announce the immediate availability of the first public preview of XAML Spy 3. XAML Spy 3 is a major new release, with lots of new features and changes. Among others version 3 adds support for Android and iOS apps build with Xamarin technology. The new XAML Spy API enables you to automate your apps, and works great with REPLs, such as the ones that come with Roslyn and scriptcs.


    Read More >>
  • Intense Toolkit for UWP

    Announcing a new toolkit for developing Universal Windows Platform apps; Intense. The toolkit provides controls, templates, and tools for building UWP apps with XAML. The Intense Templates extension for Visual Studio 2015 adds five new project templates, a great starting point for building beautiful apps. Intense Templates (formerly known as UWP Templates) previously contained a Blank, SplitView, and two templates for getting started with the Windows Composition APIs.


    Read More >>
  • UWP: new VS2015 project templates

    Announcing additional project templates for creating Universal Windows Platform (UWP) apps in Visual Studio 2015. The project templates serve as a great starting point for creating different type of UWP apps. The Visual Studio extension is named UWP Templates, and includes the following new project templates;


    Read More >>
  • UWP: MSBuild, NuGet 3 and project.json

    Universal Windows app development (UWP) comes with NuGet 3.1, and this version brings a new package configuration file called project.json. No more packages.config, no more angle brackets, apparently curly brackets are the future. For a full introduction of NuGet 3.1 and UWP development, read the article Announcing NuGet 3.1 with Support for Universal Windows Platform.


    Read More >>
  • UWP: using SystemAccentColor

    The personalization settings of Windows 10 includes a Colors section for choosing an accent color that is used throughout the system and by many apps (both modern and traditional desktop apps). The accent color can be set automatic where it is derived from the current background, or you can choose one from the palette as is shown in the following screenshot; 


    Read More >>
  • UWP: enabling Windows.UI.Composition

    If you want to play around with the supercool new Windows.UI.Composition API in Windows Universal apps, you'll need to keep in mind that the API is still in preview. The API is subject to change and a final version is expected to be available later this year. This however should not stop you from giving it a spin.


    Read More >>
  • UWP: where's [UITestMethod]?

    Update Sep 17: This article is now obsolete. It presents a workaround for the missing [UITestMethod] attribute. The workaround is no longer needed, since [UITestMethod] has been re-added in the Tools for Universal Windows apps 1.1 on Sep 16, 2015.

    When using the Visual Studio unit test project to create unit tests, a test method is typically decorated with [TestMethod]. This ensures the method is picked up by the unit test executor. That's all good, but if you attempt to access a XAML UI object in such method, errors do occur.

    Take for instance the following test method;

    [TestMethod]
    public void TestMethod1()
    {
      var brush = new SolidColorBrush(Colors.Red);
      Assert.AreEqual(Colors.Red, brush.Color);
    }
    

    Running this test will result in the following error;

    The application called an interface that was marshalled for a different thread.
    (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).
    If you are using UI objects in test consider using [UITestMethod] attribute instead of [TestMethod] to execute test in UI thread.

    Accessing XAML UI objects require the code to run on the main UI thread. To make that happen, we just need to decorate the test method with [UITestMethod] instead of [TestMethod]. [UITestMethod] ensures the test method is executed on the UI thread, and all was good.

    The problem

    Unfortunately [UITestMethod] is nowhere to be found in the Win10 RTM SDK, even though it is mentioned in the error message. It was available in the Win10 Preview SDK. I do not know the rationale behind this move, is there a compelling reason not to run unit tests on the UI thread? Or did someone forget to include it? A lot of my unit tests now fail for my Win10 universal projects, and I need this fixed.

    The solution

    Luckily, it is very easy to implement your own TestMethod attribute. Taken from the preview SDK, here's a [UITestMethod] implementation that ensures your code is executed on the UI thread. Just include the code in your unit test project, and you should be good.

    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.ApplicationModel.Core;
    using Windows.UI.Core;
    
    namespace Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AppContainer
    {
      public class UITestMethodAttribute : TestMethodAttribute
      {
        public override TestResult[] Execute(ITestMethod testMethod)
        {
          if (testMethod.GetAttributes<AsyncStateMachineAttribute>(false).Length != 0) {
            throw new NotSupportedException("async TestMethod with UITestMethodAttribute are not supported. Either remove async or use TestMethodAttribute.");
          }
    
          TestResult result = null;
    
          CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
            result = testMethod.Invoke(new object[0]);
          }).AsTask().GetAwaiter().GetResult();
    
          return new TestResult[] { result };
        }
      }
    }
    

    With the UITestMethodAttribute implementation in place, we can now decorate our testmethods with [UITestMethod] to ensure the test method is executed on the UI thread.




    Read More >>

Latest News

RSS feed

Subscribe to the RSS feed and receive the latest news from First Floor Software in your favorite RSS reader.

Subscribe