async Task PerformTestsExpectSuccess(int studyId, params string[] rolesToAdd)
        {
            var responseDto = StudyParticipantAdderAndRemover.CreateParticipantLookupDto();

            foreach (var curRole in rolesToAdd)
            {
                var studyParticipantAddConversation = await StudyParticipantAdderAndRemover.AddAndExpectSuccess(_restHelper, studyId, curRole, responseDto);

                AddStudyParticipantsAsserts.ExpectSuccess(curRole, studyParticipantAddConversation.Request, studyParticipantAddConversation.Response);
            }
        }
        async Task PerformTestsExpectFailure(int studyId, params string[] rolesToAdd)
        {
            var responseDto = StudyParticipantAdderAndRemover.CreateParticipantLookupDto();

            foreach (var curRole in rolesToAdd)
            {
                var studyParticipantAddConversation = await StudyParticipantAdderAndRemover.AddAndExpectFailure(_restHelper, studyId, curRole, responseDto);

                ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyParticipantAddConversation.Response);
            }
        }
示例#3
0
        async Task PerformTestsExpectFailure(int studyId, string roleToRemove)
        {
            var studyParticipantRemoveConversation = await StudyParticipantAdderAndRemover.RemoveAndExpectFailure(_restHelper, studyId, TestUserConstants.COMMON_NEW_PARTICIPANT_DB_ID, roleToRemove);

            ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyParticipantRemoveConversation.Response);
        }
