public async void DeleteResource_ValidConfigId_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel
            {
                ResourceType = ResourceTypeEnum.ResultConfig,
                ResourceId   = "e019f476-b413-4ee7-965b-a4c0389cd086"
            };
            var       httpService        = new HttpService(new HttpClient());
            var       resultConfigClient = new ResultConfigClient(httpService);
            Exception exception          = null;

            try
            {
                // Act
                await resultConfigClient.DeleteResource(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
        public async void UnmarkSimPlan_MarkedSimPlanModel_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.SimPlan,
                "5b07ddcf52e35100015f04e3"
                );
            var projectId     = "be69cb8c-45e4-4d80-8d55-419984aa2151";
            var httpService   = new HttpService(new HttpClient());
            var simPlanClient = new SimPlanClient(
                httpService
                );
            Exception exception = null;

            try
            {
                // Act
                await simPlanClient.UnmarkSimPlan(dependantResourceModel, projectId);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
Exemplo n.º 3
0
        public async void DeleteResource_ValidSimRunId_NoExceptionThrown()
        {
            // Arrange
            var projectId = "be69cb8c-45e4-4d80-8d55-419984aa2151";
            var dependantResourceModel = new DependantResourceModel
            {
                ResourceType = ResourceTypeEnum.SimRun,
                ResourceId   = "5b07ddd052e35100015f04e4"
            };
            var       httpService  = new HttpService(new HttpClient());
            var       simRunClient = new SimRunClient(httpService);
            Exception exception    = null;

            try
            {
                // Act
                await simRunClient.DeleteResource(dependantResourceModel, projectId);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
Exemplo n.º 4
0
        public async void DeleteResource_ValidResultDataId_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel
            {
                ResourceType = ResourceTypeEnum.ResultData,
                ResourceId   = "7ada0dd6-0bd8-4872-9344-25555ca652a8"
            };
            var       httpService      = new HttpService(new HttpClient());
            var       resultDataClient = new ResultDataClient(httpService);
            Exception exception        = null;

            try
            {
                // Act
                await resultDataClient.DeleteResource(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
        public async void UnmarkScenario_MarkedScenarioModel_NoExceptionThrown()
        {
            // Assert
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.Scenario,
                "aad965db-fceb-4ee2-bd06-c89ab182ca4c"
                );
            var httpService    = new HttpService(new HttpClient());
            var scenarioClient = new ScenarioClient(
                httpService
                );
            Exception exception = null;

            try
            {
                // Act
                await scenarioClient.UnmarkScenario(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
        public async Task UnmarkSimPlan(
            DependantResourceModel dependantResourceModel,
            string projectId
            )
        {
            if (await DoesSimPlanExist(dependantResourceModel.ResourceId, projectId))
            {
                var simPlanModel = await GetSimPlan(dependantResourceModel.ResourceId, projectId);

                simPlanModel.ToBeDeleted = false;

                var response = await _httpService.PutAsync(
                    $"http://{_baseUrl}/simplan?id={simPlanModel.Id}&projectid={projectId}",
                    simPlanModel
                    );

                response.ThrowExceptionIfNotSuccessfulResponse(
                    new FailedToUpdateResourceException(
                        await response.FormatRequestAndResponse(
                            $"Failed to update simPlan with id: {simPlanModel.Id}, projectId: {projectId} from sim-runner-svc!"
                            )
                        )
                    );
            }
        }
Exemplo n.º 7
0
        public async void DeleteResource_ValidMetadataId_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel
            {
                ResourceType = ResourceTypeEnum.Metadata,
                ResourceId   = "c9de8a5e-1ab1-431f-a759-f44d7eef4e19"
            };
            var       httpService = new HttpService(new HttpClient());
            var       fileClient  = new FileClient(httpService);
            Exception exception   = null;

            try
            {
                // Act
                await fileClient.DeleteResource(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
Exemplo n.º 8
0
        public async void UnmarkSimRun_MarkedSimRunModel_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.SimRun,
                "5b07ddd052e35100015f04e4"
                );
            var httpService  = new HttpService(new HttpClient());
            var simRunClient = new SimRunClient(
                httpService
                );
            Exception exception = null;

            try
            {
                // Act
                await simRunClient.UnmarkSimRun(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }


            // Assert
            Assert.Null(exception);
        }
        public async void UnmarkResultData_MarkedResultDataModel_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.ResultData,
                "c9de8a5e-1ab1-431f-a759-f44d7eef4e19"
                );
            var httpService      = new HttpService(new HttpClient());
            var resultDataClient = new ResultDataClient(
                httpService
                );
            Exception exception = null;

            try
            {
                // Act
                await resultDataClient.UnmarkResultData(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
        public async void DeleteResource_ValidScenarioId_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel
            {
                ResourceType = ResourceTypeEnum.Scenario,
                ResourceId   = "6aad965db-fceb-4ee2-bd06-c89ab182ca4c"
            };
            var       httpService    = new HttpService(new HttpClient());
            var       scenarioClient = new ScenarioClient(httpService);
            Exception exception      = null;

            try
            {
                // Act
                await scenarioClient.DeleteResource(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
Exemplo n.º 11
0
        public async void UnmarkMetadata_MarkedMetadataModel_NoExceptionThrown()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.Metadata,
                "c9de8a5e-1ab1-431f-a759-f44d7eef4e19"
                )
            {
                PreviousState = MetadataModel.FinishedState
            };
            var httpService    = new HttpService(new HttpClient());
            var metadataClient = new MetadataClient(
                httpService
                );
            Exception exception = null;

            try
            {
                // Act
                await metadataClient.UnmarkMetadata(dependantResourceModel);
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.Null(exception);
        }
Exemplo n.º 12
0
        public async Task UnmarkMetadata(
            DependantResourceModel dependantResourceModel
            )
        {
            var response = await _httpService.PutAsync(
                $"http://{_baseUrl}/metadata/{dependantResourceModel.ResourceId}/state?state={dependantResourceModel.PreviousState}",
                ""
                );

            /**
             * Sometimes the HttpClient gets corrupted and it sends a malformed request to the metadata-svc only.
             * Because of the time limitation, a workaround has been made which creates a new client for this request only.
             */
            if (response.StatusCode == HttpStatusCode.MethodNotAllowed)
            {
                response = await new HttpService(new HttpClient()).PutAsync(
                    $"http://{_baseUrl}/metadata/{dependantResourceModel.ResourceId}/state?state={dependantResourceModel.PreviousState}",
                    ""
                    );
            }

            response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                new FailedToUpdateResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to update {dependantResourceModel} from metadata-svc!"
                        )
                    )
                );
        }
Exemplo n.º 13
0
        public async Task <DependantResourceModel> MarkMetadata(
            MetadataModel metadataModel
            )
        {
            if (MetadataModel.ToBeDeletedState.Equals(metadataModel.State))
            {
                throw new ResourceAlreadyMarkedException(
                          $"Cannot mark metadata with id: {metadataModel.DataId}, it is already marked!"
                          );
            }

            if (!MetadataModel.FinishedState.Equals(metadataModel.State) &&
                !MetadataModel.FailedState.Equals(metadataModel.State)
                )
            {
                throw new CannotMarkResourceException(
                          $"Cannot mark metadata with id: {metadataModel.DataId}, it must be in state: {MetadataModel.FinishedState} or state: {MetadataModel.FailedState} beforehand!"
                          );
            }

            var response = await _httpService.PutAsync(
                $"http://{_baseUrl}/metadata/{metadataModel.DataId}/state?state={MetadataModel.ToBeDeletedState}",
                ""
                );

            /**
             * Sometimes the HttpClient gets corrupted and it sends a malformed request to the metadata-svc only.
             * Because of the time limitation, a workaround has been made which creates a new client for this request only.
             */
            if (response.StatusCode == HttpStatusCode.MethodNotAllowed)
            {
                response = await new HttpService(new HttpClient()).PutAsync(
                    $"http://{_baseUrl}/metadata/{metadataModel.DataId}/state?state={MetadataModel.ToBeDeletedState}",
                    ""
                    );
            }

            response.ThrowExceptionIfNotSuccessfulResponse(
                new FailedToUpdateResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to update metadata with id: {metadataModel.DataId} from metadata-svc!"
                        )
                    )
                );

            var markedResource = new DependantResourceModel(ResourceTypeEnum.Metadata, metadataModel.DataId)
            {
                PreviousState = metadataModel.State
            };

            return(markedResource);
        }
Exemplo n.º 14
0
        public async Task UnmarkResultData(DependantResourceModel dependantResourceModel)
        {
            var response = await _httpService.DeleteAsync(
                $"http://{_baseUrl}/resultData/mongodb-result/{dependantResourceModel.ResourceId}/marks"
                );

            response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                new FailedToUpdateResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to update resultData with id: {dependantResourceModel.ResourceId} from database-utility-svc!"
                        )
                    )
                );
        }
Exemplo n.º 15
0
        public async Task DeleteResource(
            DependantResourceModel dependantResourceModel
            )
        {
            var response = await _httpService.DeleteAsync(
                $"http://{_baseUrl}/scenarios/{dependantResourceModel.ResourceId}"
                );

            response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                new FailedToDeleteResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to delete {dependantResourceModel} from scenario-svc!"
                        )
                    )
                );
        }
