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);
        }
        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);
        }
示例#3
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);
        }
示例#4
0
        public IActionResult NewClient([FromBody] ClientDTO client)
        {
            if (ModelState.IsValid)
            {
                var response = _service.SaveClient(client);
                return(Created("Client successfully created", response));
            }

            return(BadRequest(ModelState));
        }