Ejemplo n.º 1
0
        public void TestGetPlatform()
        {
            // Arrange
            var ms = new MarketplaceService();

            // there should be no platforms in the system, normally
            var t  = DateTime.Now;
            var mp = new ManagedPlatform
            {
                Name        = "MyServer",
                DatabaseId  = "myserver.foo.con",
                LastContact = t
            };

            mp.Save();

            // Act
            Action a = () => ms.GetPlatform(null);

            a.ShouldNotThrow();

            // Should pull the most recently heard from platform... for now
            var p = ms.GetPlatform(null);

            // Assert
            p.Should().NotBeNull();
            p.Name.Should().Be(mp.Name);
            p.DatabaseId.Should().Be(mp.DatabaseId);
            p.LastContact.Should().Be(t);
        }
Ejemplo n.º 2
0
        public void TestDeleteUser()
        {
            ManagedPlatform p = null;
            ManagedTenant   t = null;
            ManagedUser     u = null;

            try
            {
                // Arrange
                var ps = new PlatformService();

                p = CreateTestPlatform();
                t = CreateTestTenant(p);
                u = CreateTestUser(t);
                p.Save();

                p.Should().NotBeNull();
                t.Should().NotBeNull();
                u.Should().NotBeNull();

                var pid = p.Id;
                var tid = t.Id;
                var uid = u.Id;

                // Act
                ps.DeleteUser(TestPlatformId, TestTenantName, TestUserName);

                // Assert
                var e1 = Entity.Get(pid);
                e1.Should().NotBeNull();

                var e2 = Entity.Get(tid);
                e2.Should().NotBeNull();

                var e3 = Entity.Get(uid);
                e3.Should().BeNull();
            }
            finally
            {
                if (u != null)
                {
                    Entity.Delete(u);
                }
                if (t != null)
                {
                    Entity.Delete(t);
                }
                if (p != null)
                {
                    Entity.Delete(p);
                }
            }
        }
Ejemplo n.º 3
0
        public void TestCreateOrUpdateThrows()
        {
            ManagedPlatform p = null;

            try
            {
                // Arrange
                var ps = new PlatformService();

                // Act
                Action f1 = () => { p = (ManagedPlatform)ps.CreateOrUpdate(null); };

                // Assert
                f1.ShouldThrow <ArgumentException>().WithMessage("Platform information was invalid.");

                Action f2 = () => { p = (ManagedPlatform)ps.CreateOrUpdate(new RemotePlatformInfo()); };
                f2.ShouldThrow <ArgumentException>().WithMessage("Platform information was invalid.");

                Action f3 = () => { p = (ManagedPlatform)ps.CreateOrUpdate(new RemotePlatformInfo {
                        Id = TestPlatformId
                    }); };
                f3.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: host");

                Action f4 = () => { p = (ManagedPlatform)ps.CreateOrUpdate(new RemotePlatformInfo {
                        Id = TestPlatformId, FrontEndHost = "HOST"
                    }); };
                f4.ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: catalog");
            }
            finally
            {
                if (p != null)
                {
                    Entity.Delete(p);
                }
            }
        }
Ejemplo n.º 4
0
        public void TestCreateOrUpdate()
        {
            ManagedPlatform  p  = null;
            PlatformFrontEnd fe = null;
            PlatformDatabase db = null;

            try
            {
                // Arrange
                var ps = new PlatformService();
                var pi = new RemotePlatformInfo
                {
                    Id             = TestPlatformId,
                    FrontEndHost   = "test",
                    FrontEndDomain = "platform.co",
                    Database       = "db",
                    DatabaseServer = "ds",
                    Apps           = new List <AvailableApplication>(),
                    Tenants        = new TenantList()
                };
                var t = DateTime.UtcNow;

                // Act
                p = (ManagedPlatform)ps.CreateOrUpdate(pi);

                // Assert
                p.Should().NotBeNull();
                p.DatabaseId.Should().Be(pi.Id);
                p.Name.Should().Be(pi.Id.ToLowerInvariant());
                p.LastContact.Should().BeBefore(DateTime.UtcNow).And.BeAfter(t);
                p.ContainsTenants.Should().NotBeNull().And.BeEmpty();
                p.AvailableAppVersions.Should().NotBeNull().And.BeEmpty();
                p.FrontEndHistory.Should().NotBeNullOrEmpty();
                p.FrontEndHistory.Count.Should().Be(1);

                fe = p.FrontEndHistory.First();
                fe.Name.Should().Be("test.platform.co");
                fe.Host.Should().Be("test");
                fe.Domain.Should().Be("platform.co");
                fe.LastContact.Should().BeBefore(DateTime.UtcNow).And.BeAfter(t);

                p.DatabaseHistory.Should().NotBeNullOrEmpty();
                p.DatabaseHistory.Count.Should().Be(1);

                db = p.DatabaseHistory.First();
                db.Name.Should().Be("ds (db)");
                db.Catalog.Should().Be("db");
                db.Server.Should().Be("ds");
                db.LastContact.Should().BeBefore(DateTime.UtcNow).And.BeAfter(t);
            }
            finally
            {
                if (db != null)
                {
                    Entity.Delete(db);
                }
                if (fe != null)
                {
                    Entity.Delete(fe);
                }
                if (p != null)
                {
                    Entity.Delete(p);
                }
            }
        }
