Beispiel #1
0
        public void ThenDBShouldContainUncompleteItemWithText(string itemText)
        {
            Assert.That(_db.Items.Any(e => e.Text == itemText && !e.Complete));

            // save item data to cleanup later...
            _item = _db.Items.First(e => e.Text == itemText);
        }
 public void Add(TodoItemData item)
 {
     using (TodoDbContext db = new TodoDbContext()) {
         db.Todo.Add(item);
         db.SaveChanges();
     }
 }
Beispiel #3
0
        public ApiSteps()
        {
            _db  = new TodoListDbClient();
            _api = new ApiClient(AutomationConfig.Instance.ApiHost);

            _item = null;
        }
        public void WhenTypedText(string text)
        {
            _app.HomePage.Form.Input
            .Click()
            .SendKeys(text);

            _item = new TodoItemData()
            {
                Text = text
            };                                    // save data for further use
        }
 public void CleanScenario()
 {
     if (_item != null)
     {
         var itemInfo = _app.TodoListApi.GetAll().FirstOrDefault(e => e.Text == _item.Text);
         if (itemInfo != null)
         {
             _app.TodoListApi.DeleteItem(itemInfo.Id);
             _item = null;
         }
     }
 }
        public void ThenItemShouldBeDeleted()
        {
            // wait untill element deleted on the backend
            //Helpers.Wait(
            //    () => !_app.TodoListApi.GetAll().Any(l => l.Text == _item.Text)
            //);

            // UI verification
            Assert.That(Helpers.Wait(() => !_app.HomePage.List.Items.Any(l => l.Exists && l.Text == _item.Text)));

            // set the _item to null to avoid removing nothing at the cleanup stage
            _item = null;
        }
        public bool AddNew(TodoItemData newItem)
        {
            string endpoint = "/api/todo";

            var body = JsonConvert.SerializeObject(newItem);

            var client  = new RestClient(_baseUrl);
            var request = new RestRequest(endpoint, Method.POST)
                          .AddJsonBody(body);

            IRestResponse response = client.Execute(request);

            return(response.StatusCode == HttpStatusCode.OK);
        }
        public void GivenThereIsAnUncompleteItemWithText(string itemText)
        {
            // add a complete item directly to DB
            _app.TodoListDb.Add(new TodoItemData()
            {
                Text = itemText, Complete = false
            });

            // verify it's not complete
            var item = _app.TodoListApi.GetAll().FirstOrDefault(e => e.Text == itemText);

            Assert.That(item, Is.Not.Null);
            Assert.That(!item.Complete);

            // save for further use
            _item = item;
        }
        // update
        public void Update(TodoItemData item)
        {
            var up_item = Items.FirstOrDefault(e => e.Id == item.Id);

            if (up_item == null)
            {
                return;
            }

            // update data in item
            up_item.Text     = item.Text;
            up_item.Complete = item.Complete;

            using (TodoDbContext db = new TodoDbContext()) {
                // update item in the list and save changes
                db.Todo.Update(up_item);
                db.SaveChanges();
            }
        }
        /// <summary>
        /// Creates a new todo item for the current user.
        /// </summary>
        public async Task <IHttpActionResult> Post(TodoItemCreate value)
        {
            if (value == null || string.IsNullOrWhiteSpace(value.Title))
            {
                return(BadRequest("Title is required"));
            }
            if (value == null || string.IsNullOrWhiteSpace(value.CategoryId))
            {
                return(BadRequest("CategoryId is required"));
            }

            // Create a new category via the Taxonomy Web API if requested.
            if (!string.IsNullOrWhiteSpace(value.NewCategoryName))
            {
                var client = await CategoryController.GetTaxonomyClient(this.User);

                var newCategory = new Category {
                    Name = value.NewCategoryName, IsPrivate = value.NewCategoryIsPrivate
                };
                var newCategoryRequest = new HttpRequestMessage(HttpMethod.Post, SiteConfiguration.TaxonomyWebApiRootUrl + "api/category");
                newCategoryRequest.Content = new JsonContent(newCategory);
                var newCategoryResponse = await client.SendAsync(newCategoryRequest);

                newCategoryResponse.EnsureSuccessStatusCode();
                var newCategoryResponseString = await newCategoryResponse.Content.ReadAsStringAsync();

                var category = JsonConvert.DeserializeObject <Category>(newCategoryResponseString);
                value.CategoryId = category.Id;
            }

            var userId = this.User.GetUniqueIdentifier();
            var data   = new TodoItemData(value.Title, value.CategoryId, userId);

            database.Add(data);
            return(Ok());
        }
Beispiel #11
0
        public void ThenDBShouldNotContainItemWithText(string itemText)
        {
            Assert.That(!_db.Items.Any(e => e.Text == itemText));

            _item = null; // nothing to cleanup, db is already in required state...
        }