Esempio n. 1
0
        public async Task Animal_CreateCommand_Success()
        {
            Animal rt = null;
            //Arrange
            CreateAnimalCommand command = new CreateAnimalCommand();

            command.AnimalName = "deneme";

            _animalRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Animal, bool> > >()))
            .ReturnsAsync(rt);

            _animalRepository.Setup(x => x.Add(It.IsAny <Animal>()))
            .Returns(new Animal());

            CreateAnimalCommandHandler handler = new CreateAnimalCommandHandler(_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.Added));
        }
Esempio n. 2
0
        public async Task Animal_CreateCommand_NameAlreadyExist()
        {
            //Arrange
            CreateAnimalCommand command = new CreateAnimalCommand();

            command.AnimalName = "test";

            _animalRepository.Setup(x => x.Query())
            .Returns(new List <Animal> {
                new Animal()
                {
                    AnimalId = 1, AnimalName = "test"
                }
            }.AsQueryable());

            _animalRepository.Setup(x => x.Add(It.IsAny <Animal>()))
            .Returns(new Animal());

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

            Assert.That(x.Success, Is.False);
            Assert.That(x.Message, Is.EqualTo(Messages.NameAlreadyExist));
        }