예제 #1
0
        public async Task <IActionResult> Insert([FromBody] CollectionInsertModel collection)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (String.IsNullOrEmpty(userId))
            {
                return(NotFound());
            }

            var command = new InsertCollectionC(collection, userId);

            var actionResult = await _mediator.Send(command);

            if (actionResult.IsSucceed == true)
            {
                return(Ok());
            }

            return(BadRequest(actionResult.Message));
        }
예제 #2
0
        public async Task TestB_NameExists()
        {
            var mocker = new MockDataV2();

            mocker.Reset();

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjlhNGUxZDc5LWQ2NGUtNGVjNC04NWU1LTUzYmRlZjUwNDNmNCIsIm5iZiI6MTYxOTc2OTYzOCwiZXhwIjoxNjE5ODU2MDM4LCJpc3MiOiJhIn0.tohmUFgbnXqaMoehSX9i-p_F6vpdoziu9Jz5XgM1N1k");

            var inputDTO = new CollectionInsertModel()
            {
                Name = "User 1 Name 1"
            };

            var response = await _client.PostAsync("api/collection/insert", new StringContent(JsonConvert.SerializeObject(inputDTO), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            using (var db = MockDatabaseFactory.Build())
            {
                Assert.Equal(6, await db.Collections.CountAsync());
            }
        }