コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            var    userName = GetUserName();
            Client client   = _repository.GetClientById(id);

            if (client.ClientOwner.Equals(userName))
            {
                _repository.DeleteClient(client);
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <ActionResult> DeleteClient(Guid clientId)
        {
            var clientFromRepo = await _clientsRepo.GetClientById(clientId);

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

            await _clientsRepo.DeleteClient(clientId);

            return(NoContent());
        }
コード例 #3
0
        public async Task ShouldNotToDeleteClientAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _clientService            = new BankApplication.Service.Service.ClientService(dbContext, _mapper);
            int clientId = 6;

            //Act
            var response = _clientService.DeleteClient(clientId);

            // Assert
            Assert.IsFalse(response);
            Assert.AreEqual(5, dbContext.Clients.Count());
            Assert.IsNull(dbContext.Clients.Find(clientId));
        }
コード例 #4
0
        public async Task ShouldBeAbleToDeleteClientAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            int clientId = 1;

            //Act
            var response = _service.DeleteClient(clientId);

            // Assert
            Assert.IsTrue(response);
            Assert.AreEqual(3, dbContext.Clients.Count());
            Assert.IsNull(dbContext.Clients.Find(clientId));
        }
コード例 #5
0
        public async Task DeleteClient_ShouldNotWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var clientId      = 24;
            var expectedCount = await dbContext.Clients.CountAsync();

            //Actual
            var actual      = clientsRepository.DeleteClient(clientId);
            var actualCount = await dbContext.Clients.CountAsync();

            //Assert
            Assert.False(actual);
            Assert.Equal(expectedCount, actualCount);
        }
コード例 #6
0
 public void DeleteClient(int id)
 {
     _clientsRepository.DeleteClient(id);
 }
コード例 #7
0
 public IActionResult RemoveClient([FromRoute] int id)
 {
     return(Ok(_service.DeleteClient(id)));
 }