// prepares objects for tests
        private void Arrange()
        {
            simcardService = new SimcardServiceModel()
            {
                Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
            };
            simcardController = new SimcardControllerModel()
            {
                Imsi = simcardService.Imsi, Iccid = simcardService.Iccid, Pin = simcardService.Pin, Puk = simcardService.Puk, Status = simcardService.Status
            };

            controllersSimcards = new List <SimcardControllerModel>()
            {
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                }
            };

            serviceSimcards = new List <SimcardServiceModel>()
            {
                new SimcardServiceModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardServiceModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardServiceModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                }
            };

            availableSimcards = new List <SimcardControllerModel>()
            {
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                },
                new SimcardControllerModel()
                {
                    Imsi = 1, Iccid = 2, Pin = 3456, Puk = 7891, Status = true
                }
            };
        }
Exemplo n.º 2
0
        public IActionResult PostSimcard([FromBody] SimcardControllerModel sim)
        {
            try
            {
                log.Info("Reached PostSimcard([FromBody] SimcardControllerModel sim) in SimcardsController.cs");

                if (!ModelState.IsValid)
                {
                    log.Error("A ModelState isn't valid error occured in PostSimcard([FromBody] SimcardControllerModel sim) in SimcardsController.cs");
                    return(StatusCode(400));
                }

                service.Add(mapper.Map <SimcardServiceModel>(sim));
                log.Info("Added new Simcard object in PostSimcard([FromBody] SimcardControllerModel sim) in SimcardsController.cs");

                return(Ok(sim));
            }
            catch (Exception e)
            {
                log.Error(string.Format("An exception {0} occured in PostSimcard([FromBody] SimcardControllerModel sim) in SimcardsController.cs", e));
                return(StatusCode(500));
            }
        }
Exemplo n.º 3
0
        public IActionResult PutSimcard(int id, SimcardControllerModel sim)
        {
            try
            {
                log.Info("Reached PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs");

                if (!ModelState.IsValid)
                {
                    log.Error("A ModelState isn't valid error occured in PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs");
                    return(StatusCode(400));
                }

                if (id != sim.Imsi)
                {
                    log.Error("Simcard object isn't matched with given id! Error occured in PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs");
                    return(BadRequest());
                }

                bool exists = service.Update(mapper.Map <SimcardServiceModel>(sim));

                if (exists)
                {
                    log.Info("Modified Simcard object in PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs");
                    return(Ok());
                }

                log.Error("Simcard object with given id doesn't exist! Error occured in PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs");

                return(NotFound());
            }
            catch (Exception e)
            {
                log.Error(string.Format("An exception {0} occured in PutSimcard(int id, SimcardControllerModel sim) in SimcardsController.cs", e));
                return(StatusCode(500));
            }
        }
Exemplo n.º 4
0
        public IActionResult GetSimcard(int id)
        {
            try
            {
                log.Info("Reached GetSimcard(int id) in SimcardsController.cs");

                SimcardControllerModel sim = mapper.Map <SimcardControllerModel>(service.Get(id));

                if (sim == null)
                {
                    log.Error("Got null object in GetSimcard(int id) in SimcardsController.cs");
                    return(NotFound());
                }

                log.Info("Returned Simcard object from GetSimcard(int id) in SimcardsController.cs");

                return(Ok(sim));
            }
            catch (Exception e)
            {
                log.Error(string.Format("An exception {0} occured in GetSimcard(int id) in SimcardsController.cs", e));
                return(StatusCode(500));
            }
        }