public void Delete_OneItem_SetEntityStateToModified()
        {
            var deletedEpisode = episodesSeriesOne[1];

            episodeRepositorySUT.Delete(deletedEpisode);


            Assert.DoesNotContain(deletedEpisode, episodesDbSetMock.Object.Local);
        }
        public void DeleteShouldRemoveEntity()
        {
            // Arrange
            var  context = new Mock <DbContext>();
            User user    = new User
            {
                UserName = "******"
            };
            var users = new List <User>
            {
                new User
                {
                    UserName = "******"
                },
                user,
                new User
                {
                    UserName = "******"
                }
            };

            context.Setup(m => m.Set <User>()).Returns(new FakeSet <User>(users));
            var entityFrameworkRepository = new EntityFrameworkRepository <User, int>(context.Object);

            // Act
            entityFrameworkRepository.Delete(user);

            // Assert
            Assert.AreEqual(2, users.Count);
            Assert.IsFalse(users.Contains(user));
        }
        public void SoftDelete_OneItem_SetDeletedDate()
        {
            var deletedQuote = quotes[0];

            quoteRepositorySUT.Delete(deletedQuote);
            var quoteById = quoteRepositorySUT.GetById(deletedQuote.Id);


            Assert.NotNull(quoteById.DeletedDate);
        }
        public void DeleteWithNullShouldThrowArgumentNull()
        {
            // Arrange
            var context = new Mock <DbContext>();
            var users   = new List <User>();

            context.Setup(m => m.Set <User>()).Returns(new FakeSet <User>(users));
            var entityFrameworkRepository = new EntityFrameworkRepository <User, int>(context.Object);

            // Act
            entityFrameworkRepository.Delete(null);
        }
        public void Delete_CanMarkEntityForDeletion_WhenEntityExists()
        {
            using (var context = new FakeDbContext())
            {
                var repository = new EntityFrameworkRepository<FakeCustomer>(() => context);
                var customer = repository.Get(1);
                Assert.NotNull(customer);

                repository.Delete(customer);

                Assert.Equal(EntityState.Deleted, context.Entry(customer).State);
            }
        }
Пример #6
0
        public void Delete_CanMarkEntityForDeletion_WhenEntityExists()
        {
            using (var context = new FakeDbContext())
            {
                var repository = new EntityFrameworkRepository <FakeCustomer>(() => context);
                var customer   = repository.Get(1);
                Assert.NotNull(customer);

                repository.Delete(customer);

                Assert.Equal(EntityState.Deleted, context.Entry(customer).State);
            }
        }
Пример #7
0
        public void TestDelete_ShouldCallDbContextSetDeleted()
        {
            // Arrange
            var mockedDbContext = new Mock <ILogsDbContext>();

            var repository = new EntityFrameworkRepository <FakeGenericRepositoryType>(mockedDbContext.Object);

            var entity = new Mock <FakeGenericRepositoryType>();

            // Act
            repository.Delete(entity.Object);

            // Assert
            mockedDbContext.Verify(c => c.SetDeleted(entity.Object), Times.Once);
        }
        public IHttpActionResult DeleteOrder([FromUri] Guid OrderID)
        {
            var countBefore = _efr.CountAll();

            _efr.Delete(OrderID);
            var countAfter = _efr.CountAll();

            if (countBefore - 1 == countAfter)
            {
                return(Ok("Order Deleted"));
            }
            else
            {
                return(Ok("Order not Found!!"));
            }
        }
        public IHttpActionResult DeleteUser([FromUri] Guid UserId)
        {
            var countBefore = _efr.CountAll();

            _efr.Delete(UserId);
            var countAfter = _efr.CountAll();

            if (countBefore == countAfter - 1)
            {
                return(Ok("User Deleted"));
            }
            else
            {
                return(Ok("User not Found!!"));
            }
        }
