Exemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] CreateElectronicServiceDto dto)
        {
            var eService = eServiceService.UpdateElectronicService(id, dto);

            if (eService == null)
            {
                return(NotFound("Did not found such Electronic Service"));
            }

            return(NoContent());
        }
        public ElectronicService AddNewEservice(CreateElectronicServiceDto dto)
        {
            if (CheckIfTrezorExist(dto.TreasureAccount))
            {
                return(null);
            }


            var eservice = mapper.Map <ElectronicService>(dto);

            eseviceRepository.Add(eservice);
            return(eservice);
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] CreateElectronicServiceDto dto)
        {
            var eService = eServiceService.AddNewEservice(dto);

            if (eService == null)
            {
                return(NotFound("Service with such Trez already exists"));
            }

            var result = mapper.Map <ElectronicServiceDto>(eService);

            return(CreatedAtAction(nameof(Get), new { id = eService.Id }, result));
        }
        public ElectronicService UpdateElectronicService(int id, CreateElectronicServiceDto dto)
        {
            var eservice = eseviceRepository.Find(id);

            if (eservice == null)
            {
                throw new NotFoundException("Electornic Service not found!");
            }

            eservice    = mapper.Map <ElectronicService>(dto);
            eservice.Id = id;

            eseviceRepository.Update(eservice);
            return(eservice);
        }
        public void CreateElectronicService_ReturnElectronicService()
        {
            //Arrange
            CreateElectronicServiceDto dto = new CreateElectronicServiceDto()
            {
                Name            = "dtodto",
                Amount          = 10,
                TreasureAccount = "dtodto"
            };

            mockEServiceService.Setup(m => m.AddNewEservice(It.IsAny <CreateElectronicServiceDto>())).Returns((CreateElectronicServiceDto dto) => new ElectronicService
            {
                Name            = dto.Name,
                Amount          = dto.Amount,
                TreasureAccount = dto.TreasureAccount
            });

            //Act
            var result = eServiceController.Post(dto) as CreatedAtActionResult;

            //Assert
            Assert.AreEqual(HttpStatusCode.Created, (HttpStatusCode)result.StatusCode);
            Assert.AreEqual("dtodto", (result.Value as ElectronicServiceDto).Name);
        }