Esempio 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);
            }
        }
        public void TestEnable()
        {
            const string test = "foo";

            try
            {
                // Arrange
                var ts = new TenantService();

                using (new GlobalAdministratorContext())
                {
                    var id = TenantHelper.CreateTenant(test);
                    id.Should().BeGreaterThan(0);

                    var tenant = Entity.Get <Tenant>(id).AsWritable <Tenant>();
                    tenant.IsTenantDisabled = true;
                    tenant.Save();
                }

                // Act
                ts.Enable(test);

                // Assert
                using (new GlobalAdministratorContext())
                {
                    var tid = TenantHelper.GetTenantId(test);
                    tid.Should().BeGreaterThan(0);

                    var result = Entity.Get <Tenant>(tid);
                    result.Should().NotBeNull();
                    result.IsTenantDisabled.Should().BeFalse();
                }

                Action a1 = () => ts.Enable(null);
                a1.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid.");

                Action a2 = () => ts.Enable(string.Empty);
                a2.ShouldThrow <ArgumentException>().WithMessage("The specified tenantName parameter is invalid.");

                var    notATenant = Guid.NewGuid().ToString();
                Action a3         = () => ts.Enable(notATenant);
                a3.ShouldThrow <Exception>().WithMessage("Tenant " + notATenant + " not found.");
            }
            finally
            {
                using (new GlobalAdministratorContext())
                {
                    var testId = TenantHelper.GetTenantId(test);
                    if (testId > 0)
                    {
                        TenantHelper.DeleteTenant(testId);
                    }
                }
            }
        }
Esempio n. 3
0
        public void AddTenant()
        {
            long tenantId = 0;

            try
            {
                tenantId = TenantHelper.CreateTenant("TenantHelperTests_AddTenant");
            }
            finally
            {
                if (tenantId != 0)
                {
                    TenantHelper.DeleteTenant(tenantId);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Creates the tenant.
        /// </summary>
        /// <param name="tenantName">Name of the tenant.</param>
        /// <remarks></remarks>
        public static void CreateTenant(string tenantName)
        {
            using (new GlobalAdministratorContext( ))
            {
                /////
                // Check for existing tenant
                /////
                long tenantId = TenantHelper.GetTenantId(tenantName);

                if (tenantId != -1)
                {
                    // Fail, the tenant already exists.
                    Console.WriteLine(@"The tenant {0} already exists.", tenantName);
                    return;
                }

                TenantHelper.CreateTenant(tenantName);
            }
        }
        public void TestDelete()
        {
            const string test = "foo";

            try
            {
                // Arrange
                var ts = new TenantService();

                using (new GlobalAdministratorContext())
                {
                    var id = TenantHelper.CreateTenant(test);
                    id.Should().BeGreaterThan(0);
                }

                // Act
                ts.Delete(test);

                // Assert
                using (new GlobalAdministratorContext())
                {
                    TenantHelper.GetTenantId(test).Should().BeLessThan(0);
                }

                Action a1 = () => ts.Delete(null);
                a1.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: tenantName");

                Action a2 = () => ts.Delete(string.Empty);
                a2.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: tenantName");
            }
            finally
            {
                using (new GlobalAdministratorContext())
                {
                    var testId = TenantHelper.GetTenantId(test);
                    if (testId > 0)
                    {
                        TenantHelper.DeleteTenant(testId);
                    }
                }
            }
        }
        public void TestRename()
        {
            const string test = "foo";
            const string name = "new";

            try
            {
                // Arrange
                var ts = new TenantService();

                long id;
                using (new GlobalAdministratorContext())
                {
                    id = TenantHelper.CreateTenant(test);
                }

                id.Should().BeGreaterThan(0);

                // Act
                ts.Rename(id, name);

                // Assert
                long nid;
                using (new GlobalAdministratorContext())
                {
                    var tid = TenantHelper.GetTenantId(test);
                    tid.Should().BeLessThan(0);

                    nid = TenantHelper.GetTenantId(name);
                    nid.Should().BeGreaterThan(0);
                }

                Action a1 = () => ts.Rename(-1, null);
                a1.ShouldThrow <ArgumentException>().WithMessage("New tenant name may not be null or empty.\r\nParameter name: name");

                Action a2 = () => ts.Rename(-1, string.Empty);
                a2.ShouldThrow <ArgumentException>().WithMessage("New tenant name may not be null or empty.\r\nParameter name: name");

                Action a3 = () => ts.Rename(-1, name);
                a3.ShouldThrow <Exception>().WithMessage("Tenant not found.");

                Action a4 = () => ts.Rename(nid, name); // same
                a4.ShouldNotThrow();
            }
            finally
            {
                using (new GlobalAdministratorContext())
                {
                    var testId = TenantHelper.GetTenantId(test);
                    if (testId > 0)
                    {
                        TenantHelper.DeleteTenant(testId);
                    }

                    var newId = TenantHelper.GetTenantId(name);
                    if (newId > 0)
                    {
                        TenantHelper.DeleteTenant(newId);
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Creates the tenant.
 /// </summary>
 /// <param name="tenantName">Name of the tenant.</param>
 public static void CreateTenant(string tenantName)
 {
     TenantHelper.CreateTenant(tenantName);
 }
Esempio n. 8
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);
                }
            }
        }