Exemplo n.º 1
0
        public async Task PutClient_ShouldWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var clientDto = new ClientDTO
            {
                Id          = 1,
                Name        = "Updated Client",
                PhoneNumber = "999-929-391",
                Type        = ClientType.Business,
                Mail        = "*****@*****.**",
                AddressId   = 2
            };

            //Actual
            var actual = clientsRepository.PutClient(clientDto.Id, clientDto);

            //Assert
            Assert.Equal(clientDto.Name, actual.Name);
            Assert.Equal(clientDto.PhoneNumber, actual.PhoneNumber);
            Assert.Equal(clientDto.Type, actual.Type);
            Assert.Equal(clientDto.Mail, actual.Mail);
            Assert.Equal(clientDto.AddressId, actual.AddressId);
        }
Exemplo n.º 2
0
        public async Task PutClient_ShouldNotWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var clientDto = new ClientDTO
            {
                Id          = 19,
                Name        = "Updated Client",
                PhoneNumber = "999-929-391",
                Type        = ClientType.Business,
                Mail        = "*****@*****.**",
                AddressId   = 2
            };

            //Actual

            //Assert
            var exception = Assert.Throws <Exception>
                                (() => clientsRepository.PutClient(clientDto.Id, clientDto));

            Assert.Equal("Client not found", exception.Message);
        }
        public async Task ShouldBeAbleToUpdateAccountAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            Account accountEntity = new Account()
            {
                Name     = "Client",
                Balance  = 2,
                IsActive = true,
                Type     = AccountType.CreditCard,
                ClientId = 1,
            };

            dbContext.Accounts.Add(accountEntity);
            dbContext.SaveChanges();

            AccountDTO accountDto = new AccountDTO()
            {
                Name     = "Client",
                Balance  = 2,
                IsActive = true,
                Type     = AccountType.CreditCard,
                ClientId = 1,
            };

            //Act
            var response = _service.PutAccount(accountEntity.Id, accountDto);

            // Assert
            Assert.AreEqual(accountDto.Name, response.Name);
        }
        public async Task ShouldBeAbleToAddClientAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _clientService            = new BankApplication.Service.Service.ClientService(dbContext, _mapper);
            ClientDTO client = new ClientDTO()
            {
                Name        = "Client",
                PhoneNumber = "073666777",
                Mail        = "*****@*****.**",
                Type        = ClientType.Business,
                AddressId   = 4
            };

            //Act
            var response = _clientService.SaveClient(client);
            var item     = dbContext.Clients.Find(response.Id);

            // Assert
            Assert.AreEqual(item.Name, response.Name);
            Assert.AreEqual(item.PhoneNumber, response.PhoneNumber);
            Assert.AreEqual(item.Email, response.Mail);
            Assert.AreEqual(item.Type, response.Type);
            Assert.AreEqual(item.AddressId, response.AddressId);
        }
Exemplo n.º 5
0
        public async Task ShouldBeAbleToUpdateStudentAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            Client clientEntity = new Client()
            {
                Name        = "Client",
                PhoneNumber = "Test",
                Email       = "*****@*****.**",
                Type        = ClientType.Business,
                AddressId   = 1,
            };

            dbContext.Clients.Add(clientEntity);
            dbContext.SaveChanges();

            ClientDTO clientDto = new ClientDTO()
            {
                Name        = "Client",
                PhoneNumber = "Test",
                Mail        = "*****@*****.**",
                // Type = ClientType
                AddressId = 1,
            };

            //Act
            var response = _service.PutClient(clientEntity.Id, clientDto);

            // Assert
            Assert.AreEqual(clientDto.Name, response.Name);
            Assert.AreEqual(clientDto.Mail, response.Mail);
        }
