Ejemplo n.º 1
0
        public async Task PostItemAsync_InvalidValues()
        {
            var emptyNameItem = new Item {
                Name = "", PhoneNumber = "780-233-4555"
            };
            var itemRepo = new ItemRepo(null);

            var exception = await Record.ExceptionAsync(async() => await itemRepo.PostItemAsync(emptyNameItem));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);

            var emptyPhoneNumber = new Item {
                Name = "Jordan", PhoneNumber = ""
            };

            exception = await Record.ExceptionAsync(async() => await itemRepo.PostItemAsync(emptyPhoneNumber));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
        }
Ejemplo n.º 2
0
        public async Task PostItemAsync_InvalidPhoneNumber()
        {
            var invalidPhoneNumber = new Item {
                Name = "Jordan", PhoneNumber = "780-3-4555"
            };
            var itemRepo = new ItemRepo(null);

            var exception = await Record.ExceptionAsync(async() => await itemRepo.PostItemAsync(invalidPhoneNumber));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.Contains(invalidPhoneNumber.PhoneNumber, exception.Message);
        }
Ejemplo n.º 3
0
        public async Task PostItemAsync_Failure()
        {
            var item = new Item {
                Name = "Test", PhoneNumber = "780.246.8060"
            };
            var airTableClient = new Mock <AirTableClientProvider>("");

            airTableClient.Setup(a => a.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>())).ReturnsAsync(new HttpResponseMessage(HttpStatusCode.BadGateway));

            var itemRepo  = new ItemRepo(airTableClient.Object);
            var exception = await Record.ExceptionAsync(async() => await itemRepo.PostItemAsync(item));

            Assert.NotNull(exception);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] Item itemToPost)
        {
            try{
                await _itemRepo.PostItemAsync(itemToPost);

                return(Ok());
            }
            catch (ArgumentException ex) {
                return(BadRequest(ex));
            }
            catch (Exception ex) {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
Ejemplo n.º 5
0
        public async Task PostItemAsync_ValidateGenerated()
        {
            var item = new Item {
                Name = "Test", PhoneNumber = "780.246.8060"
            };
            HttpContent outputHttpContent = null;
            var         airTableClient    = new Mock <AirTableClientProvider>("");

            airTableClient.Setup(a => a.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>())).Callback <string, HttpContent>((uri, content) => outputHttpContent = content);

            var itemRepo = new ItemRepo(airTableClient.Object);
            await Record.ExceptionAsync(async() => await itemRepo.PostItemAsync(item));

            var outputStr = await outputHttpContent.ReadAsStringAsync();

            var output = JsonConvert.DeserializeObject <AirTablePostItem>(outputStr);

            Assert.NotNull(output);
            Assert.Equal("(780) 246-8060", output.Fields.PhoneNumber);
            Assert.Equal(10, output.Fields.Id.Length);
        }