Esri / arcgis-enterprise-sdk-resources

Apache License 2.0
20 stars 23 forks source link

Unit test Enterprise SDK #24

Closed gmarbury closed 2 years ago

gmarbury commented 2 years ago

In the documentation, it states the following,

"Therefore, it's highly recommended that the extension code with business logic be tested on a local project for unit testing first and then tested with a service, as this will reduce the work of debugging the extension on ArcGIS Server."

However, as of 10.9.1 with the ArcMapRuntime not installed, most of the classes appear not to be able to be co-created in a Unit Test project. Please provide a sample Unit test project that creates an IWorkspace and/or IMapserver that can be passed into unit test code not running in the SOE. Here is an example project that I can not get to work.

EnterpriseSdkUnitTest.zip .

gmarbury commented 2 years ago

This Unit test Class does NOT work

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntSDK.Tests
{
    [TestClass]
    public  class EntSDK_TestClass
    {
        [TestMethod]
        public void TestCreateSdeWorkspaceFactory()
        {

            IWorkspaceFactory2 wf = new ESRI.ArcGIS.DatasourcesGDB.SdeWorkspaceFactoryClass();

            if( wf != null )
            {
                System.Diagnostics.Debug.WriteLine(wf.GetClassID().Value.ToString());
            }
        }
        [TestMethod]
        public void TestCreateMapServer()
        {

            var ms = new ESRI.ArcGIS.Carto.MapServerClass();

            if (ms != null)
            {
                System.Diagnostics.Debug.WriteLine(ms.TypeName);
            }
        }

        [TestMethod]
        public void TestCreateGeometry()
        {

            var pt = new ESRI.ArcGIS.Geometry.PointClass();

            if (pt != null)
            {
                System.Diagnostics.Debug.WriteLine(pt.GeometryType);
            }
        }

        static IAoInitialize initializeClass;

        [AssemblyInitialize]
        static public void AssemblyInit(TestContext context)
        {
            try
            {
                initializeClass = new AoInitializeClass();

                initializeClass.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

        [AssemblyCleanup]
        static public void AssemblyCleanup()
        {
            if( initializeClass != null )
            {
                initializeClass.Shutdown();
            }

        }
    }
}
hanhansun commented 2 years ago

Unlike ArcObjects SDK, Enterprise SDK doesn't support building or running a standalone project, so it's not possible to write unit testing either in a standalone console application or in the Java Maven test for functions using the APIs provided by Enterprise SDK, such as creating or connecting to a workspace, and accessing IMapServer or other services. Even though AoInitialize is provided by Enterprise SDK, it's no longer valid and is not designed to authorize a standalone project to use the SDK's APIs. The only way to call these APIs and run the code is to test them in an SOE or SOI deployed on the server.

The documentation you referred to only applies to ArcObjects SDK, and doesn't apply to Enterprise SDK, because you can't run Enterprise SDK's APIs on a "local project". This content is indeed misleading and we will remove it from the help documentation. It will take about a week for this change to be applied to the online help page.

gmarbury commented 2 years ago

Thank you for your response. It's unfortunate that the solution is to remove a "highly recommended" statement. The statement in the documentation is absolutely correct, it IS extremely difficult to create SOIs and SOEs inside a running service. Furthermore, when code or dependencies change this is the preferred way to ensure a bug has not been introduced or reintroduced. These processes have been in place for years using sound development practices. To just remove the ability, coupled with documented Enterprise SDK API classes that exist but are "no longer valid". Is extremely frustrating.

hanhansun commented 2 years ago

If your extension references other third-party APIs or .NET libraries for your business logic, such as using Json.NET to parse certain JSON objects or sending a REST request to a service, then you can write unit testing for these functions and run it in a local project. This is a scenario where what the documentation suggests can apply.

Since Enterprise SDK currently doesn't support running in a standalone application, we don't want to mislead other users to assume that the SDK's APIs work in a standalone application.

Can you submit an enhancement request via Technical Support to request running Enterprise SDK's APIs in a standalone application? In this way, we can track this request and consider this feature for future releases.

gmarbury commented 2 years ago

Sure, where? What link should I use?

hanhansun commented 2 years ago

You can contact Technical Support here: https://support.esri.com/en/contact-tech-support

Once you request a case referencing our discussions on this Github issue, a support specialist should be able to help submit the enhancement request and provide you with the defect number. You can then log in to My Esri and track the status of the enhancement request.