Exemplo n.º 6
0
        public async Task ShouldBeAbleToAddClientAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            ClientDTO client = new ClientDTO()
            {
                Name        = "Client",
                PhoneNumber = "543890530",
                Mail        = "*****@*****.**",
                // Type =
                AddressId = 1
            };

            //Act
            var response = _service.SaveClient(client);
            var item     = dbContext.Clients.Find(response.Id);

            // Assert
            Assert.AreEqual(item.Name, response.Name);
            Assert.AreEqual(item.PhoneNumber, response.PhoneNumber);
            //  Assert.AreEqual(item.Mail, response.Mail);
            //  Assert.AreEqual(item.Type, response.Type);
            Assert.AreEqual(item.AddressId, response.AddressId);
        }
Exemplo n.º 7
0
        public async Task ShouldBeAbleToAddAccountAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            AccountDTO account = new AccountDTO()
            {
                Name = "blhs",
                // Balance = 1,5 ,
                // Type = ,
                IsActive = true,
                ClientId = 1
            };

            //Act
            var response = _service.SaveAccount(account);
            var item     = dbContext.Accounts.Find(response.Id);

            // Assert
            Assert.AreEqual(item.Name, response.Name);
            Assert.AreEqual(item.Balance, response.Balance);
            Assert.AreEqual(item.Type, response.Type);
            Assert.AreEqual(item.IsActive, response.IsActive);
            Assert.AreEqual(item.ClientId, response.ClientId);
        }
Exemplo n.º 8
0
        public async Task PutAccount_ShouldWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var accountDto = new AccountDTO
            {
                Id       = 1,
                Name     = "Updated Account",
                Type     = AccountType.CreditCard,
                Balance  = 529m,
                IsActive = true,
                ClientId = 2
            };

            //Actual
            var actual = accountsRepository.PutAccount(accountDto.Id, accountDto);

            //Assert
            Assert.Equal(accountDto.Name, actual.Name);
            Assert.Equal(accountDto.Type, actual.Type);
            Assert.Equal(accountDto.Balance, actual.Balance);
            Assert.Equal(accountDto.IsActive, actual.IsActive);
            Assert.Equal(accountDto.ClientId, actual.ClientId);
        }
            public async Task ShouldBeAbleToAddAccountAsync()
            {
                // Arrange
                using var factory         = new SQLiteDbContextFactory();
                await using var dbContext = factory.CreateContext();
                _accountService           = new BankApplication.Service.Service.AccountsService(dbContext, _mapper);
                AccountDTO account = new AccountDTO()
                {
                    Name     = "Account",
                    Balance  = 000,
                    Type     = AccountType.SavingsAccount,
                    IsActive = false,
                    ClientId = 4
                };

                //Act
                var response = _accountService.SaveAccount(account);
                var item     = dbContext.Accounts.Find(response.Id);

                // Assert
                Assert.AreEqual(item.Name, response.Name);
                Assert.AreEqual(item.Balance, response.Balance);
                Assert.AreEqual(item.Type, response.Type);
                Assert.AreEqual(item.IsActive, response.IsActive);
                Assert.AreEqual(item.ClientId, response.ClientId);
            }
Exemplo n.º 10
0
        public async Task SaveClient_ShouldWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var expectedCount = await dbContext.Clients.CountAsync() + 1;

            var clientDto = new ClientDTO
            {
                Name        = "New Client",
                PhoneNumber = "111-111-111",
                Type        = ClientType.Residential,
                Mail        = "*****@*****.**",
                AddressId   = 1
            };

            //Actual
            var actual      = clientsRepository.SaveClient(clientDto);
            var actualCount = await dbContext.Clients.CountAsync();

            //Assert
            Assert.NotNull(actual);
            Assert.Equal(expectedCount, actualCount);
            Assert.Equal(clientDto.Name, actual.Name);
            Assert.Equal(clientDto.PhoneNumber, actual.PhoneNumber);
            Assert.Equal(clientDto.Type, actual.Type);
            Assert.Equal(clientDto.Mail, actual.Mail);
            Assert.Equal(clientDto.AddressId, actual.AddressId);
        }
