Exemplo n.º 1
0
        public IHttpActionResult PutTodoEntry(int id, TodoEntry todoEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todoEntry.TodoEntryId)
            {
                return(BadRequest());
            }

            db.Entry(todoEntry).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoEntryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public async Task <TodoEntry> AddTodoAsync(TodoEntry todo)
        {
            _context.TodoEntries.Add(todo);
            await _context.SaveChangesAsync();

            return(todo);
        }
Exemplo n.º 3
0
        public void Update()
        {
            // Arrange
            var todo = new TodoEntry()
            {
                OwnerId = 23, IsCompleted = false, Description = "Make a nice cake.", LastUpdated = new DateTime(2012, 12, 12)
            };

            // Act
            Repository.SaveOrUpdate(todo);
            todo.OwnerId++;
            todo.IsCompleted = true;
            todo.Description = "Eat cake.";
            todo.LastUpdated = new DateTime(2010, 10, 10);
            Repository.SaveOrUpdate(todo);

            // Assert
            var list = Repository.Select <TodoEntry>();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(1, list[0].Id);
            Assert.AreEqual(24, ((TodoEntry)list[0]).OwnerId);
            Assert.AreEqual("Eat cake.", ((TodoEntry)list[0]).Description);
            Assert.AreEqual(true, ((TodoEntry)list[0]).IsCompleted);
            Assert.AreEqual(new DateTime(2010, 10, 10), ((TodoEntry)list[0]).LastUpdated);
        }
        public async Task <ActionResult <TodoEntry> > PostTodoEntry(TodoEntry todoEntry)
        {
            _context.TodoEntries.Add(todoEntry);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoEntry", new { id = todoEntry.id }, todoEntry));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <TodoEntryView> > CreateListEntry(
            [FromRoute] Guid id,
            [FromBody] ListEntryCreate entry)
        {
            var list = await db.Lists.FindAsync(id);

            if (list == null || list.Owner.Id != AuthorizedUser.Id)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(entry.Content))
            {
                return(BadRequest("content value can not be null or empty"));
            }

            var createdEntry = new TodoEntry()
            {
                Content     = entry.Content,
                Checked     = entry.Checked ?? false,
                ContainedIn = list,
            };

            db.Add(createdEntry);
            await db.SaveChangesAsync();

            return(Created(
                       $"/api/lists/{list.Id}/entries/{createdEntry.Id}",
                       new TodoEntryView(createdEntry)));
        }
Exemplo n.º 6
0
        public void TodoEntryStoresInputText()
        {
            const string cEntryText = "This is a log entry";

            TodoEntry entry = new TodoEntry(cEntryText);

            Assert.AreEqual(cEntryText, entry.Text);
        }
Exemplo n.º 7
0
 public TodoEntryView(
     TodoEntry entry,
     bool displayContainedList      = true,
     bool displayContainedListOwner = true) : base(entry)
 {
     ContainedIn = displayContainedList
         ? new TodoListView(entry.ContainedIn, displayContainedListOwner)
         : null;
     Content = entry.Content;
     Checked = entry.Checked;
 }
