public async Task DeleteShouldReturnTrueAndDeletedMedicine()
        {
            var db = Tests.GetDatabase();
            var medicineService = new MedicineService(db);
            await medicineService.Create("Lekarstvo",
                                         "6 x 2",
                                         "Lekuva vsichkooooooooooooooooo");

            await db.SaveChangesAsync();

            var id = await db.Medicines
                     .Where(d => d.Name == "Lekarstvo")
                     .Select(d => d.Id)
                     .FirstOrDefaultAsync();

            var deleted = await medicineService.Delete(id);

            await db.SaveChangesAsync();

            deleted.Should()
            .BeTrue();

            db.Medicines.Should()
            .HaveCount(0);
        }
        public async Task CreateShouldReturnTrueAndNewMedicine()
        {
            var db = Tests.GetDatabase();
            var medicineService = new MedicineService(db);
            await medicineService.Create("Lekarstvo",
                                         "6 x 2",
                                         "Lekuva vsichkooooooooooooooooo");

            db.Medicines.Should()
            .HaveCount(1);
        }
Esempio n. 3
0
        public ActionResult <Medicine> Create(MedicineDTO medicineDTO)
        {
            var medicine = new Medicine()
            {
                name         = medicineDTO.name,
                quantity     = medicineDTO.quantity,
                creationDate = medicineDTO.creationDate
            };

            _medicineService.Create(medicine);

            return(CreatedAtRoute
                       ("GetMidicine",
                       new { id = medicine.Id },
                       medicine));
        }
        public async Task EditShouldReturnTrueAndEditedMedicine()
        {
            var db = Tests.GetDatabase();
            var medicineService = new MedicineService(db);
            await medicineService.Create("Lekarstvo",
                                         "6 x 2",
                                         "Lekuva vsichkooooooooooooooooo");

            await db.SaveChangesAsync();

            var id = await db.Medicines
                     .Where(d => d.Name == "Lekarstvo")
                     .Select(d => d.Id)
                     .FirstOrDefaultAsync();

            var edited = await medicineService
                         .Edit(id, "EditedName", "6 x 1", "Description");

            edited.Should()
            .BeTrue();

            db.Medicines.Should()
            .HaveCount(1);
        }
Esempio n. 5
0
 public Medicine Create(Medicine entity)
 => medicineService.Create(entity);