Exemplo n.º 11
0
        public async Task SaveAccount_ShouldWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var expectedCount = await dbContext.Accounts.CountAsync() + 1;

            var accountDto = new AccountDTO
            {
                Name     = "New Account",
                Type     = AccountType.SavingsAccount,
                Balance  = 924m,
                IsActive = true,
                ClientId = 1
            };

            //Actual
            var actual      = accountsRepository.SaveAccount(accountDto);
            var actualCount = await dbContext.Accounts.CountAsync();

            //Assert
            Assert.NotNull(actual);
            Assert.Equal(expectedCount, actualCount);
            Assert.Equal(accountDto.Name, actual.Name);
            Assert.Equal(accountDto.Type, actual.Type);
            Assert.Equal(accountDto.Balance, actual.Balance);
            Assert.Equal(accountDto.IsActive, actual.IsActive);
            Assert.Equal(accountDto.ClientId, actual.ClientId);
        }
Exemplo n.º 12
0
        public async Task PutAccount_ShouldNotWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var accountDto = new AccountDTO
            {
                Id       = 62,
                Name     = "Updated Account",
                Type     = AccountType.CreditCard,
                Balance  = 529m,
                IsActive = true,
                ClientId = 2
            };

            //Actual

            //Assert
            var exception = Assert.Throws <Exception>
                                (() => accountsRepository.PutAccount(accountDto.Id, accountDto));

            Assert.Equal("Account not found", exception.Message);
        }
Exemplo n.º 13
0
        public async Task GetById_Should_Return_Null_Account()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            var accountsId = 9;

            // Act
            var actual = await _service.GetAccount(accountsId);

            // Assert
            Assert.IsNull(actual);
        }
            public async Task GetById_Should_Return_Correct_Account()
            {
                // Arrange
                using var factory         = new SQLiteDbContextFactory();
                await using var dbContext = factory.CreateContext();
                _accountService           = new BankApplication.Service.Service.AccountsService(dbContext, _mapper);
                var accountId = 1;

                // Act
                var actual = await _accountService.GetAccount(accountId);

                // Assert
                Assert.AreEqual(accountId, actual.Id);
            }
        public async Task GetClients_Should_Return_Correct_Count()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _clientService            = new BankApplication.Service.Service.ClientService(dbContext, _mapper);
            const int clientCount = 4;

            // Act
            var actual = _clientService.GetClients();

            // Assert
            Assert.AreEqual(clientCount, actual.Count());
        }
        public async Task GetById_Should_Return_Null_Client()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _clientService            = new BankApplication.Service.Service.ClientService(dbContext, _mapper);
            var clientId = 6;

            // Act
            var actual = await _clientService.GetClient(clientId);

            // Assert
            Assert.IsNull(actual);
        }
Exemplo n.º 17
0
        public async Task GetAccounts_Should_Return_Correct_Count()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            const int accountsCount = 8;

            // Act
            var actual = _service.GetAccounts();

            // Assert
            Assert.AreEqual(accountsCount, actual.Count());
        }
Exemplo n.º 18
0
        public async Task GetById_Should_Return_Correct_Client()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            var clientId = 1;

            // Act
            var actual = await _service.GetClient(clientId);

            // Assert
            Assert.AreEqual(clientId, actual.Id);
        }
Exemplo n.º 19
0
        public async Task GetClient_ShouldReturnCorrectClient()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var clientId = 1;

            //Actual
            var actual = await clientsRepository.GetClient(clientId);

            //Assert
            Assert.Equal(clientId, actual.Id);
        }