Exemplo n.º 16
0
        private async Task UnmarkResource(
            DependantResourceModel dependantResourceModel,
            string projectId
            )
        {
            switch (dependantResourceModel.ResourceType)
            {
            case ResourceTypeEnum.Project:
                await _projectClient.UnmarkProject(dependantResourceModel);

                break;

            case ResourceTypeEnum.Metadata:
                await _metadataClient.UnmarkMetadata(dependantResourceModel);

                break;

            case ResourceTypeEnum.Scenario:
                await _scenarioClient.UnmarkScenario(dependantResourceModel);

                break;

            case ResourceTypeEnum.ResultConfig:
                break;

            case ResourceTypeEnum.SimPlan:
                await _simPlanClient.UnmarkSimPlan(dependantResourceModel, projectId);

                break;

            case ResourceTypeEnum.SimRun:
                await _simRunClient.UnmarkSimRun(dependantResourceModel);

                break;

            case ResourceTypeEnum.ResultData:
                await _resultDataClient.UnmarkResultData(dependantResourceModel);

                break;

            default:
                throw new UnknownResourceTypeException(
                          $"{dependantResourceModel} is unknown!"
                          );
            }
        }
Exemplo n.º 17
0
        public async Task UnmarkSimRun(DependantResourceModel dependantResourceModel)
        {
            var simRunMarkUpdateModel = new SimRunMarkUpdateModel(dependantResourceModel.ResourceId, false);

            var response = await _httpService.PutAsync(
                $"http://{_baseUrl}/simrun/marks",
                simRunMarkUpdateModel
                );

            response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                new FailedToUpdateResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to update simRun with id: {dependantResourceModel.ResourceId} from sim-runner-svc!"
                        )
                    )
                );
        }
