예제 #1
0
        public async Task <IActionResult> AddNewWord([FromBody] AddWordRequest request)
        {
            if (string.IsNullOrEmpty(request?.Word))
            {
                return(BadRequest("No word"));
            }
            using (var con = _sqlConnectionFactory.GetConnection())
            {
                var selectQ = "SELECT id from words where word=@word";
                var exist   = await con.QueryFirstOrDefaultAsync <int?>(selectQ, new
                {
                    word = request.Word
                });

                if (exist.HasValue)
                {
                    return(BadRequest("already exist"));
                }
                var insertQ = "INSERT INTO public.words(word) VALUES (@word);";
                await con.ExecuteAsync(insertQ, new
                {
                    word = request.Word
                });
            }

            return(Ok());
        }
예제 #2
0
        public static void AddOneWordTest(string token)
        {
            // arrange
            using var clientFabric = new GetClient <DictionaryProviderClient>(d => new DictionaryProviderClient(d));
            DictionaryProviderClient client          = clientFabric.Client;
            AddWordsRequest          addwordsRequest = new AddWordsRequest();
            AddWordRequest           addWordRequest  = new AddWordRequest()
            {
                LocalId     = 1,
                WordForeign = "cat",
                WordNative  = "кот"
            };

            addwordsRequest.Words.Add(addWordRequest);
            // act
            var headers = new Metadata
            {
                { "Authorization", $"Bearer {token}" }
            };
            var empty = client.AddWords(addwordsRequest, headers);

            // assert
            Assert.Single(empty.WordIds);
            Assert.Equal(1, empty.WordIds[0].LocalId);
        }
예제 #3
0
        public AddWordsRequest GetExamples()
        {
            AddWordsRequest addWordRequest = new AddWordsRequest();
            AddWordRequest  word1          = new AddWordRequest()
            {
                LocalId     = 10,
                WordForeign = "Test",
                WordNative  = "Тест"
            };
            AddWordRequest word2 = new AddWordRequest()
            {
                LocalId     = 24,
                WordForeign = "Test 2",
                WordNative  = "Тест 2"
            };

            addWordRequest.Words.Add(word1);
            addWordRequest.Words.Add(word2);
            return(addWordRequest);
        }