Ejemplo n.º 5
0
        public void TestUpdateInstalledApplications()
        {
            ManagedPlatform   p = null;
            ManagedTenant     t = null;
            ManagedAppVersion v = null;

            try
            {
                // Arrange
                var ps = new PlatformService();

                // Act
                t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>());

                // Assert
                t.Should().BeNull();

                p = CreateTestPlatform();
                t = CreateTestTenant(p);
                p.Save();

                t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>());
                t.Should().NotBeNull();
                t.Name.Should().Be(TestTenantName);
                t.Platform.DatabaseId.Should().Be(TestPlatformId);
                t.HasAppsInstalled.Count.Should().Be(0);

                var tid = t.Id;

                t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>
                {
                    new InstalledApplication {
                        ApplicationVersionId = TestAppVersionId
                    }
                });

                t.Should().NotBeNull();
                t.Id.Should().Be(tid);
                t.Name.Should().Be(TestTenantName);
                t.Platform.DatabaseId.Should().Be(TestPlatformId);
                t.HasAppsInstalled.Count.Should().Be(1);

                v = t.HasAppsInstalled.First();
                v.Name.Should().BeNull();
                v.PublishDate.Should().NotHaveValue();
                v.Version.Should().BeNull();
                v.VersionId.Should().Be(TestAppVersionId);
                v.Application.Should().BeNull();
                v.RequiredApps.Should().BeEmpty();
                v.RequiredAppVersions.Should().BeEmpty();

                var vid = v.Id;

                t = (ManagedTenant)ps.UpdateInstalledApplications(TestPlatformId, TestTenantName, new List <InstalledApplication>
                {
                    new InstalledApplication
                    {
                        ApplicationVersionId = TestAppVersionId,
                        Name            = "Test App Version",
                        ReleaseDate     = new DateTime(2000, 10, 24),
                        PackageVersion  = "2.3.3.0",
                        SolutionVersion = "1.7.7.0"
                    }
                });

                t.Should().NotBeNull();
                t.Id.Should().Be(tid);
                t.Name.Should().Be(TestTenantName);
                t.Platform.DatabaseId.Should().Be(TestPlatformId);
                t.HasAppsInstalled.Count.Should().Be(1);

                v = t.HasAppsInstalled.First();
                v.Id.Should().Be(vid);
                v.Name.Should().Be("Test App Version");
                v.PublishDate.Should().HaveValue().And.Be(new DateTime(2000, 10, 24));
                v.Version.Should().Be("1.7.7.0");
                v.VersionId.Should().Be(TestAppVersionId);
                v.Application.Should().BeNull();
                v.RequiredApps.Should().BeEmpty();
                v.RequiredAppVersions.Should().BeEmpty();
            }
            finally
            {
                if (v != null)
                {
                    Entity.Delete(v);
                }
                if (t != null)
                {
                    Entity.Delete(t);
                }
                if (p != null)
                {
                    Entity.Delete(p);
                }
            }
        }
Ejemplo n.º 6
0
        public void TestCreateOrUpdateUser()
        {
            ManagedPlatform p = null;
            ManagedTenant   t = null;
            ManagedUser     u = null;

            try
            {
                // Arrange
                var ps = new PlatformService();
                var ui = new RemoteUserInfo
                {
                    Name = TestUserName
                };

                // Act
                u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui);

                // Assert
                u.Should().BeNull();

                p = CreateTestPlatform();
                t = CreateTestTenant(p);
                p.Save();

                u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui);
                u.Should().BeNull();

                ui.RemoteId = TestUserRemoteId;

                u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, ui);
                u.Should().NotBeNull();
                u.Name.Should().Be(TestUserName);
                u.RemoteId.Should().Be(TestUserRemoteId.ToString());
                u.Status_Enum.Should().Be(ManagedUserStatusEnumeration.Unknown);
                u.Tenant.Name.Should().Be(TestTenantName);
                u.Tenant.Platform.DatabaseId.Should().Be(TestPlatformId);

                var uid = u.Id;

                u = (ManagedUser)ps.CreateOrUpdateUser(TestPlatformId, TestTenantName, new RemoteUserInfo
                {
                    RemoteId = TestUserRemoteId,
                    Name     = "Another Name",
                    Status   = UserStatus.Expired
                });

                u.Should().NotBeNull();
                u.Id.Should().Be(uid);
                u.Name.Should().Be("Another Name");
                u.RemoteId.Should().Be(TestUserRemoteId.ToString());
                u.Status_Enum.Should().Be(ManagedUserStatusEnumeration.Expired);
                u.Tenant.Name.Should().Be(TestTenantName);
                u.Tenant.Platform.DatabaseId.Should().Be(TestPlatformId);
            }
            finally
            {
                if (u != null)
                {
                    Entity.Delete(u);
                }
                if (t != null)
                {
                    Entity.Delete(t);
                }
                if (p != null)
                {
                    Entity.Delete(p);
                }
            }
        }