public void Setup()
        {
            LogHelper.ConfigureConsoleLogger();

            StaticStartup.Startup();

            _newId             = Guid.NewGuid();
            _tenantId          = Guid.NewGuid();
            _inspectionService = Substitute.For <IInspectionService>();
            _inspectionService.When(s => s.BeginInspectionAsync(Arg.Any <Inspection>()))
            .Do(v => ((Inspection)v[0]).Id = _newId);
            _inspectionService.BeginInspectionAsync(Arg.Any <Inspection>()).ReturnsForAnyArgs(_newId);
            _tenantIdProvider = Substitute.For <ITenantIdProvider>();
            _tenantIdProvider.GetTenantId().Returns(_tenantId);

            _incompleteInspection = new Inspection()
            {
            };
        }
示例#2
0
        public async Task <IActionResult> PostInspection([FromBody] InspectionPostDto inspectionDto)
        {
            if (inspectionDto == null)
            {
                return(InvalidRequestBodyJson(nameof(InspectionDto)));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newInspection = Mapper.Map <Inspection>(inspectionDto);

            newInspection.TenantId = _tenantIdProvider.GetTenantId();
            try
            {
                var newId = await _inspectionService.BeginInspectionAsync(newInspection);

                return(Created(nameof(GetInspection), new CreatedWithGuidDto {
                    Id = newId
                }));
            }
            catch (ItemAlreadyExistsException ex)
            {
                if (ex.Id.HasValue)
                {
                    // should yield 'found' response status code
                    return(RedirectToAction(nameof(GetInspection), new CreatedWithGuidDto {
                        Id = ex.Id.Value
                    }));
                }
                throw new Exception(
                          $"Exception of type {nameof(ItemAlreadyExistsException)} should have Id defined"
                          );
            }
        }