Exemplo n.º 18
0
        public async Task DeleteResource(
            DependantResourceModel dependantResourceModel,
            string projectId
            )
        {
            if (await DoesSimRunExist(dependantResourceModel.ResourceId, projectId))
            {
                var response = await _httpService.DeleteAsync(
                    $"http://{_baseUrl}/simrun?simRunId={dependantResourceModel.ResourceId}"
                    );

                response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                    new FailedToDeleteResourceException(
                        await response.FormatRequestAndResponse(
                            $"Failed to delete {dependantResourceModel} from sim-runner-svc!"
                            )
                        )
                    );
            }
        }
 public async Task UnmarkProject(
     DependantResourceModel dependantResourceModel
     )
 {
     try
     {
         await _projectServiceClient.UpdateProjectAsync(
             new UpdateProjectRequest
         {
             ProjectId   = dependantResourceModel.ResourceId,
             ToBeDeleted = "false"
         }
             );
     }
     catch (Exception e)
     {
         throw new FailedToUpdateResourceException(
                   $"Failed to update project with id: {dependantResourceModel.ResourceId} from project-svc!",
                   e
                   );
     }
 }
        public async void UnmarkProject_InvalidDependantResourceModel_ThrowsException()
        {
            // Arrange
            var dependantResourceModel = new DependantResourceModel(
                ResourceTypeEnum.Project,
                "0"
                );
            var       projectClient = new ProjectClient();
            Exception exception     = null;

            try
            {
                // Act
                await projectClient.UnmarkProject(dependantResourceModel);
            }
            catch (FailedToUpdateResourceException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
        }
Exemplo n.º 21
0
        public async Task UnmarkScenario(
            DependantResourceModel dependantResourceModel
            )
        {
            var scenarioModel = new ScenarioModel
            {
                ScenarioId  = dependantResourceModel.ResourceId,
                ToBeDeleted = false,
                ReadOnly    = false
            };

            var response = await _httpService.PutAsync(
                $"http://{_baseUrl}/scenarios/{scenarioModel.ScenarioId}/marks",
                scenarioModel
                );

            response.ThrowExceptionIfNotSuccessfulResponseOrNot404Response(
                new FailedToUpdateResourceException(
                    await response.FormatRequestAndResponse(
                        $"Failed to update {dependantResourceModel} from scenario-svc!"
                        )
                    )
                );
        }