public async Task ShouldGetModelForValidInformation()
        {
            var rnd         = new Random();
            var randomBytes = new byte[10];

            rnd.NextBytes(randomBytes);
            var createContentFile = new CreateContentFileCommand
            {
                TenantId  = _tenantId,
                CreatedBy = _adminUserId,
                CreateContentFileModels = new List <CreateContentFileCommandModel>
                {
                    new CreateContentFileCommandModel
                    {
                        Data        = randomBytes,
                        Name        = "contentFile1",
                        ContentType = "image/jpeg"
                    }
                }
            };

            var contentFileModel = await _createContentFileCommandHandler.Handle(createContentFile, CancellationToken.None);

            Assert.Null(contentFileModel.Errors);
        }
        public async Task CanCreateContentFileAsync()
        {
            var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var createContentFileCommand = new CreateContentFileCommand
            {
                CreateContentFileModels = new List <CreateContentFileCommandModel>
                {
                    new CreateContentFileCommandModel
                    {
                        Name        = "contentFile1",
                        ContentType = "contentFile1",
                        Data        = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                    }
                }
            };

            var serializedContentFileCommand = JsonConvert.SerializeObject(createContentFileCommand);

            // The endpoint or route of the controller action.
            var httpResponse = await authorizedClient.PostAsync(requestUri : "/ContentFile",
                                                                content : new StringContent(content: serializedContentFileCommand,
                                                                                            encoding: Encoding.UTF8,
                                                                                            mediaType: StringConstants.ApplicationJson));

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <ResponseModel <CreateContentFileModel> > > Post([FromBody] CreateContentFileCommand command)
        {
            try
            {
                var userId   = Claims[ClaimTypes.Sid].ToInt();
                var tenantId = Guid.Parse(Claims[ClaimTypes.UserData]);

                command.CreatedBy = userId;
                command.TenantId  = tenantId;

                var createContentFileModel = await Mediator.Send(command);

                return(Created($"api/traineeUser", createContentFileModel));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <CreateContentFileModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }