public void ApproveNewApplication()
        {
            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.ApproveApplicationAsync(app.ApplicationId, false, null).Wait();
                var registration = service.GetApplicationAsync(app.ApplicationId, false).Result;

                Assert.Equal(ApplicationState.Approved, registration.Application.State);

                // reject approved app should fail
                Assert.ThrowsAsync <ResourceInvalidStateException>(
                    () => service.RejectApplicationAsync(app.ApplicationId, false, null)).Wait();

                service.RejectApplicationAsync(app.ApplicationId, true, null).Wait();
                registration = service.GetApplicationAsync(app.ApplicationId, false).Result;

                Assert.Equal(ApplicationState.Rejected, registration.Application.State);
            }
        }
        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.RejectApplicationAsync(null, false, null));

                await Assert.ThrowsAsync <ArgumentNullException>(
                    () => service.RejectApplicationAsync("", false, 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));
            }
        }
        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 ApproveRejectedApplicationForce()
        {
            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.ApproveApplicationAsync(app.ApplicationId, false, null).Wait();
                service.RejectApplicationAsync(app.ApplicationId, true, null).Wait();
                var registration = service.GetApplicationAsync(app.ApplicationId, false).Result;
                Assert.Equal(ApplicationState.Rejected, registration.Application.State);
            }
        }