public void QueryApplicationsByClientAndServerApplicationType()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose()) {
                mock.Provide <IIoTHubTwinServices>(IoTHubServices.Create(devices));
                mock.Provide <IApplicationRepository, ApplicationTwins>();
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var records = service.QueryApplicationsAsync(new ApplicationRegistrationQueryModel {
                    ApplicationType = ApplicationType.ClientAndServer
                }, null).Result;

                // Assert
                Assert.Equal(apps.Count(x =>
                                        x.ApplicationType == ApplicationType.ClientAndServer), records.Items.Count);
            }
        }
        public void ListAllApplicationsUsingQuery()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var records = service.QueryApplicationsAsync(null, null).Result;

                // Assert
                Assert.True(apps.IsSameAs(records.Items));
            }
        }
示例#3
0
        public void GetApplicationThatExists()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);
            var first = apps.First();

            using (var mock = AutoMock.GetLoose()) {
                mock.Provide <IIoTHubTwinServices>(IoTHubServices.Create(devices));
                mock.Provide <IApplicationRepository, ApplicationTwins>();
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var result = service.GetApplicationAsync(
                    ApplicationInfoModelEx.CreateApplicationId(site,
                                                               first.ApplicationUri, first.ApplicationType), false).Result;

                // Assert
                Assert.True(result.Application.IsSameAs(apps.First()));
                Assert.True(result.Endpoints.Count == 0);
            }
        }
示例#4
0
        public void UnregisterApplications()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose()) {
                var hub = IoTHubServices.Create(devices);
                mock.Provide <IIoTHubTwinServices>(hub);
                mock.Provide <IApplicationRepository, ApplicationTwins>();
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                foreach (var app in apps)
                {
                    service.UnregisterApplicationAsync(app.ApplicationId, null).Wait();
                }

                // Assert
                Assert.Empty(hub.Devices);
            }
        }
        public void DisableEnableApplication()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                var app = apps.First();
                service.DisableApplicationAsync(app.ApplicationId, null).Wait();
                var registration = service.GetApplicationAsync(app.ApplicationId, false).Result;
                Assert.NotNull(registration.Application.NotSeenSince);
                service.EnableApplicationAsync(app.ApplicationId, null).Wait();
                registration = service.GetApplicationAsync(app.ApplicationId, false).Result;
                Assert.Null(registration.Application.NotSeenSince);
            }
        }
        public void QueryApplicationsByApplicationNameDifferentCase()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var records = service.QueryApplicationsAsync(new ApplicationRegistrationQueryModel {
                    ApplicationName = apps.First().ApplicationName.ToUpperInvariant()
                }, null).Result;

                // Assert
                Assert.True(records.Items.Count == 0);
            }
        }
        public void GetApplicationThatDoesNotExist()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var t = service.GetApplicationAsync("test", false);

                // Assert
                Assert.NotNull(t.Exception);
                Assert.IsType <AggregateException>(t.Exception);
                Assert.IsType <ResourceNotFoundException>(t.Exception.InnerException);
            }
        }
        public void QueryApplicationsByDiscoveryServerApplicationType()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var records = service.QueryApplicationsAsync(new ApplicationRegistrationQueryModel {
                    ApplicationType = ApplicationType.DiscoveryServer
                }, null).Result;

                // Assert
                Assert.Equal(apps.Count(x => x.ApplicationType == ApplicationType.DiscoveryServer), records.Items.Count);
            }
        }
        public void RejectApproveWhenDisabledApplicationShouldAlwaysFail()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            using (var mock = AutoMock.GetLoose()) {
                var hub = IoTHubServices.Create(devices);
                mock.Provide <IIoTHubTwinServices>(hub);
                mock.Provide <IApplicationRepository, ApplicationTwins>();
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                var app = apps.First();
                service.DisableApplicationAsync(app.ApplicationId, null).Wait();

                Assert.ThrowsAsync <ResourceInvalidStateException>(
                    () => service.ApproveApplicationAsync(app.ApplicationId, false, null)).Wait();
                Assert.ThrowsAsync <ResourceInvalidStateException>(
                    () => service.RejectApplicationAsync(app.ApplicationId, false, null)).Wait();
                Assert.ThrowsAsync <ResourceInvalidStateException>(
                    () => service.ApproveApplicationAsync(app.ApplicationId, true, null)).Wait();
                Assert.ThrowsAsync <ResourceInvalidStateException>(
                    () => service.RejectApplicationAsync(app.ApplicationId, true, null)).Wait();
            }
        }
        public void GetApplicationThatExists()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);
            var first = apps.First();

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(devices);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                var result = service.GetApplicationAsync(
                    ApplicationInfoModelEx.CreateApplicationId(site,
                                                               first.ApplicationUri, first.ApplicationType), false).Result;

                // Assert
                Assert.True(result.Application.IsSameAs(apps.First()));
                Assert.True(result.Endpoints.Count == 0);
            }
        }
        public void UnregisterApplications()
        {
            CreateAppFixtures(out var site, out var super, out var apps, out var devices);

            var hub = IoTHubServices.Create(devices);

            using (var mock = AutoMock.GetLoose(builder => {
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
                builder.RegisterType <ApplicationTwins>().As <IApplicationRepository>();
            })) {
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                // Run
                foreach (var app in apps)
                {
                    service.UnregisterApplicationAsync(app.ApplicationId, null).Wait();
                }

                // Assert
                Assert.Empty(hub.Devices);
            }
        }
示例#12
0
        public async Task BadArgShouldThrowExceptions()
        {
            using (var mock = AutoMock.GetLoose()) {
                var hub = new IoTHubServices();
                mock.Provide <IIoTHubTwinServices>(hub);
                mock.Provide <IApplicationRepository, ApplicationTwins>();
                IApplicationRegistry service = mock.Create <ApplicationRegistry>();

                await Assert.ThrowsAsync <ArgumentNullException>(
                    () => service.RegisterApplicationAsync(null));

                await Assert.ThrowsAsync <ArgumentNullException>(
                    () => service.GetApplicationAsync(null, false));

                await Assert.ThrowsAsync <ArgumentNullException>(
                    () => service.GetApplicationAsync("", false));

                await Assert.ThrowsAsync <ResourceNotFoundException>(
                    () => service.GetApplicationAsync("abc", false));

                await Assert.ThrowsAsync <ResourceNotFoundException>(
                    () => service.GetApplicationAsync(Guid.NewGuid().ToString(), false));
            }
        }
 /// <summary>
 /// Create controller
 /// </summary>
 /// <param name="applications"></param>
 /// <param name="onboarding"></param>
 public ApplicationsController(IApplicationRegistry applications,
                               IOnboardingServices onboarding)
 {
     _applications = applications;
     _onboarding   = onboarding;
 }