Ejemplo n.º 1
0
        public void TestGetMissingDependencies_Missing( )
        {
            Solution appA = new Solution
            {
                Name = "appA"
            };
            Solution appB = new Solution
            {
                Name = "appB"
            };
            Solution appC = new Solution
            {
                Name = "appC"
            };

            ApplicationDependency aDependsOnB = new ApplicationDependency
            {
                Name = "appA depends on appB",
                DependentApplication  = appA,
                DependencyApplication = appB
            };

            appA.DependentApplicationDetails.Add(aDependsOnB);

            appA.Save( );

            ApplicationDependency bDependsOnC = new ApplicationDependency
            {
                Name = "appB depends on appC",
                DependentApplication  = appB,
                DependencyApplication = appC
            };

            appB.DependentApplicationDetails.Add(bDependsOnC);

            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appA");
            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB");

            long tenantId = TenantHelper.CreateTenant("ABC");

            AppManager.DeployApp("ABC", Applications.CoreApplicationId.ToString("B"));

            Guid appAUpgradeId = Entity.GetUpgradeId(appA.Id);

            using (new GlobalAdministratorContext( ))
            {
                AppPackage appPackage = SystemHelper.GetLatestPackageByGuid(appAUpgradeId);

                var applicationDependencies = SolutionHelper.GetMissingPackageDependencies(appPackage.Id, tenantId);

                Assert.AreEqual(1, applicationDependencies.Count);

                DependencyFailure dependency = applicationDependencies[0];

                Assert.AreEqual(DependencyFailureReason.Missing, dependency.Reason);
            }
        }
Ejemplo n.º 2
0
        public void TestGetMissingDependencies_InvalidTenant( )
        {
            using (new GlobalAdministratorContext( ))
            {
                AppPackage appPackage = new AppPackage( );

                SolutionHelper.GetMissingPackageDependencies(appPackage, -1);
            }
        }
