Hi Luke,
Have you end up with any solution?
Could you suggest me any way to solve that problem?
ArcEmiEditorTest.DataConnectionTest.GetGDBConnection_ReturnTrue:
System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {588E5A11-D09B-11D1-AA7C-00C04FA33A15} failed due to the following error: 80040154 Sınıf kaydedilmemiş (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Luke, Tugba,
You may get this kind of error if you don't bind to an ArcObjects license before running the test. You can do so in the Arrange section of your test or in a setup method that is run before all tests. For example, with NUnit, if you have all your tests in one assembly, it is sufficient to have one class with the SetUpFixture attribute and a one-line method to bind the license:
[SetUpFixture] public class GetLicense { [SetUp] public void TestSetUp() { RuntimeManager.BindLicense(ProductCode.Desktop, LicenseLevel.Standard) } }
With regard to mocking, I prefer using NUnit with NSubstitute, and it works quite well. Luckily, in ArcObjects everything has an interface and can be mocked. Sometimes you need to mock several interfaces in one object, but NSubstitute lets you do this, or you can write your own interface and inherit as many of the ArcObjects interfaces as you need and then mock them with NSubstitute.
Yep, the Failed to create COM object error is always due to licensing. As Fridjof says, you need to activate your license before trying to create any Arcobjects.
You don't need to do this if you are using mocks though. I've been testing with Visual Studio 2010 unit tests and Moq - there is very little doc available on how to use Moq with ArcObjects, but it's quite easy to figure out with the quickstart guide. You just have to remember to add every cast, call, return value, etc. to your mock. Any time you need an actual object in your test code, just use mock.Object.
For example, here's a FeatureWorkspace that has an AliasName property and you can call the OpenFeatureClass method:
// mock feature workspace object // has AliasName and can OpenFeatureClass var mockFeatureWorkspace = new Mock<IFeatureWorkspace>(); var mockFC = new Mock<IFeatureClass>(); mockFC.Setup(x => x.AliasName).Returns(featureClassName); mockFeatureWorkspace.Setup(x => x.OpenFeatureClass(It.IsAny<string>())).Returns(mockFC.Object); GeodatabaseManager.FeatureWorkspace = mockFeatureWorkspace.Object;
GeodatabaseManager and featureClassName are variables used in my test.