Author Topic: Microsoft Fakes Platform doesn't create ShimApplication class.  (Read 1614 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Microsoft Fakes Platform doesn't create ShimApplication class.
« on: January 02, 2016, 05:41:19 PM »
MS Visual Studio 2015 Enterprise.
AutoCAD 2009 SP3

I need to generate the shims through Microsoft Fakes Platform for some sealed classes of AcMng.dll, AcDbMgd.dll. I wrote these fakes-files:

Code - XML: [Select]
  1. <!-- acmgd.fakes -->
  2. <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  3.   <Assembly Name="acmgd" Version="17.2.0.0"/>
  4.   <StubGeneration>
  5.     <Clear/>
  6.   </StubGeneration>
  7.   <ShimGeneration>
  8.     <Clear />
  9.     <Add FullName=
  10.         "Autodesk.AutoCAD.ApplicationServices.Application"/>
  11.     <Add FullName=
  12.         "Autodesk.AutoCAD.ApplicationServices.DocumentCollection"/>
  13.     <Add FullName=
  14.         "Autodesk.AutoCAD.ApplicationServices.Document"/>
  15.     <Add FullName=
  16.         "Autodesk.AutoCAD.EditorInput.Editor"/>
  17.   </ShimGeneration>
  18. </Fakes>

Code - XML: [Select]
  1. <!-- acdbmgd.fakes -->
  2. <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  3.   <Assembly Name="acdbmgd" Version="17.2.0.0"/>
  4.   <StubGeneration>
  5.     <Clear/>
  6.   </StubGeneration>
  7.   <ShimGeneration>
  8.     <Clear />
  9.     <Add FullName=
  10.         "Autodesk.AutoCAD.DatabaseServices.Database"/>
  11.     <Add FullName=
  12.         "Autodesk.AutoCAD.DatabaseServices.Transaction"/>
  13.   </ShimGeneration>
  14. </Fakes>

The each of these classes is sealed. The *Microsoft Fakes Platform* doesn't create the shim for `Autodesk.AutoCAD.ApplicationServices.Application` (the `ShimApplication` class is not exist in the result):

Quote
The type or namespace name ShimApplication does not exist in the namespace Autodesk.AutoCAD.ApplicationServices.Fakes (are you missing an assembly reference?)

I haven't this problem for Document and DocumentCollection types. I marked the problem through the TODO comment in my "HelloWorld" code:

Code - C#: [Select]
  1. using System;
  2. using System.Diagnostics;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Microsoft.QualityTools.Testing.Fakes;
  5.  
  6. using shim_cad = Autodesk.AutoCAD.ApplicationServices
  7.     .Fakes.ShimApplication; // TODO: ShimApplication is not exist.
  8. using Autodesk.AutoCAD.ApplicationServices.Fakes;
  9. using Autodesk.AutoCAD.DatabaseServices.Fakes;
  10. using Autodesk.AutoCAD.EditorInput.Fakes;
  11.  
  12. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  13. using Autodesk.AutoCAD.ApplicationServices;
  14. using Autodesk.AutoCAD.DatabaseServices;
  15. using Autodesk.AutoCAD.EditorInput;
  16.  
  17. namespace msfakes {
  18.     [TestClass]
  19.     public class UnitTest1 {
  20.  
  21.         /// <summary>
  22.         /// Attempt of Microsoft Fakes using for AutoCAD
  23.         /// </summary>
  24.         [TestMethod]
  25.         public void TestMethod1() {
  26.             using (ShimsContext.Create()) {
  27.  
  28.                 ShimDocument doc = null;
  29.  
  30.                 ShimDocumentCollection docs =
  31.                     new ShimDocumentCollection() {
  32.                         MdiActiveDocumentGet = () => doc
  33.                     };
  34.  
  35.                 shim_cad.DocumentManagerGet = () => docs;
  36.  
  37.                 Assert.IsNull(
  38.                     cad.DocumentManager.MdiActiveDocument);
  39.             }
  40.         }
  41.     }
  42. }

Anybody knows how to fix it?
« Last Edit: January 02, 2016, 06:12:44 PM by Andrey Bushman »