Ejemplo n.º 3
0
        public void TestGetMissingDependencies( )
        {
            Solution appA = new Solution
            {
                Name = "appA"
            };
            Solution appB = new Solution
            {
                Name = "appB"
            };
            Solution appC = new Solution
            {
                Name = "appC"
            };

            ApplicationDependency aDependsOnB = new ApplicationDependency
            {
                Name = "appA depends on appB",
                DependentApplication  = appA,
                DependencyApplication = appB
            };

            appA.DependentApplicationDetails.Add(aDependsOnB);

            appA.Save( );

            ApplicationDependency bDependsOnC = new ApplicationDependency
            {
                Name = "appB depends on appC",
                DependentApplication  = appB,
                DependencyApplication = appC
            };

            appB.DependentApplicationDetails.Add(bDependsOnC);

            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appA");

            Guid appAUpgradeId = Entity.GetUpgradeId(appA.Id);
            long tenantId      = RequestContext.TenantId;

            using (new GlobalAdministratorContext( ))
            {
                AppPackage appPackage = SystemHelper.GetLatestPackageByGuid(appAUpgradeId);

                SolutionHelper.GetMissingPackageDependencies(appPackage.Id, tenantId);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the package dependencies recursive.
        /// </summary>
        /// <param name="packageId">The package identifier.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="results">The results.</param>
        /// <param name="discoveredPackageIds">The discovered package ids.</param>
        /// <exception cref="ApplicationDependencyException">
        /// </exception>
        private void GetPackageDependenciesRecursive(long packageId, long tenantId, List <MissingDependencyData> results, ISet <Guid> discoveredPackageIds)
        {
            IList <DependencyFailure> applicationDependencies = SolutionHelper.GetMissingPackageDependencies(packageId, tenantId);

            if (applicationDependencies != null && applicationDependencies.Count > 0)
            {
                foreach (DependencyFailure dependency in applicationDependencies)
                {
                    if (dependency.Reason == DependencyFailureReason.BelowMinVersion)
                    {
                        SolutionHelper.EnsureUpgradePath(tenantId, dependency);
                    }

                    string dependencyPackageAppVersionString = null;

                    var dependencyPackageId = SystemHelper.GetPackageIdByGuid(dependency.ApplicationId, dependency.MinVersion, dependency.MaxVersion);

                    if (dependencyPackageId >= 0)
                    {
                        AppPackage dependencyPackage = ReadiNow.Model.Entity.Get <AppPackage>(dependencyPackageId);

                        if (dependencyPackage != null)
                        {
                            dependencyPackageAppVersionString = dependencyPackage.AppVersionString;
                        }
                    }

                    if (!discoveredPackageIds.Contains(dependency.ApplicationId))
                    {
                        discoveredPackageIds.Add(dependency.ApplicationId);

                        if (dependencyPackageId >= 0)
                        {
                            GetPackageDependenciesRecursive(dependencyPackageId, tenantId, results, discoveredPackageIds);
                        }

                        results.Add(new MissingDependencyData(dependency, dependencyPackageId, dependencyPackageAppVersionString));
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void TestGetMissingDependencies_NullPackage( )
 {
     SolutionHelper.GetMissingPackageDependencies(null, 0);
 }
Ejemplo n.º 6
0
        public void TestGetMissingDependencies_NoUpgradePath( )
        {
            Solution appA = new Solution
            {
                Name = "appA",
                SolutionVersionString = "1.0.0.0"
            };
            Solution appB = new Solution
            {
                Name = "appB",
                SolutionVersionString = "1.0.0.0"
            };
            Solution appC = new Solution
            {
                Name = "appC",
                SolutionVersionString = "1.0.0.0"
            };

            ApplicationDependency aDependsOnB = new ApplicationDependency
            {
                Name = "appA depends on appB",
                DependentApplication  = appA,
                DependencyApplication = appB
            };

            appA.DependentApplicationDetails.Add(aDependsOnB);

            appA.Save( );

            ApplicationDependency bDependsOnC = new ApplicationDependency
            {
                Name = "appB depends on appC",
                DependentApplication  = appB,
                DependencyApplication = appC
            };

            appB.DependentApplicationDetails.Add(bDependsOnC);

            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appA");
            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB");
            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appC");

            Guid appAUpgradeId = Entity.GetUpgradeId(appA.Id);
            Guid appBUpgradeId = Entity.GetUpgradeId(appB.Id);

            long tenantId = TenantHelper.CreateTenant("ABC");

            AppManager.DeployApp("ABC", Applications.CoreApplicationId.ToString("B"));
            AppManager.DeployApp("ABC", appAUpgradeId.ToString("B"));

            bDependsOnC.ApplicationMinimumVersion = "2.0.0.0";
            bDependsOnC.Save( );
            appB.SolutionVersionString = "2.0.0.0";
            appB.Save( );

            AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB");

            using (new GlobalAdministratorContext( ))
            {
                AppPackage appPackage = SystemHelper.GetLatestPackageByGuid(appBUpgradeId);

                var applicationDependencies = SolutionHelper.GetMissingPackageDependencies(appPackage.Id, tenantId);

                if (applicationDependencies != null && applicationDependencies.Count > 0)
                {
                    Assert.AreEqual(1, applicationDependencies.Count);

                    DependencyFailure dependency = applicationDependencies[0];

                    if (dependency.Reason == DependencyFailureReason.BelowMinVersion)
                    {
                        SolutionHelper.EnsureUpgradePath(tenantId, dependency);
                    }

                    Assert.AreEqual(DependencyFailureReason.NoUpgradePathAvailable, dependency.Reason);
                }
            }
        }
Ejemplo n.º 7
0
 public void TestGetMissingDependencies_NegativeTenantId( )
 {
     SolutionHelper.GetMissingPackageDependencies(0, -1);
 }
Ejemplo n.º 8
0
 public void TestGetMissingDependencies_NegativePackageId( )
 {
     SolutionHelper.GetMissingPackageDependencies(-1, 0);
 }
Ejemplo n.º 9
0
 public void TestGetMissingDependencies_InvalidPackageId( )
 {
     SolutionHelper.GetMissingPackageDependencies(1234, 0);
 }