コード例 #1
0
ファイル: CreateAttachment.cs プロジェクト: dukeofharen/wolk
        public async Task CreateAttachment_ValidationError_ShouldReturn400()
        {
            // Arrange
            var note = await WolkDbContext.CreateAndSaveNote();

            var contents = new byte[] { 1, 2, 3, 4 };
            var model    = new MutateAttachmentModel
            {
                Filename = new string('a', 301), Base64Contents = Convert.ToBase64String(contents)
            };

            var url = $"/api/note/{note.Id}/attachments";

            var request = new HttpRequestMessage(HttpMethod.Post, url)
            {
                Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, MimeTypes.Json)
            };
            var token = await GetJwt();

            request.AddJwtBearer(token);

            // Act
            using var response = await HttpClient.SendAsync(request);

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
コード例 #2
0
        public async Task <ActionResult <AttachmentDto> > CreateAttachment(
            [FromRoute] long noteId,
            [FromBody] MutateAttachmentModel model)
        {
            var command = Mapper.Map <CreateAttachmentCommand>(model);

            command.NoteId = noteId;
            var result = await Mediator.Send(command);

            return(CreatedAtAction(
                       nameof(GetAttachment),
                       new { noteId, attachmentId = result.Id },
                       result));
        }
コード例 #3
0
ファイル: CreateAttachment.cs プロジェクト: dukeofharen/wolk
        public async Task CreateAttachment_HappyFlow()
        {
            // Arrange
            var note = await WolkDbContext.CreateAndSaveNote();

            var contents = new byte[] { 1, 2, 3, 4 };
            var model    = new MutateAttachmentModel
            {
                Filename = "file.txt", Base64Contents = Convert.ToBase64String(contents)
            };

            var url = $"/api/note/{note.Id}/attachments";

            var request = new HttpRequestMessage(HttpMethod.Post, url)
            {
                Content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, MimeTypes.Json)
            };
            var token = await GetJwt();

            request.AddJwtBearer(token);

            // Act
            using var response = await HttpClient.SendAsync(request);

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            var content = await response.Content.ReadAsStringAsync();

            var returnedAttachment = JsonConvert.DeserializeObject <AttachmentDto>(content);

            var attachment = await WolkDbContext.Attachments.SingleAsync();

            ShouldBeEqual(attachment, returnedAttachment);

            Assert.AreEqual(1, MockFileService.Files.Count);
        }