Exemplo n.º 8
0
        public ActionResult <TodoEntry> Post([FromBody] TodoEntry model)
        {
            var serviceResult = _todoEntryService.Create(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
Exemplo n.º 9
0
        public IHttpActionResult GetTodoEntry(int id)
        {
            TodoEntry todoEntry = db.TodoEntries.Find(id);

            if (todoEntry == null)
            {
                return(NotFound());
            }

            return(Ok(todoEntry));
        }
Exemplo n.º 10
0
        public IHttpActionResult PostTodoEntry(TodoEntry todoEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TodoEntries.Add(todoEntry);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = todoEntry.TodoEntryId }, todoEntry));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> CreateAsync([FromRoute] TodoEntry todo)
        {
            try
            {
                var addedTodo = await _service.AddTodoAsync(todo);

                return(Ok(addedTodo));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 12
0
        public IHttpActionResult DeleteTodoEntry(int id)
        {
            TodoEntry todoEntry = db.TodoEntries.Find(id);

            if (todoEntry == null)
            {
                return(NotFound());
            }

            db.TodoEntries.Remove(todoEntry);
            db.SaveChanges();

            return(Ok(todoEntry));
        }
Exemplo n.º 13
0
        public void InsertTodo(int Id, string Title, string Text, string LastModified, string Category)
        {
            var cat = db.Categories.Single(x => x.Name == Category);

            TodoEntry newTodo = new TodoEntry()
            {
                Title        = Title,
                Text         = Text,
                LastModified = DateTime.Now,
                Category     = cat
            };

            db.Todos.Add(newTodo);
            db.SaveChanges();
        }
Exemplo n.º 14
0
        public IEnumerable <TodoDetails> Create([FromBody] TodoItem item)
        {
            var user = CommonCode.GetCurrentUser(Request);

            if (user.IsAuthenticated && item != null)
            {
                var todoEntry = new TodoEntry()
                {
                    Description = HttpUtility.HtmlEncode(item.Description), IsCompleted = item.IsCompleted, LastUpdated = DateTime.Now, OwnerId = user.UserId
                };
                Repository.SaveOrUpdate(todoEntry);
            }

            return(All());
        }
        private List <TodoEntry> Grab_Entries()
        {
            List <TodoEntry> entries = new List <TodoEntry>();

            db.Open();
            SqliteCommand    selectCommand = new SqliteCommand("SELECT Title_Entry, Content_Entry, Ticks_Entry, Id, Done from TodoList;", db);
            SqliteDataReader query;

            try
            {
                query = selectCommand.ExecuteReader();
            }
            catch (SqliteException error)
            {
                System.Diagnostics.Debug.WriteLine(error);
                return(entries);
            }
            while (query.Read())
            {
                TodoEntry tmpEntry = new TodoEntry();
                tmpEntry.title   = query.GetString(0);
                tmpEntry.content = query.GetString(1);
                System.Diagnostics.Debug.WriteLine(query.GetInt64(2));
                tmpEntry.date = new DateTimeOffset(new DateTime(query.GetInt64(2)));
                tmpEntry.id   = query.GetInt16(3);
                if (query.GetInt16(4) == 0)
                {
                    tmpEntry.done = "";
                }
                else
                {
                    tmpEntry.done = "DONE";
                }
                entries.Add(tmpEntry);
                if (firstQuerry)
                {
                    onGoing.Add(tmpEntry.id, query.GetInt16(4));
                    count = tmpEntry.id;
                }
            }
            if (firstQuerry)
            {
                count++;
            }
            db.Dispose();
            firstQuerry = false;
            return(entries);
        }
Exemplo n.º 16
0
        public ActionResult <TodoEntry> Delete(int id)
        {
            var model = new TodoEntry()
            {
                TodoEntryId = id
            };

            var serviceResult = _todoEntryService.Delete(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
Exemplo n.º 17
0
        public ActionResult <TodoEntry> Put(int id, [FromBody] TodoEntry model)
        {
            model.TodoEntryId = id;

            var serviceResult = _todoEntryService.Update(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }
            if (serviceResult.Status == BrashActionStatus.NOT_FOUND)
            {
                return(NotFound(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
Exemplo n.º 18
0
        public ActionResult <TodoEntry> Get(int id)
        {
            var model = new TodoEntry()
            {
                TodoEntryId = id
            };

            var serviceResult = _todoEntryService.Fetch(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }
            if (serviceResult.Status == BrashActionStatus.NOT_FOUND)
            {
                return(NotFound(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
Exemplo n.º 19
0
        public void DisplayTodoHeaderStateOutputsAllTodoItems()
        {
            TodoEntry        todoEntry   = new TodoEntry("entry");
            List <TodoEntry> todoEntries = new List <TodoEntry>()
            {
                todoEntry
            };

            IConsole  mockConsole  = Substitute.For <IConsole>();
            ILog      mockLog      = Substitute.For <ILog>();
            ITodoList mockTodoList = Substitute.For <ITodoList>();

            mockTodoList.GetEntries().Returns(todoEntries);

            DisplayTodoListHeaderState state = new DisplayTodoListHeaderState(mockConsole, mockLog, mockTodoList);

            state.Execute();

            mockConsole.Received(1).Output("0> ");
            mockConsole.Received(1).OutputLine("entry");
        }
Exemplo n.º 20
0
        public async Task <IActionResult> PutTodoEntry(int id, TodoEntry todoEntry)
        {
            todoEntry.id = id;

            _context.Entry(todoEntry).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoEntryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 21
0
        public void CreateUpdateDeleteFetch()
        {
            // file system
            var path         = "/shop/randomsilo/modern-web/backends/TodoList";
            var project      = "TodoList";
            var outputPath   = $"{path}/{project}.Infrastructure.Test/TestOutput/";
            var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod());

            // logger
            ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log");

            // database setup

            // - context
            IDatabaseContext databaseContext = new DatabaseContext(
                $"Data Source={databaseFile}"
                , "TestDb"
                , "TestSchema"
                , $"{path}/sql/sqlite/ALL.sql"
                );

            Assert.NotNull(databaseContext);

            // - manager
            IManageDatabase databaseManager = new DatabaseManager(databaseContext);

            Assert.NotNull(databaseManager);

            // - create tables
            databaseManager.CreateDatabase();

            // - repository
            var todoEntryRepository = new TodoEntryRepository(databaseManager, new TodoEntryRepositorySql(), logger);

            Assert.NotNull(todoEntryRepository);

            // faker
            BrashActionResult <TodoEntry> result = null;
            var todoEntryFaker = new TodoEntryFaker(databaseManager, logger);

            Assert.NotNull(todoEntryFaker);

            // create
            var todoEntryCreateModel = todoEntryFaker.GetOne();

            result = todoEntryRepository.Create(todoEntryCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.TodoEntryId > 0);

            // use model with id
            todoEntryCreateModel = result.Model;

            // update
            var todoEntryUpdateModel = todoEntryFaker.GetOne();

            todoEntryUpdateModel.TodoEntryId = todoEntryCreateModel.TodoEntryId;
            result = todoEntryRepository.Update(todoEntryUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // delete
            result = todoEntryRepository.Delete(todoEntryCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // fetch

            // - make fakes
            var fakes = todoEntryFaker.GetMany(10);

            // - add fakes to database
            List <int?> ids = new List <int?>();

            foreach (var f in fakes)
            {
                result = todoEntryRepository.Create(f);

                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.TodoEntryId >= 0);
                ids.Add(result.Model.TodoEntryId);
            }

            // - get fakes from database
            foreach (var id in ids)
            {
                var model = new TodoEntry()
                {
                    TodoEntryId = id
                };

                result = todoEntryRepository.Fetch(model);
                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.TodoEntryId >= 0);
            }
        }
Exemplo n.º 22
0
 public BrashActionResult <TodoEntry> Fetch(TodoEntry model)
 {
     return(Repository.Fetch(model));
 }
Exemplo n.º 23
0
 public BrashActionResult <TodoEntry> Delete(TodoEntry model)
 {
     return(Repository.Delete(model));
 }
Exemplo n.º 24
0
 public void TodoEntryThrowsExceptionWhenGivenEmptyText()
 {
     TodoEntry entry = new TodoEntry("");
 }
Exemplo n.º 25
0
 public void TodoEntryThrowsExceptionWhenGivenNullText()
 {
     TodoEntry entry = new TodoEntry(null);
 }
Exemplo n.º 26
0
 public async Task <TodoEntry> AddTodoAsync(TodoEntry todo)
 {
     return(await _repository.AddTodoAsync(todo));
 }