public void RejectNewApplication() { 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.RejectApplicationAsync(app.ApplicationId, false, null).Wait(); var registration = service.GetApplicationAsync(app.ApplicationId, false).Result; Assert.Equal(ApplicationState.Rejected, registration.Application.State); // reject approved app should fail Assert.ThrowsAsync <ResourceInvalidStateException>( () => service.ApproveApplicationAsync(app.ApplicationId, false, null)).Wait(); service.ApproveApplicationAsync(app.ApplicationId, true, null).Wait(); registration = service.GetApplicationAsync(app.ApplicationId, false).Result; Assert.Equal(ApplicationState.Approved, registration.Application.State); } }
public void DoubleApproveApplicationDoesNothing() { 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.ApproveApplicationAsync(app.ApplicationId, false, null).Wait(); var registration = service.GetApplicationAsync(app.ApplicationId, false).Result; Assert.Equal(ApplicationState.Approved, registration.Application.State); } }
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(); } }