POST
|
Hello Unit Testers, I'm experimenting with MSTest (via VS2010) and nUnit for building .NET class libraries for large modular applications using Arc 10. My main problem is described in the title, but since there's not a great deal of information on the subject I'd like to share a little of my experiences so far as part of the setup to my question. (But if you just want to get to the point, you can go straight to the end of the post 🙂 My goal is to have an automated build process check out the sources and run the unit tests. I also want to be able to test 'internal' classes (internal scoped constructors), but I'm not looking to test private methods. Based on various readings, this appears to be the most robust setup for the long term. MSTest works except for testing internal classes, which is a serious drawback. The problem is that it seems to require a separate project externally referencing the class library under test. For example, if you write some code and want to create a test, adding a new test in VS2010 actually creates a new project containing a template unit test class and adds it to the class lib solution. (A variety of readings around the web indicate other less serious issues relating to MS's infamous version instability, as well as clarity of expressions, among others). One interesting quirk is that, for me, the license manager only works when the tests are run in multi-threaded mode, unlike the discussion here suggests. Otherwise, an error is thrown indicating that the RCW has been separated from the underlying COM object. There are some helpful discussions here and here. Based on these discussions, multi-threaded tests are the way to go for the short term, but it might be worth figuring out STA if this becomes the test environment for the long term. nUnit has a lot of good opinions around the web, and easily accommodates tests within the class library, and therefore tests that instantiate internal classes. This would be my preferred route, except that Arc licensing fails when I run the tests. The licensing fails just at the point of initializing the products, while trying to load the ESRI.ArcGIS.Version assembly. The exact message is: "Could not load file or assembly 'ESRI.ArcGIS.Version, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified.":"ESRI.ArcGIS.Version, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86" My licensing code is adapted from the LicenseInitializer snippet available in the console application template. For example, create a new console application in VS, then click the Project menu, then "Add ArcGIS License Checking". I'm confident the methodology is not a problem, plus there's the fact the same code works under MSTest. So if anyone has any idea why nUnit might be failing here I'd be very grateful for your insights. And of course comments on any of the above points are most welcome. Thanks! -Chris.
... View more
09-22-2011
02:32 AM
|
0
|
1
|
1819
|
POST
|
Neil, Thanks very much for your (as usual) correct response. Changing the EngineOrDesktop option to Desktop solved the problem with opening the file GDB. I'll have to wrap this in a try/catch block. I haven't opened shapefiles with AO in a while and seemed to recall having to pass in the actual shapefile name, but I guess I mis-remembered. If I had read a bit further in the help, I would have seen this. I'll note here that the bug doesn't seem to affect opening the shapefile workspace. Many thanks! -Chris. The workspace for a shapefile is the directory that contains the files that make up the shapefile. The problem with the code that you posted is that you're passing in the path to the *.shp file, which is incorrect. The workspace for a file geodatabase is also a directory. The workspace for a personal geodatabase is the database file. So, make sure you're passing in the correct path for the type of workspace you're trying to open. A recent thread also suggested that there is a bug when binding using the EngineOrDesktop option. If you have Engine installed but not licensed then the binding will fail even if you have Desktop installed and properly licensed.
... View more
09-06-2011
08:55 AM
|
0
|
0
|
861
|
POST
|
I've seen so many previous posts.... Tried all the things I could find, but still get this stubborn error when I try to instantiate a workspace from a file spec. Environment: Windows 7, sp 1 Intel i7, 8Gb RAM Visual Studio 2010, sp 1 Arc version: 10.0.2414 .NET build target: 3.5 I have a very simple example console program to test opening a simple shape file. (I'm actually trying to get a file gdb workspace opened, but that fails as well, so does personal gdb.) All the other posts I've seen have been resolved by one or the other things I've added into the following code, so I'm turning to the real experts 🙂
using System;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
namespace EngineProj
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string gdbName = @"C:\Projects\test\lines.shp";
IWorkspace workspace = null;
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
IAoInitialize ao = new AoInitializeClass();
ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
// This line fails with COMException: Exception from HRESULT: 0x80040228
workspace = workspaceFactory.OpenFromFile(gdbName, 0);
}
}
} Any hints are most appreciated. Thanks! -Chris.
... View more
09-05-2011
08:55 AM
|
0
|
3
|
4607
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|