Пример #10
0
        public IHttpActionResult DeleteLineItem([FromUri] Guid WishListID)
        {
            var countBefore = _efr.CountAll();

            _efr.Delete(WishListID);
            var countAfter = _efr.CountAll();

            if (countBefore - 1 == countAfter)
            {
                return(Ok("WishList Deleted"));
            }
            else
            {
                return(Ok("WishList not Found!!"));
            }
        }
        public void ShouldKnowHowToDeleteAModelByItsIdWhenItExists()
        {
            var book = new Book {Id = 1, Title = "The Book"};
            var dbContext = new Mock<PukuDbContext>();
            var dbSet = new Mock<IDbSet<Book>>();
            dbSet.Setup(set => set.Find(book.Id)).Returns(book);
            dbSet.Setup(set => set.Remove(book));
            dbContext.Setup(context => context.GetDbSet<Book>()).Returns(dbSet.Object);
            var efRepo = new EntityFrameworkRepository(dbContext.Object);

            efRepo.Delete<Book>(book.Id);

            dbContext.Verify(context => context.GetDbSet<Book>(), Times.Once());
            dbSet.Verify(set => set.Find(book.Id), Times.Once());
            dbSet.Verify(set => set.Remove(book), Times.Once());
        }
Пример #12
0
        public IHttpActionResult DeleteProductCategory([FromUri] Guid ProductCategoryID)
        {
            var countBefore = _efr.CountAll();

            _efr.Delete(ProductCategoryID);
            var countAfter = _efr.CountAll();

            if (countBefore - 1 == countAfter)
            {
                return(Ok("ProductCategory Deleted"));
            }
            else
            {
                return(Ok("ProductCategory not Found!!"));
            }
        }
        public void Delete_Should_Work_As_Expected()
        {
            //Arrange
            TestEntity entity = new TestEntity {
                Id = 1, Value = "Hello World"
            };

            _repository.Add(entity);
            _testDbContext.SaveChanges();

            //Act
            _repository.Delete(entity);
            _testDbContext.SaveChanges();

            //Assert
            Assert.Null(_testDbContext.TestEntities.FirstOrDefault(q => q.Id == entity.Id));
        }
Пример #14
0
        public IHttpActionResult DeleteLineItemID([FromUri] Guid AddressID)
        {
            var countBefore = _efr.CountAll();

            if (countBefore > 0)
            {
                _efr.Delete(AddressID);
            }

            var countAfter = _efr.CountAll();

            if (countBefore - 1 == countAfter)
            {
                return(Ok("Address  Deleted"));
            }
            else
            {
                return(Ok("Address not Found!!"));
            }
        }
Пример #15
0
        // Delete Personal Details
        public static async Task <bool> DeletePersonalDetails(Guid Id)
        {
            try
            {
                Errors.Clear();
                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        var entity = await db.PersonalDetails.FindAsync(Id);

                        repo.Delete <PersonalDetail>(entity);
                        return(await db.SaveChangesAsync() == 0 ? false : true);
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                return(false);
            }
        }
Пример #16
0
        public async Task Delete(T entity)
        {
            try
            {
                _errors.Clear();
                _errorDetail.Clear();

                using (var db = new WebApiProjectDbContext())
                    using (var repo = new EntityFrameworkRepository <WebApiProjectDbContext>(db))
                    {
                        repo.Delete <T>(entity);
                        await db.SaveChangesAsync();
                    }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);

                //Add Error message
                _errors.Add("There was an error trying to send the information to the database ");
                _errorDetail.Add(e.Message);
                _errorDetail.Add(e.InnerException.Message);
            }
        }
Пример #17
0
 public IHttpActionResult DeleteItem(Guid itemId)
 {
     erf.Delete(itemId);
     return(Ok("Item Deleted"));
 }
Пример #18
0
 public IHttpActionResult DeleteOrder(Guid orderId)
 {
     erf.Delete(orderId);
     return(Ok("Order Deleted"));
 }
Пример #19
0
 public IHttpActionResult DeleteWishlist(Guid wishlistId)
 {
     erf.Delete(wishlistId);
     return(Ok("Wishlist Deleted"));
 }
Пример #20
0
 public IHttpActionResult DeleteAddress(Guid addressId)
 {
     erf.Delete(addressId);
     return(Ok("Address Deleted"));
 }
Пример #21
0
 public IHttpActionResult DeleteUser(Guid userId)
 {
     erf.Delete(userId);
     return(Ok("Data Deleted"));
 }
Пример #22
0
 public IHttpActionResult DeleteUser(Guid productId)
 {
     erf.Delete(productId);
     return(Ok("Product Deleted"));
 }