Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public IActionResult UpdateClient([FromRoute] int id, [FromBody] ClientDTO client)
        {
            if (ModelState.IsValid)
            {
                var response = _service.PutClient(id, client);
                return(Ok(response));
            }

            return(BadRequest(ModelState));
        }
Beispiel #5
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 ShouldBeAbleToUpdateClientAsync()
        {
            // 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 = "543890530",
                Mail        = "*****@*****.**",
                // Type =
                AddressId = 1
            };

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

            ClientDTO clientDto = new ClientDTO()
            {
                Name        = "Edited",
                PhoneNumber = "5490530",
                Mail        = "*****@*****.**",
                // Type = "jygg"
                AddressId = 1,
                Id        = clientEntity.Id
            };

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

            // Assert
            Assert.AreEqual(clientDto.Name, response.Name);
            Assert.AreEqual(clientDto.PhoneNumber, response.PhoneNumber);
            Assert.AreEqual(clientDto.Mail, response.Mail);
            // Assert.AreEqual(clientDto.Type, response.Type);
            Assert.AreEqual(clientDto.AddressId, response.AddressId);
        }