public async Task TestPostFactorySuccess()
        {
            CityDTO cdto = new CityDTO();

            cdto.Latitude  = -20.0;
            cdto.Longitude = 4.0;
            cdto.CityId    = 3;
            cdto.Name      = "Third_Test_City";

            FactoryDTO dto = new FactoryDTO();

            dto.Description = "Post_Test_Factory";
            dto.City        = cdto;


            //Should create the new factory
            var result = await controller.PostFactory(dto);

            Assert.IsType <CreatedAtActionResult>(result);

            OkObjectResult new_res = (OkObjectResult)await controller.GetFactory(3);

            FactoryDTO new_dto = (FactoryDTO)new_res.Value;

            //Information inside the retrived FactoryDTO should be equivalent to the newly created factory
            Assert.Equal("Post_Test_Factory", new_dto.Description);
            Assert.True(3 == new_dto.FactoryId);
            Assert.Equal("Third_Test_City", new_dto.City.Name);
            Assert.True(-20.0 == new_dto.City.Latitude);
            Assert.True(4.0 == new_dto.City.Longitude);
            Assert.True(3 == new_dto.City.CityId);
        }
        public async Task TestPostFactoryFail()
        {
            CityDTO cdto = new CityDTO();

            cdto.Latitude  = -40.0;
            cdto.Longitude = 8.0;
            cdto.CityId    = 2;
            cdto.Name      = "Second_Test_City";

            FactoryDTO dto = new FactoryDTO();

            dto.Description = "Test_Factory";
            dto.City        = cdto;

            //Should not create the new factory if the name already exists
            var result = await controller.PostFactory(dto);

            Assert.IsType <BadRequestResult>(result);

            //Should not create the new factory if the city is already used
            dto.Description = "Post_Test_City";
            var result1 = await controller.PostFactory(dto);

            Assert.IsType <BadRequestResult>(result1);

            //Should not create the new factory if the city does not exists
            dto.City.CityId = 1000;
            dto.City.Name   = "Post_Test_City";
            var result2 = await controller.PostFactory(dto);

            Assert.IsType <BadRequestResult>(result2);
        }
コード例 #3
0
        public async Task <IActionResult> PutFactory([FromRoute] int id, [FromBody] FactoryDTO factoryDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != factoryDTO.FactoryId)
            {
                return(BadRequest());
            }

            var f = await factoryRepository.Edit(id, factoryDTO);

            if (f == null)
            {
                return(BadRequest());
            }

            FactoryDTO dto = new FactoryDTO();

            dto.FactoryId   = f.FactoryId;
            dto.Description = f.Description;
            CityDTO cityDTO = new CityDTO();
            City    c       = f.City;

            cityDTO.CityId    = c.CityId;
            cityDTO.Name      = c.Name;
            cityDTO.Latitude  = c.Latitude;
            cityDTO.Longitude = c.Longitude;

            dto.City = cityDTO;

            return(Ok(dto));
        }
