예제 #1
0
        /// <inheritdoc/>
        public async Task <int?> CreateItemAsync(NewUploadedItem upload)
        {
            var s3UploadResponse = await this.s3UnicornRepository.UploadImageToS3(upload.Image, upload.Unicorn.image);

            if (s3UploadResponse != 200 & s3UploadResponse != 201)
            {
                return(null);
            }

            return(await this.unicornRepository.CreateUnicornAsync(upload.Unicorn));
        }
        public void CreateUnicorn_WhenCalled_ReturnBadRequest()
        {
            this.GivenUnicornService();
            this.GivenRekognitionService();
            this.GivenUnicornController();
            var unicorn = new Unicorn {
                unicorn_id = Guid.NewGuid()
            };
            var uploadItem = new NewUploadedItem {
                Unicorn = unicorn, Image = this.fakeImageBytes2
            };
            var result = this.unicornController.CreateUnicorn(uploadItem).Result.Result;

            result.Should().BeOfType <BadRequestObjectResult>();
        }
        public void CreateUnicorn_WhenCalled_CreatedActionGetUnicorn()
        {
            this.GivenUnicornService();
            this.GivenRekognitionService();
            this.GivenUnicornController();
            var unicorn = new Unicorn {
                unicorn_id = Guid.NewGuid()
            };
            var uploadItem = new NewUploadedItem {
                Unicorn = unicorn, Image = this.fakeImageBytes1
            };
            var result = this.unicornController.CreateUnicorn(uploadItem).Result.Result as CreatedAtActionResult;

            result.ActionName.Should().Be("GetUnicorn");
            result.StatusCode.Should().Be(201, "because a new inventory item was created");
        }
        public async Task <ActionResult <Unicorn> > CreateUnicorn(NewUploadedItem upload)
        {
            // Uncomment the code below for the AI Content Moderation extra credit lab

            /*
             * var rekognitionResponse = await this.rekognitionService.GetContentModerationLabels(upload.Image);
             * if (rekognitionResponse != null)
             * {
             *  return this.BadRequest(rekognitionResponse);
             * }
             */

            var createItemResponse = await this.unicornService.CreateItemAsync(upload);

            if (createItemResponse == null)
            {
                return(this.BadRequest());
            }

            return(this.CreatedAtAction("GetUnicorn", new { id = upload.Unicorn.unicorn_id }, upload.Unicorn));
        }