コード例 #1
0
        public async Task ShouldRegisterInstance()
        {
            var mockOdsInstances = MockExtensions.EmptyMockDbSet <OdsInstance>();
            var mockVendors      = MockExtensions.EmptyMockDbSet <Vendor>();
            var mockApps         = MockExtensions.EmptyMockDbSet <Application>();
            var mockUsersContext = new Mock <IUsersContext>();

            mockUsersContext.Setup(c => c.Vendors).Returns(mockVendors.Object);
            mockUsersContext.Setup(c => c.Applications).Returns(mockApps.Object);

            mockUsersContext.Setup(c => c.OdsInstances).Returns(mockOdsInstances.Object);

            var mockApplications = MockExtensions.EmptyMockDbSet <Security.DataAccess.Models.Application>();

            var mockSecurityContext = new Mock <SecurityContext>();

            mockSecurityContext.Object.Applications = mockApplications.Object;

            var command = new AzureFirstTimeSetupService(mockUsersContext.Object, mockSecurityContext.Object, new TestHashProvider(),
                                                         new TestHashConfigurationProvider());

            var odsFirstTimeSetupConfiguration = GetFirstTimeSetupConfiguration();

            var result =
                (await command.CreateAdminAppInAdminDatabase(odsFirstTimeSetupConfiguration.ClaimSet.ClaimSetName,
                                                             odsFirstTimeSetupConfiguration.Name, odsFirstTimeSetupConfiguration.Version,
                                                             ApiMode.SharedInstance)).Application;

            Assert.AreEqual(result.OdsInstance.InstanceType, "CloudOds");
            Assert.AreEqual(result.OdsInstance.IsExtended, false);
            Assert.AreEqual(result.OdsInstance.Name, odsFirstTimeSetupConfiguration.Name);
            Assert.AreEqual(result.OdsInstance.Status, CloudOdsStatus.Ok.DisplayName);
            Assert.AreEqual(result.OdsInstance.Version, odsFirstTimeSetupConfiguration.Version);
        }
コード例 #2
0
        public void ShouldRetryDatabaseMigrations()
        {
            var mockOdsInstances = MockExtensions.EmptyMockDbSet <OdsInstance>();
            var mockVendors      = MockExtensions.EmptyMockDbSet <Vendor>();
            var mockApps         = MockExtensions.EmptyMockDbSet <Application>();
            var mockUsersContext = new Mock <IUsersContext>();

            mockUsersContext.Setup(c => c.Vendors).Returns(mockVendors.Object);
            mockUsersContext.Setup(c => c.Applications).Returns(mockApps.Object);

            int numCalls = 0;

            mockUsersContext.Setup(c => c.OdsInstances).Callback(() =>
            {
                ++numCalls;
                if (numCalls < 5)
                {
                    throw new Exception("Simulated failure");
                }
            }).Returns(mockOdsInstances.Object);

            var mockApplications = MockExtensions.EmptyMockDbSet <Security.DataAccess.Models.Application>();

            var mockSecurityContext = new Mock <ISecurityContext>();

            mockSecurityContext.Setup(c => c.Applications).Returns(mockApplications.Object);

            var command = new AzureFirstTimeSetupService(mockUsersContext.Object, mockSecurityContext.Object, new TestHashProvider(), new TestHashConfigurationProvider());

            command.EnsureAdminDatabaseInitialized();

            command.RunsAttempted.ShouldBe(5);
        }
コード例 #3
0
        public async Task ShouldSetupApplicationAndVendor()
        {
            var mockOdsInstances = MockExtensions.EmptyMockDbSet <OdsInstance>();
            var mockVendors      = MockExtensions.EmptyMockDbSet <Vendor>();
            var mockApps         = MockExtensions.EmptyMockDbSet <Application>();
            var mockUsersContext = new Mock <IUsersContext>();

            mockUsersContext.Setup(c => c.Vendors).Returns(mockVendors.Object);
            mockUsersContext.Setup(c => c.Applications).Returns(mockApps.Object);

            mockUsersContext.Setup(c => c.OdsInstances).Returns(mockOdsInstances.Object);

            var mockApplications = MockExtensions.EmptyMockDbSet <Security.DataAccess.Models.Application>();

            var mockSecurityContext = new Mock <SecurityContext>();

            mockSecurityContext.Object.Applications = mockApplications.Object;

            var command = new AzureFirstTimeSetupService(mockUsersContext.Object, mockSecurityContext.Object, new TestHashProvider(), new TestHashConfigurationProvider());

            var odsFirstTimeSetupConfiguration = GetFirstTimeSetupConfiguration();

            var result =
                (await command.CreateAdminAppInAdminDatabase(odsFirstTimeSetupConfiguration.ClaimSet.ClaimSetName,
                                                             odsFirstTimeSetupConfiguration.Name, odsFirstTimeSetupConfiguration.Version,
                                                             ApiMode.SharedInstance)).Application;

            var expectedApplicationName = odsFirstTimeSetupConfiguration.Name.GetAdminApplicationName();

            Assert.AreEqual(result.ApplicationName, expectedApplicationName);
            Assert.AreEqual(result.ClaimSetName, CloudOdsAdminApp.InternalAdminAppClaimSet);
            Assert.IsTrue(result.ApiClients.Count == 1);
            Assert.AreEqual(result.ApiClients.First(a => !a.UseSandbox).Name, expectedApplicationName);

            Assert.AreEqual(result.Vendor.VendorName, CloudOdsAdminApp.VendorName);
            Assert.AreEqual(result.Vendor.VendorNamespacePrefixes.First().NamespacePrefix, CloudOdsAdminApp.VendorNamespacePrefix);
        }