示例#4
0
        //[InlineData(false, true)]
        //[InlineData(true, true)]
        public async Task AddStudyAndSandboxAndVm_WithRequiredRole_ShouldSucceed(bool isAdmin, bool isSponsor)
        {
            Trace.WriteLine("START AddStudyAndSandboxAndVm_WithRequiredRole_ShouldSucceed");
            await WithBasicSeeds();

            SetScenario(isEmployee: true, isAdmin: isAdmin, isSponsor: isSponsor);

            //CREATE STUDY
            var studyCreateConversation = await StudyCreator.CreateAndExpectSuccess(_restHelper);
            CreateStudyAsserts.ExpectSuccess(studyCreateConversation.Request, studyCreateConversation.Response);

            //CREATE STUDY SPECIFIC DATASET
            var datasetSeedResponse = await DatasetCreator.Create(_restHelper, studyCreateConversation.Response.Content.Id);
            var datasetCreateRequest = datasetSeedResponse.Request;
            var datasetResponseWrapper = datasetSeedResponse.Response;
            CreateDatasetAsserts.ExpectSuccess(datasetCreateRequest, datasetResponseWrapper);

            var createDatasetResponse = datasetResponseWrapper.Content;

            //CREATE SANDBOX
            var sandboxSeedResponse = await SandboxCreator.CreateAndExpectSuccess(_restHelper, studyCreateConversation.Response.Content.Id);
            var sandboxCreateRequest = sandboxSeedResponse.Request;
            var sandboxResponseWrapper = sandboxSeedResponse.Response;

            SandboxDetailsAsserts.NewlyCreatedExpectSuccess(sandboxCreateRequest, sandboxResponseWrapper);

            var sandboxResponse = sandboxResponseWrapper.Content;

            //ADD DATASET TO SANDBOX
            var addDatasetToSandboxResponse = await SandboxOperations.AddDataset(_restHelper, sandboxResponse.Id, createDatasetResponse.Id);
            var sandboxDatasetResponseWrapper = addDatasetToSandboxResponse.Response;
            AddDatasetToSandboxAsserts.ExpectSuccess(createDatasetResponse.Id, createDatasetResponse.Name, createDatasetResponse.Classification, "Open", sandboxDatasetResponseWrapper);

            //CREATE VM
            var virtualMachineSeedResponse = await VirtualMachineCreator.Create(_restHelper, sandboxResponse.Id);
            var virtualMachineCreateRequest = virtualMachineSeedResponse.Request;
            var virtualMachineResponseWrapper = virtualMachineSeedResponse.Response;

            CreateVirtualMachineAsserts.ExpectSuccess(virtualMachineCreateRequest, sandboxResponse.Region, virtualMachineResponseWrapper);

            //GET SANDBOX RESOURCE LIST AND ASSERT RESULT BEFORE CREATION
            var sandboxResourcesPreProvisioningResponseWrapper = await _restHelper.Get<List<SandboxResourceLight>>($"api/sandboxes/{sandboxResponse.Id}/resources");
            SandboxResourceListAsserts.BeforeProvisioning(sandboxResourcesPreProvisioningResponseWrapper, virtualMachineResponseWrapper.Content.Name);

            //GET SANDBOX VM LIST AND ASSERT RESULT BEFORE CREATION
            var virtualMachinesPreProvisioningResponseWrapper = await GenericReader.ReadAndAssertExpectSuccess<List<VmDto>>(_restHelper, GenericReader.SandboxVirtualMachines(sandboxResponse.Id));
            SandboxVirtualMachineAsserts.BeforeProvisioning(virtualMachinesPreProvisioningResponseWrapper.Response, virtualMachineResponseWrapper.Content.Name);

            //SETUP INFRASTRUCTURE BY RUNNING A METHOD ON THE API            
            var processWorkQueueResponse = await ProcessWorkQueue();

            //GET SANDBOX RESOURCE LIST AND ASSERT RESULT
            var sandboxResourcesResponseWrapper = await _restHelper.Get<List<SandboxResourceLight>>($"api/sandboxes/{sandboxResponse.Id}/resources");
            SandboxResourceListAsserts.AfterProvisioning(sandboxResourcesResponseWrapper, virtualMachineResponseWrapper.Content.Name);

            //TODO: GET SANDBOX VM LIST AND ASSERT RESULT
            var virtualMachinesAfterProvisioningResponseWrapper = await GenericReader.ReadAndAssertExpectSuccess<List<VmDto>>(_restHelper, GenericReader.SandboxVirtualMachines(sandboxResponse.Id));
            SandboxVirtualMachineAsserts.AfterProvisioning(virtualMachinesAfterProvisioningResponseWrapper.Response, virtualMachineResponseWrapper.Content.Name);

            //Add some participants

            var studyParticipantResponse = await StudyParticipantAdderAndRemover.AddAndExpectSuccess(_restHelper, studyCreateConversation.Response.Content.Id, StudyRoles.SponsorRep,
                StudyParticipantAdderAndRemover.CreateParticipantLookupDto());

            var getStudy = await _restHelper.Get<StudyDetailsDto>($"api/studies/{studyCreateConversation.Response.Content.Id}");

            var studyParticipant = getStudy.Content.Participants.Find(x => x.UserId == studyParticipantResponse.Response.Content.UserId);

            AddStudyParticipantsAsserts.ExpectSuccess(StudyRoles.SponsorRep, studyParticipant, studyParticipantResponse.Response);

            var vmRuleExtended = await _restHelper.Get<VmRuleDto>($"api/virtualmachines/{virtualMachineResponseWrapper.Content.Id}/extended");

            //OPEN INTERNET
            var openInternetResponse = await SandboxOperations.OpenInternetForVm<VmRuleDto>(_restHelper, virtualMachineResponseWrapper.Content.Id);

            SandboxVirtualMachineRuleAsserts.ExpectSuccess(openInternetResponse.Response.Content, vmRuleExtended.Content);

            await SandboxOperations.CloseInternetForVm<VmRuleDto>(_restHelper, virtualMachineResponseWrapper.Content.Id);

            //MOVE TO NEXT PHASE
            var sandboxAfterMovingToNextPhase = await SandboxOperations.MoveToNextPhase<SandboxDetails>(_restHelper, sandboxResponseWrapper.Content.Id);

            SandboxDetailsAsserts.AfterPhaseShiftExpectSuccess(sandboxAfterMovingToNextPhase.Response);
            
            //DELETE VM
            var deleteVmConversation = await SandboxOperations.DeleteVm(_restHelper, virtualMachineResponseWrapper.Content.Id);
            ApiResponseBasicAsserts.ExpectNoContent(deleteVmConversation.Response);

            //RUN WORKER
            await ProcessWorkQueue();

            //ASSERT THAT VM DISSAPEARS
            var sandboxVmsAfterDelete = await _restHelper.Get<List<VmDto>>($"api/virtualmachines/forsandbox/{sandboxResponseWrapper.Content.Id}");

            SandboxVirtualMachineAsserts.AfterProvisioning(sandboxVmsAfterDelete, "vm-studyname-sandboxnam-integrationtest");

            //TRY TO DELETE STUDY, GET ERROR
            await StudyDeleter.DeleteAndExpectFailure(_restHelper, studyCreateConversation.Response.Content.Id);

            //DELETE SANDBOX
            await SandboxDeleter.DeleteAndExpectSuccess(_restHelper, sandboxResponseWrapper.Content.Id);

            //DELETE STUDY

            await StudyDeleter.DeleteAndExpectSuccess(_restHelper, studyCreateConversation.Response.Content.Id);
            Trace.WriteLine("START AddStudyAndSandboxAndVm_WithRequiredRole_ShouldSucceed");
        }