public void Delete_ShouldReturnProperResultWhenNotExisting()
        {
            var mr         = new MockRepository(true);
            var controller = mr.CreateController <AnamnesesController>();

            // tries to delete the anamnese
            var result = controller.Delete(999);
            JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;

            Assert.AreEqual(false, deleteMessage.success);
            Assert.IsNotNull(deleteMessage.text);
        }
        public void Delete_HappyPath()
        {
            // obtains a valid patient
            Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
            this.db.SaveChanges();
            var patientId = this.db.Patients.First().Id;

            // obtains a valid certificate model
            ModelMedicalCertificateViewModel certificateModelFormModel = new ModelMedicalCertificateViewModel()
            {
                Name = "My Model",
                Text = "This is a reference: <%FIELD_1%>"
            };

            var mr = new MockRepository(true);
            var certificateModelController       = mr.CreateController <ModelMedicalCertificatesController>();
            var certificateModelControllerResult = certificateModelController.Edit(certificateModelFormModel);
            var certificateModel = this.db.ModelMedicalCertificates.First();

            // tries to save a certificate based on that model
            MedicalCertificateViewModel formModel = new MedicalCertificateViewModel()
            {
                ModelId   = certificateModel.Id,
                PatientId = patientId,
                Fields    = new List <MedicalCertificateFieldViewModel>()
                {
                    new MedicalCertificateFieldViewModel()
                    {
                        Name = "field_1", Value = "value 1"
                    }
                }
            };

            var certificateController       = mr.CreateController <MedicalCertificatesController>();
            var certificateControllerResult = certificateController.Edit(new[] { formModel });
            var certificate = this.db.MedicalCertificates.First();

            // tries to delete the certificate
            var result = certificateController.Delete(certificate.Id);
            JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;

            Assert.AreEqual(true, deleteMessage.success, "deleteMessage.success must be true");
            Assert.AreEqual(0, this.db.MedicalCertificates.Count());
        }
        public void Delete_HappyPath()
        {
            // obtains a valid patient
            Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
            this.db.SaveChanges();
            var patientId = this.db.Patients.First().Id;

            var formModel = new AnamneseViewModel()
            {
                PatientId            = patientId,
                Conclusion           = "This is my anamnese",
                DiagnosticHypotheses = new List <DiagnosticHypothesisViewModel>()
                {
                    new DiagnosticHypothesisViewModel()
                    {
                        Text = "Text", Cid10Code = "Q878"
                    },
                    new DiagnosticHypothesisViewModel()
                    {
                        Text = "Text2", Cid10Code = "Q879"
                    }
                }
            };

            var mr         = new MockRepository(true);
            var controller = mr.CreateController <AnamnesesController>();

            controller.Create(new[] { formModel });

            Assert.IsTrue(controller.ModelState.IsValid);

            // get's the newly created anamnese
            var newlyCreatedAnamnese = this.db.Anamnese.First();

            // tries to delete the anamnese
            var result = controller.Delete(newlyCreatedAnamnese.Id);
            JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;

            Assert.AreEqual(true, deleteMessage.success);
            Assert.AreEqual(0, this.db.Anamnese.Count());
        }