public async Task Update(Cube3DModel cube3D) { var mappedEntity = ObjectMapper.Mapper.Map <Cube3D>(cube3D) ?? throw new ApplicationException($"Entity could not be mapped."); await _cube3DRepository.Update(mappedEntity); _logger.LogInformation($"Entity successfully updated - {serviceName}"); }
private async Task ValidateIfExist(Cube3DModel Cube3DModel) { var cube3D = await _cube3DRepository.GetById(Cube3DModel.Id); if (cube3D != null) { throw new ApplicationException($"The cube 3D with Id = { Cube3DModel.Id } already exists"); } }
public async Task PostCubes3DIntersectionShouldOverlap() { // Arrange var cubes3DIntersectionApiController = CreateCubes3DIntersectionApiController(); var firstCube3D = new Cube3DModel { PointCoordinates = PointModelFactory.Create(2, 2, 2) }; var secondCube3D = new Cube3DModel { PointCoordinates = PointModelFactory.Create(3, 2, 2) }; var edgesLength = 2; var cube3DIntersectionRequest = new Cube3DIntersectionModel { FirstCube3D = firstCube3D, SecondCube3D = secondCube3D, EdgesLength = edgesLength }; var cube3DIntersectionExpectedResponse = new Cube3DIntersectionModel { FirstCube3D = firstCube3D, SecondCube3D = secondCube3D, EdgesLength = edgesLength, Collision = true, IntersectionVolume = 4 }; _mockCube3DIntersectionService .Setup(ci => ci.Create(cube3DIntersectionRequest)) .ReturnsAsync(cube3DIntersectionExpectedResponse); // Act var createdResponse = await cubes3DIntersectionApiController.PostCubes3DIntersection( cube3DIntersectionRequest); Assert.NotNull(createdResponse); var result = createdResponse.Result as ObjectResult; Assert.Equal(result?.StatusCode, (int)HttpStatusCode.Created); var actualResult = result?.Value as Cube3DIntersectionModel; Assert.IsType <Cube3DIntersectionModel>(actualResult); Assert.True(actualResult.Collision == cube3DIntersectionExpectedResponse.Collision); Assert.True(actualResult.IntersectionVolume.Equals(cube3DIntersectionExpectedResponse.IntersectionVolume)); _mockCube3DIntersectionService.VerifyAll(); }
public async Task <Cube3DModel> Create(Cube3DModel Cube3DModel) { await ValidateIfExist(Cube3DModel); var entity = ObjectMapper.Mapper.Map <Cube3D>(Cube3DModel) ?? throw new Exception($"Entity {nameof(Cube3DModel)} could not be mapped."); var newEntity = await _cube3DRepository.Create(entity); _logger.LogInformation($"Entity successfully added - { serviceName }"); var newMappedEntity = ObjectMapper.Mapper.Map <Cube3DModel>(newEntity); return(newMappedEntity); }
private void MakeCube3DIntersectionRequest( out Cubes3DIntersectionApiController cubes3DIntersectionApiController, out Cube3DModel firstCube3D, out Cube3DModel secondCube3D, out int edgesLength, out Cube3DIntersectionModel cube3DIntersectionRequest) { cubes3DIntersectionApiController = CreateCubes3DIntersectionApiController(); firstCube3D = new Cube3DModel { PointCoordinates = PointModelFactory.Create(2, 2, 2) }; secondCube3D = new Cube3DModel { PointCoordinates = PointModelFactory.Create(4, 2, 2) }; edgesLength = 2; cube3DIntersectionRequest = new Cube3DIntersectionModel { FirstCube3D = firstCube3D, SecondCube3D = secondCube3D, EdgesLength = edgesLength }; }
private async Task <Cube3DModel> UpdateCubeDto(Cube3DModel cube3DModel, double edgesLength) { var CubePointDto = cube3DModel?.PointCoordinates; CubePointDto.Cube3DId = cube3DModel.Id; await _point3DService.Update(CubePointDto); var edgeWithDto = await CreateEdgeDto(CubePointDto.X0, edgesLength, CubePointDto.Cube3DId); var edgeHeightDto = await CreateEdgeDto(CubePointDto.Y0, edgesLength, CubePointDto.Cube3DId); var edgeDepthDto = await CreateEdgeDto(CubePointDto.Z0, edgesLength, CubePointDto.Cube3DId); cube3DModel.Edges = new List <EdgeModel>() { edgeWithDto, edgeHeightDto, edgeDepthDto }; await _cube3DService.Update(cube3DModel); return(cube3DModel); }
public static double IntersectionVolume(this Cube3DModel firstCube, Cube3DModel secondCube) => firstCube.Edges.ElementAt(0).Overlap(secondCube.Edges.ElementAt(0)) * firstCube.Edges.ElementAt(1).Overlap(secondCube.Edges.ElementAt(1)) * firstCube.Edges.ElementAt(2).Overlap(secondCube.Edges.ElementAt(2));
public static bool Collision(this Cube3DModel firstCube, Cube3DModel secondCube) => firstCube.Edges.ElementAt(0).Collision(secondCube.Edges.ElementAt(0)) || firstCube.Edges.ElementAt(1).Collision(secondCube.Edges.ElementAt(1)) || firstCube.Edges.ElementAt(2).Collision(secondCube.Edges.ElementAt(2));