コード例 #4
0
        public async Task <IActionResult> DeleteFactory([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var f = await factoryRepository.Remove(id);

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

            FactoryDTO dto = new FactoryDTO();

            dto.FactoryId   = f.FactoryId;
            dto.Description = f.Description;
            CityDTO cityDTO = new CityDTO();
            City    c       = f.City;

            cityDTO.CityId    = c.CityId;
            cityDTO.Name      = c.Name;
            cityDTO.Latitude  = c.Latitude;
            cityDTO.Longitude = c.Longitude;

            dto.City = cityDTO;

            return(Ok(dto));
        }
コード例 #5
0
        public async Task <IActionResult> PostFactory([FromBody] FactoryDTO factoryDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var f = await factoryRepository.Add(factoryDTO);

            if (f == null)
            {
                return(BadRequest());
            }

            FactoryDTO dto = new FactoryDTO();

            dto.FactoryId   = f.FactoryId;
            dto.Description = f.Description;
            CityDTO cityDTO = new CityDTO();
            City    c       = f.City;

            cityDTO.CityId    = c.CityId;
            cityDTO.Name      = c.Name;
            cityDTO.Latitude  = c.Latitude;
            cityDTO.Longitude = c.Longitude;

            dto.City = cityDTO;

            return(CreatedAtAction("GetFactory", dto));
        }
コード例 #6
0
        public async Task <IActionResult> UpdateCategory([FromBody] FactoryDTO model)
        {
            try
            {
                await _service.UpdateFactory(model);

                return(StatusCode(204));
            }
            catch
            {
                return(StatusCode(404));
            }
        }
コード例 #7
0
        /* [Route("Factory")]*/
        public async Task <IActionResult> AddFactory([FromBody] FactoryDTO model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model"));
                }
                await _service.AddFactory(model);

                return(StatusCode(201));
            }
            catch
            {
                return(StatusCode(400));
            }
        }
        public async Task TestPutFactorySuccess()
        {
            //Should update Factory
            FactoryDTO dto = new FactoryDTO();

            dto.Description = "Test_Factory_Updated";
            dto.FactoryId   = 1;

            var result = await controller.PutFactory(1, dto);

            Assert.IsType <OkObjectResult>(result);

            OkObjectResult new_res = (OkObjectResult)await controller.GetFactory(1);

            FactoryDTO new_dto = (FactoryDTO)new_res.Value;

            //Information inside the retrived FactoryDTO should be updated
            Assert.Equal("Test_Factory_Updated", new_dto.Description);
            Assert.True(1 == new_dto.FactoryId);
        }
        public async Task TestDeleteFactorySuccess()
        {
            //Should remove the factory
            var result = await controller.DeleteFactory(2);

            Assert.IsType <OkObjectResult>(result);

            OkObjectResult new_res = (OkObjectResult)result;

            FactoryDTO new_dto = (FactoryDTO)new_res.Value;

            //Information inside the elimanated FactoryDTO should be equivalent to the requested factory for deletion
            Assert.Equal("Second_Test_Factory", new_dto.Description);
            Assert.True(2 == new_dto.FactoryId);

            //Should not be possible to get the factory once its deleted
            var result2 = await controller.GetFactory(2);

            Assert.IsType <NotFoundResult>(result2);
        }
コード例 #10
0
        public IEnumerable <FactoryDTO> GetFactory()
        {
            List <FactoryDTO> dtos = new List <FactoryDTO>();

            foreach (Factory f in factoryRepository.FindAll())
            {
                FactoryDTO dto = new FactoryDTO();
                dto.FactoryId   = f.FactoryId;
                dto.Description = f.Description;
                CityDTO cityDTO = new CityDTO();
                City    c       = f.City;
                cityDTO.CityId    = c.CityId;
                cityDTO.Name      = c.Name;
                cityDTO.Latitude  = c.Latitude;
                cityDTO.Longitude = c.Longitude;

                dto.City = cityDTO;
                dtos.Add(dto);
            }

            return(dtos);
        }
コード例 #11
0
        public async Task TestPutFactoryFail()
        {
            FactoryDTO dto = new FactoryDTO();

            dto.Description = "Test_Factory";
            dto.FactoryId   = 1000;

            //Should not update if the factory does not exist
            var result = await controller.PutFactory(1000, dto);

            Assert.IsType <BadRequestResult>(result);

            //Should not update if there is a mismatch between a route id and FactoryId
            dto.FactoryId = 1;

            var result1 = await controller.PutFactory(1000, dto);

            Assert.IsType <BadRequestResult>(result1);

            //Should not update if the factory description already exists
            var result2 = await controller.PutFactory(1, dto);

            Assert.IsType <BadRequestResult>(result2);
        }
コード例 #12
0
 public async Task UpdateFactory(FactoryDTO factory)
 {
     var x = _mapper.Map <FactoryDTO, Factory>(factory);
     await _uow.Factories.Update(x);
 }
コード例 #13
0
        public async Task <int> AddFactory(FactoryDTO factory)
        {
            var x = _mapper.Map <FactoryDTO, Factory>(factory);

            return(await _uow.Factories.Add(x));
        }
コード例 #14
0
 public void Logout()
 {
     CurrentFactory = null;
     CurrentAccount = null;
 }
コード例 #15
0
        public async Task Login(string username, string password)
        {
            CurrentAccount = await _authenticationService.LoginAsync(username, password);

            CurrentFactory = CurrentAccount.Employee.Factories.FirstOrDefault();
        }