public static async Task <ApiConversation <Common.Dto.ErrorResponse> > ReadAndAssertExpectForbidden(RestHelper restHelper, string url) { var conversation = await Read <Common.Dto.ErrorResponse>(restHelper, url); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(conversation.Response); return(conversation); }
public static void SandboxResourceAsserts(ApiResponseWrapper <List <SandboxResourceLight> > responseWrapper, bool createFinished) { ApiResponseBasicAsserts.ExpectSuccess <List <SandboxResourceLight> >(responseWrapper); var index = 0; foreach (var curResource in responseWrapper.Content) { if (index > 4) { break; } Assert.NotNull(curResource.Name); IsRequiredType(index, curResource); if (createFinished) { Assert.Equal(CloudResourceStatus.OK, curResource.Status); } else { Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } index++; } }
public static async Task <ApiConversation <T> > ReadAndAssertExpectSuccess <T>(RestHelper restHelper, string url) { var conversation = await Read <T>(restHelper, url); ApiResponseBasicAsserts.ExpectSuccess(conversation.Response); return(conversation); }
public static void VmAsserts(ApiResponseWrapper <List <SandboxResourceLight> > responseWrapper, bool vmDeleted, bool vmDeleteFinished, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <SandboxResourceLight> >(responseWrapper); var index = 0; foreach (var curResource in responseWrapper.Content) { if (index < 4) { continue; } Assert.NotNull(curResource.Name); IsRequiredType(index, curResource, expectedVmNames); if (!vmDeleted) { Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } else if (vmDeleted && !vmDeleteFinished) { Assert.Contains(CloudResourceStatus.DELETING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } else if (vmDeleteFinished) { Assert.Contains(CloudResourceStatus.DELETING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } index++; } }
public static void ExpectSuccess(DatasetCreateUpdateInputBaseDto createRequest, ApiResponseWrapper <DatasetDto> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <DatasetDto>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Equal(createRequest.Name, responseWrapper.Content.Name); Assert.Equal(createRequest.Classification, responseWrapper.Content.Classification); }
public static void NewlyCreatedExpectSuccess(SandboxCreateDto createRequest, ApiResponseWrapper <SandboxDetails> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <SandboxDetails>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Equal(createRequest.Name, responseWrapper.Content.Name); Assert.Equal(createRequest.Region, responseWrapper.Content.Region); }
public async Task Throw_IfUserLacksRequiredRole(bool isEmployee, bool isDatasetAdmin) { SetScenario(isEmployee: isEmployee, isDatasetAdmin: isDatasetAdmin); var studyCreateConversation = await StudyCreator.CreateAndExpectFailure(_restHelper); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyCreateConversation.Response, "does not have permission to perform operation"); }
public static void ExpectSuccess(VirtualMachineCreateDto createRequest, string sandboxRegion, ApiResponseWrapper <VmDto> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <VmDto>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Contains(createRequest.Name, responseWrapper.Content.Name); Assert.Equal(createRequest.OperatingSystem, responseWrapper.Content.OperatingSystem); Assert.Equal(sandboxRegion, responseWrapper.Content.Region);//Same region as sandbox }
async Task PerformTestExpectForbidden(int studyId) { var updateRequest = new StudyDto() { Name = "newName", Vendor = "newVendor" }; var studyDeleteConversation = await StudyUpdater.UpdateAndExpectFailure(_restHelper, studyId, updateRequest); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyDeleteConversation.Response, "does not have permission to perform operation"); }
public static void ExpectSuccess(ApiResponseWrapper <SandboxResourceLight> responseWrapper, string statusShouldContain) { ApiResponseBasicAsserts.ExpectSuccess <SandboxResourceLight>(responseWrapper); var sandboxResourceResponse = responseWrapper.Content; Assert.NotNull(sandboxResourceResponse.Name); Assert.Null(sandboxResourceResponse.RetryLink); Assert.Contains(statusShouldContain, sandboxResourceResponse.Status); }
public async Task Read_Study_WithoutRelevantRoles_ShouldFail(bool employee, bool isSponsor, bool datasetAdmin) { SetScenario(isEmployee: employee, isSponsor: isSponsor, isDatasetAdmin: datasetAdmin); await WithUserSeeds(); var createdStudy = await WithStudyCreatedByOtherUser(restricted : true); var studyReadConversation = await GenericReader.ReadExpectFailure(_restHelper, GenericReader.StudyUrl(createdStudy.Id)); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyReadConversation.Response, "does not have permission to perform operation"); }
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); } }
public static void AfterProvisioning(ApiResponseWrapper <List <VmDto> > responseWrapper, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <VmDto> >(responseWrapper); var sandboxResourceResponse = responseWrapper.Content; var index = 0; foreach (var curResource in sandboxResourceResponse) { Assert.NotNull(curResource.Name); Assert.Equal(CloudResourceStatus.OK, curResource.Status); index++; } }
public static void ExpectSuccess(int datasetId, string datasetName, string classification, string totalClassification, ApiResponseWrapper <AvailableDatasets> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <AvailableDatasets>(responseWrapper); Assert.NotEmpty(responseWrapper.Content.Datasets); Assert.Equal(totalClassification, responseWrapper.Content.Classification); var newlyAddedDataset = responseWrapper.Content.Datasets.SingleOrDefault(ds => ds.DatasetId == datasetId); Assert.NotNull(newlyAddedDataset); Assert.Equal(datasetId, newlyAddedDataset.DatasetId); Assert.Equal(datasetName, newlyAddedDataset.Name); Assert.Equal(classification, newlyAddedDataset.Classification); Assert.True(newlyAddedDataset.AddedToSandbox); }
public static void BeforeProvisioning(ApiResponseWrapper <List <VmDto> > responseWrapper, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <VmDto> >(responseWrapper); var sandboxVmResponse = responseWrapper.Content; var index = 0; foreach (var curResource in sandboxVmResponse) { Assert.NotNull(curResource.Name); Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); index++; } }
public async Task Read_StudyList_WithoutRelevantRoles_ShouldFail(bool datasetAdmin) { SetScenario(isDatasetAdmin: datasetAdmin); await WithUserSeeds(); _ = await WithStudyCreatedByCurrentUser(false); _ = await WithStudyCreatedByCurrentUser(true); _ = await WithStudyCreatedByOtherUser(false); _ = await WithStudyCreatedByOtherUser(true); var studyReadConversation = await GenericReader.ReadExpectSuccess <List <StudyListItemDto> >(_restHelper, GenericReader.StudiesUrl()); ApiResponseBasicAsserts.ExpectSuccess <List <StudyListItemDto> >(studyReadConversation.Response); Assert.Empty(studyReadConversation.Response.Content); }
public async Task Read_StudyList_ShouldOnlyContainRelevantRestrictedStudies(bool employee, string myRole) { SetScenario(isEmployee: employee); await WithUserSeeds(); var studyThisUserShouldSee = await WithStudyCreatedByOtherUser(true, new List <string> { myRole }); var studyThisUserShouldNotSee = await WithStudyCreatedByOtherUser(true); var studyReadConversation = await GenericReader.ReadExpectSuccess <List <StudyListItemDto> >(_restHelper, GenericReader.StudiesUrl()); ApiResponseBasicAsserts.ExpectSuccess <List <StudyListItemDto> >(studyReadConversation.Response); Assert.NotEmpty(studyReadConversation.Response.Content); Assert.NotNull(studyReadConversation.Response.Content.FirstOrDefault(s => s.Id == studyThisUserShouldSee.Id)); Assert.Null(studyReadConversation.Response.Content.FirstOrDefault(s => s.Id == studyThisUserShouldNotSee.Id)); }
async Task PerformTestExpectSuccess(int studyId) { var studyDeleteConversation = await GenericDeleter.DeleteAndExpectSuccess(_restHelper, GenericDeleter.StudyUrl(studyId)); ApiResponseBasicAsserts.ExpectNoContent(studyDeleteConversation.Response); }
async Task PerformTestsExpectFailure(int sandboxId) { var sandboxCreateConversation = await GenericPoster.PostAndExpectFailure(_restHelper, GenericPoster.SandboxNextPhase(sandboxId)); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(sandboxCreateConversation.Response); }
public static void AfterPhaseShiftExpectSuccess(ApiResponseWrapper <SandboxDetails> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <SandboxDetails>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Equal(SandboxPhase.DataAvailable, responseWrapper.Content.CurrentPhase); }
async Task PerformTestsExpectFailure(int studyId) { var sandboxCreateConversation = await SandboxCreator.CreateAndExpectFailure(_restHelper, studyId); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(sandboxCreateConversation.Response); }
async Task PerformTestExpectForbidden(int studyId) { var studyReadConversation = await GenericDeleter.DeleteAndExpectFailure(_restHelper, GenericDeleter.StudyUrl(studyId)); ApiResponseBasicAsserts.ExpectForbiddenWithMessage(studyReadConversation.Response); }
//[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"); }
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); }