public async Task <IHttpActionResult> Delete(int id)
        {
            var result = await _service.DeleteAsync(id);

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

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task DeleteAsync_RemovesEntity()
        {
            //Assert

            //Act
            await testedService.DeleteAsync(singleEntity.Id);

            //Assert
            Mock.Verify(c => c.Remove(anyEntity), Times.Once());
            Mock.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Esempio n. 3
0
        public async Task ShouldDeleteEmployee()
        {
            var employeeId = Guid.NewGuid();

            var employee = new Employee
            {
                Id           = employeeId,
                SecurityUser = new SecurityUser
                {
                    User = new User()
                }
            };

            _mock.Mock <IEmployeeProvider>()
            .Setup(provider => provider.GetByIdAsync(employeeId))
            .ReturnsAsync(employee);

            await _service.DeleteAsync(employeeId);

            _mock.Mock <IUserManager>()
            .Verify(manager => manager.DeleteAsync(employee.SecurityUser.User));
        }
        public async Task DeleteAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var userRepo = new EfDeletableEntityRepository <ApplicationUser>(dbContext);

            var service = new EmployeesService(userRepo);

            await userRepo.AddAsync(new ApplicationUser
            {
                FirstName  = "ivan",
                LastName   = "ivanov",
                MiddleName = "ivanov",
                EGN        = "1234567890",
            });

            await userRepo.AddAsync(new ApplicationUser
            {
                FirstName  = "ivan2",
                LastName   = "ivanov2",
                MiddleName = "ivanov2",
                EGN        = "1234567892",
            });

            await userRepo.SaveChangesAsync();

            var customerId = (await userRepo.AllAsNoTracking()
                              .FirstOrDefaultAsync()).Id;

            await service.DeleteAsync(customerId);

            var customers = await userRepo.All().ToListAsync();

            Assert.Single(customers);
            Assert.DoesNotContain(customers, x => x.Id == customerId);
        }
        public async Task DeleteAsyncWithValidId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            var service = new EmployeesService(new EfDeletableEntityRepository <Employee>(dbContext));
            var date    = DateTime.UtcNow;
            await service.AddAsync(
                "Ivan Ivanov",
                "*****@*****.**",
                "08888888888",
                date,
                "1");

            var employee = await dbContext.Employees.FirstOrDefaultAsync();

            await service.DeleteAsync(employee.Id);

            var result = await dbContext.GamingHalls.Where(x => x.Id == employee.Id).FirstOrDefaultAsync();

            Assert.True(result == null);
            dbContext.Database.EnsureDeleted();
            dbContext.Dispose();
        }