Esempio n. 1
0
        public void Add_WithValidData_ReturnsCreatedItem()
        {
            //Arrange
            var sut   = CreateSUT();
            var model = new TodoDetailModel
            {
                IsDone         = true,
                Task           = "Take out trash",
                AssignedPerson = new PersonModel
                {
                    FirstName = "Karel",
                    LastName  = "Omáčka"
                }
            };

            TodoDetailModel createdModel = null;

            try
            {
                //Act
                createdModel = sut.Add(model);

                //Assert
                Assert.NotNull(createdModel);
            }
            finally
            {
                //Teardown
                if (createdModel != null)
                {
                    sut.Remove(createdModel.Id);
                }
            }
        }
Esempio n. 2
0
        public void FindById_ExistingItem_ReturnsIt()
        {
            //Arrange
            var sut   = CreateSUT();
            var model = new TodoDetailModel
            {
                IsDone         = true,
                Task           = "Take out trash",
                AssignedPerson = new PersonModel
                {
                    FirstName = "Karel",
                    LastName  = "Omáčka"
                }
            };
            var createdModel = sut.Add(model);

            try
            {
                //Act
                var foundModel = sut.GetById(createdModel.Id);

                //Assert
                Assert.NotNull(foundModel);
            }
            finally
            {
                //Teardown
                sut.Remove(createdModel.Id);
            }
        }
Esempio n. 3
0
 public void Update(TodoDetailModel todo)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = mapper.MapTodoDetailToEntity(todo);
         dbContext.Todos.Update(entity);
         dbContext.SaveChanges();
     }
 }
Esempio n. 4
0
 public TodoDetailModel Add(TodoDetailModel todo)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = mapper.MapTodoDetailToEntity(todo);
         dbContext.Todos.Add(entity);
         dbContext.SaveChanges();
         return(mapper.MapTodoDetailModelFromEntity(entity));
     }
 }
Esempio n. 5
0
 public Todo MapTodoDetailToEntity(TodoDetailModel todo)
 {
     return(new Todo
     {
         Id = todo.Id,
         IsDone = todo.IsDone,
         Task = todo.Task,
         AssignedPerson = MapPersonToEntity(todo.AssignedPerson)
     });
 }
Esempio n. 6
0
        public void Remove_ExistingItem_RemovesIt()
        {
            //Arrange
            var sut   = CreateSUT();
            var model = new TodoDetailModel
            {
                IsDone         = true,
                Task           = "Take out trash",
                AssignedPerson = new PersonModel
                {
                    FirstName = "Karel",
                    LastName  = "Omáčka"
                }
            };
            var createdModel = sut.Add(model);

            //Act
            sut.Remove(createdModel.Id);

            //Assert
            Assert.Null(sut.GetById(createdModel.Id));
        }