public void Add_Returns_Fail_When_NullPatientId()
        {
            Immunisation immunisation = new Immunisation();
            var          repository   = new ImmunisationRepository();

            Assert.ThrowsException <ArgumentException>(() => repository.Add(0, immunisation));
        }
        public void Merge_Returns_Success_When_NoPriorImmunisation()
        {
            var          patientId    = 100;
            Immunisation immunisation = new Immunisation()
            {
                ImmunisationId = 10,
            };
            var repository = new ImmunisationRepository();

            repository.Add(patientId, immunisation);
            repository.Remove(patientId, 10);

            List <Immunisation> immunisationsToBeMerged = new List <Immunisation>()
            {
                new Immunisation()
                {
                    ImmunisationId = 11
                },
                new Immunisation()
                {
                    ImmunisationId = 12
                }
            };

            repository.Merge(patientId, immunisationsToBeMerged);
            Assert.IsNull(repository.Get(patientId, 10));
            Assert.IsNotNull(repository.Get(patientId, 11));
            Assert.IsNotNull(repository.Get(patientId, 12));
            //Assert.ThrowsException<System.Data.Linq.DuplicateKeyException>(() => repository.Add(patientId, immunisation));
        }
示例#3
0
        public IHttpActionResult PutImmunisation(int id, Immunisation immunisation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != immunisation.ImmunisationId)
            {
                return(BadRequest());
            }

            db.Entry(immunisation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ImmunisationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public IHttpActionResult GetImmunisation(int id)
        {
            Immunisation immunisation = db.Immunisations.Find(id);

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

            return(Ok(immunisation));
        }
示例#5
0
        public IHttpActionResult PostImmunisation(Immunisation immunisation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Immunisations.Add(immunisation);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = immunisation.ImmunisationId }, immunisation));
        }
        public void Add_Returns_DuplicateException()
        {
            var          patientId    = 100;
            Immunisation immunisation = new Immunisation()
            {
                ImmunisationId = 10,
            };
            var repository = new ImmunisationRepository();

            repository.Add(patientId, immunisation);

            Assert.ThrowsException <System.Data.Linq.DuplicateKeyException>(() => repository.Add(patientId, immunisation));
        }
示例#7
0
        public IHttpActionResult DeleteImmunisation(int id)
        {
            Immunisation immunisation = db.Immunisations.Find(id);

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

            db.Immunisations.Remove(immunisation);
            db.SaveChanges();

            return(Ok(immunisation));
        }
        public void Add_Returns_Success_When_EmptyImmunisation()
        {
            var          patientId    = 100;
            Immunisation immunisation = new Immunisation()
            {
                ImmunisationId = 10,
            };
            var repository = new ImmunisationRepository();

            repository.Add(patientId, immunisation);

            var returnImmunisation = repository.Get(patientId, immunisation.ImmunisationId);

            Assert.IsNotNull(returnImmunisation);
        }
        public void Add(int patientId, Immunisation immunisation)
        {
            if (immunisation == null)
            {
                throw new ArgumentNullException(nameof(immunisation));
            }

            if (patientId < 1)
            {
                throw new ArgumentException(nameof(patientId));
            }

            // if the immunisation id already exists then an exception will be thrown.
            if (!this.patientImmunisations.TryGetValue(patientId, out var immunisations) && (immunisations == null || !immunisations.Any()))
            {
                this.patientImmunisations[patientId] = new List <Immunisation>();
            }
            else if (this.patientImmunisations[patientId].Any(x => x.ImmunisationId == immunisation.ImmunisationId))
            {
                throw new System.Data.Linq.DuplicateKeyException(immunisation, $"Item already exists with the same immunisation id.");
            }

            this.patientImmunisations[patientId].Add(immunisation);
        }