Esempio n. 1
0
        public async Task Invoke()
        {
            var animals = await _mediator.Send(new GetDeletedAnimalsQuery());

            if (animals.Any())
            {
                foreach (var a in animals)
                {
                    var animalId = a.Id;

                    var qrDeleteCommand = new DeleteQRCodeCommand
                    {
                        AnimalId = animalId
                    };

                    await _mediator.Send(qrDeleteCommand);

                    var animalDeleteCommand = new DeleteAnimalCommand
                    {
                        Id = animalId
                    };

                    await _mediator.Send(animalDeleteCommand);
                }
            }

            _logger.LogInformation($"The clear database job completed successfully. {animals.Count()} marked data has been deleted.");
        }
Esempio n. 2
0
        public void ShouldRequireValidAnimalId()
        {
            var command = new DeleteAnimalCommand {
                Id = 99
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete([FromBody] DeleteAnimalCommand deleteAnimal)
        {
            var result = await Mediator.Send(deleteAnimal);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
        public void Handle_GivenInvalidId_ThrowsException()
        {
            var command = new DeleteAnimalCommand
            {
                Id = 99
            };

            var handler = new DeleteAnimalCommand.DeleteAnimalCommandHandler(Context);

            Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None));
        }
Esempio n. 5
0
        public MainWindowVm()
        {
            SignInCommand              = new SignInCommand();
            SignOutCommand             = new SignOutCommand();
            AddAnimalCommand           = new AddAnimalCommand();
            EditAnimalCommand          = new EditAnimalCommand();
            DeleteAnimalCommand        = new DeleteAnimalCommand();
            CallVaccineCommand         = new CallVaccineCommand();
            CallTreatmentCommand       = new CallTreatmentCommand();
            CompleteCallCommand        = new CompleteCallCommand();
            ShowVaccinationCardCommand = new ShowVaccinationCardCommand();
            SignInCommand.Execute(this);

            Update();
        }
        public async Task Handle_GivenValidId_ShouldRemovePersistedAnimal()
        {
            var command = new DeleteAnimalCommand
            {
                Id = 3
            };

            var handler = new DeleteAnimalCommand.DeleteAnimalCommandHandler(Context);

            await handler.Handle(command, CancellationToken.None);

            var entity = Context.Animals.Find(command.Id);

            entity.ShouldBeNull();
        }
Esempio n. 7
0
        public async Task Animal_DeleteCommand_Success()
        {
            //Arrange
            DeleteAnimalCommand command = new DeleteAnimalCommand();

            _animalRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Animal, bool> > >()))
            .ReturnsAsync(new Animal()
            {
                AnimalId = 1, AnimalName = "deneme"
            });

            _animalRepository.Setup(x => x.Delete(It.IsAny <Animal>()));

            DeleteAnimalCommandHandler handler = new DeleteAnimalCommandHandler(_animalRepository.Object);
            var x = await handler.Handle(command, new System.Threading.CancellationToken());

            _animalRepository.Verify(x => x.SaveChangesAsync());
            Assert.That(x.Success, Is.True);
            Assert.That(x.Message, Is.EqualTo(Messages.Deleted));
        }