示例#1
0
        public async Task WhenATodoIsSubmitted_ThenItCanBeFoundInDatabase()
        {
            var client     = new HttpClient();
            var createTodo = new CreateToDoDto
            {
                Name        = $"systemtest-{Guid.NewGuid()}",
                Description = "systemtest",
                DueAt       = DateTime.UtcNow.AddDays(1),
                Price       = 500,
                BillToEmail = "*****@*****.**"
            };
            var content = new StringContent(JsonConvert.SerializeObject(createTodo), Encoding.UTF8, "application/json");

            var response = await client.PostAsync("https://testingdemo-api-test.azurewebsites.net/todos", content);

            response.EnsureSuccessStatusCode();

            var todo = JsonConvert.DeserializeObject <ToDo>(await response.Content.ReadAsStringAsync());

            var comsosClient = new CosmosClient(
                TestContext.Parameters["CosmosDbEndpoint"],
                TestContext.Parameters["CosmosDbKey"]);

            var database  = comsosClient.GetDatabase(TestContext.Parameters["CosmosDbDatabaseName"]);
            var container = database.GetContainer(TestContext.Parameters["CosmosDbCollectionName"]);

            var actual = container
                         .GetItemLinqQueryable <ToDo>(true)
                         .Where(x => x.id == todo.id)
                         .ToArray()
                         .SingleOrDefault();

            Assert.IsNotNull(actual);
        }
示例#2
0
        public async Task <IActionResult> Create([FromBody] CreateToDoDto createToDoDto)
        {
            _logger.LogTrace("Adding todo");

            var todo = await _toDoService.CreateAsync(createToDoDto);

            return(Ok(todo));
        }
示例#3
0
        public async Task <IActionResult> Create([FromBody] CreateToDoDto ToDoDto)
        {
            var validationResult = _ToDoValidator.Validate(ToDoDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(BadRequestMessageHelper.BadRequestFormat(validationResult.Errors)));
            }

            var entity = _mapper.Map <CreateToDoDto, ToDoEntity>(ToDoDto);
            await _ToDoRepository.AddAsync(entity);

            return(Created($"{entity.Id}", null));
        }
示例#4
0
        public async Task <ToDo> CreateAsync(CreateToDoDto createToDoDto)
        {
            var todo = ToDo.Create(
                createToDoDto.Name,
                createToDoDto.Description,
                createToDoDto.Price,
                createToDoDto.DueAt,
                createToDoDto.BillToEmail);

            _logger.LogTrace("Created new todo with id {id}", todo.id);

            await _toDoRepository.AddAsync(todo);

            _logger.LogTrace("Stored new todo with id {id}", todo.id);

            return(todo);
        }