Exemplo n.º 20
0
        public async Task GetAccount_ShouldReturnNull()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var accountId = 85;

            //Actual
            var actual = await accountsRepository.GetAccount(accountId);

            //Assert
            Assert.Null(actual);
        }
            public async Task ShouldBeAbleToDeleteAccountAsync()
            {
                // Arrange
                using var factory         = new SQLiteDbContextFactory();
                await using var dbContext = factory.CreateContext();
                _accountService           = new BankApplication.Service.Service.AccountsService(dbContext, _mapper);
                int accountId = 1;

                //Act
                var response = _accountService.DeleteAccount(accountId);

                // Assert
                Assert.IsTrue(response);
                Assert.AreEqual(4, dbContext.Accounts.Count());
                Assert.IsNull(dbContext.Accounts.Find(accountId));
            }
Exemplo n.º 22
0
        public async Task ShouldNotToDeleteAccountAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            int accountId = 9;

            //Act
            var response = _service.DeleteAccount(accountId);

            // Assert
            Assert.IsFalse(response);
            Assert.AreEqual(8, dbContext.Accounts.Count());
            Assert.IsNull(dbContext.Accounts.Find(accountId));
        }
Exemplo n.º 23
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));
        }
        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));
        }
Exemplo n.º 25
0
        public async Task GetAccounts_ShouldReturnCorrectAmount()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var expected = await dbContext.Accounts.CountAsync();

            //Actual
            var actual = accountsRepository
                         .GetAccounts()
                         .Count();

            //Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 26
0
        public async Task DeleteAccount_ShouldNotWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            accountsRepository        = new AccountsService(dbContext, mapper);

            //Arrange
            var accountId     = 92;
            var expectedCount = await dbContext.Accounts.CountAsync();

            //Actual
            var actual      = accountsRepository.DeleteAccount(accountId);
            var actualCount = await dbContext.Accounts.CountAsync();

            //Assert
            Assert.False(actual);
            Assert.Equal(expectedCount, actualCount);
        }
Exemplo n.º 27
0
        public async Task DeleteClient_ShouldWork()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

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

            //Actual
            var actual       = clientsRepository.DeleteClient(clientId);
            var actualClient = await dbContext.Clients.FindAsync(clientId);

            var actualCount = await dbContext.Clients.CountAsync();

            //Assert
            Assert.True(actual);
            Assert.Null(actualClient);
            Assert.Equal(expectedCount, actualCount);
        }
Exemplo n.º 28
0
        public async Task ShouldNotUpdateAccountAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.AccountsService(dbContext, _mapper);
            AccountDTO accountDto = new AccountDTO()
            {
                Name = "Edited",
                // Balance = 1,8 ,
                // Type = ,
                IsActive = false,
                ClientId = 1
            };

            //Act
            var ex = Assert.Throws <Exception>(() => _service.PutAccount(accountDto.Id, accountDto));

            // Assert
            Assert.That(ex.Message == "Account not found");
        }
Exemplo n.º 29
0
        public async Task ShouldNotUpdateClientAsync()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            ClientDTO clientDto = new ClientDTO()
            {
                Name        = "Client",
                PhoneNumber = "Test",
                Mail        = "*****@*****.**",
                Type        = ClientType.Business,
                AddressId   = 1,
            };

            //Act
            var ex = Assert.Throws <Exception>(() => _service.PutClient(clientDto.Id, clientDto));

            // Assert
            Assert.That(ex.Message == "Client not found");
        }
            public async Task ShouldNotUpdateAccountAsync()
            {
                // Arrange
                using var factory         = new SQLiteDbContextFactory();
                await using var dbContext = factory.CreateContext();
                _accountService           = new BankApplication.Service.Service.AccountsService(dbContext, _mapper);
                AccountDTO accountDto = new AccountDTO()
                {
                    Name     = "Account",
                    Balance  = 000,
                    Type     = AccountType.SavingsAccount,
                    IsActive = false,
                    ClientId = 4,
                    Id       = 6
                };

                //Act
                var ex = Assert.Throws <Exception>(() => _accountService.PutAccount(accountDto.Id, accountDto));

                // Assert
                Assert.That(ex.Message == "Account not found");
            }