Пример #1
0
        public async Task RemovendoCategoriaComSubCategorias()
        {
            var entity = new Categoria()
            {
                SubCategorias = new List <SubCategoria> {
                    new SubCategoria()
                }
            };
            var repository = new Mock <ICategoriaRepository>();

            repository
            .Setup(s => s.Delete(It.IsAny <Categoria>()))
            .Verifiable();

            repository
            .Setup(s => s.SaveAsync())
            .Returns(Task.Delay(1))
            .Verifiable();

            repository
            .Setup(s => s.GetSingle(It.IsAny <int>()))
            .Returns(entity);

            RemoverCategoria testClass = new RemoverCategoria(repository.Object);

            Notification note = await testClass.Executar(1);

            Assert.AreEqual(true, note.HasErrors);
            Assert.AreEqual("É necessário remover todas sub-categorias desta categoria", note.Errors.FirstOrDefault());
        }
Пример #2
0
        public async Task RemovendoCategoria()
        {
            var entity = new Categoria()
            {
                SubCategorias = new List <SubCategoria>()
            };
            var repository = new Mock <ICategoriaRepository>();

            repository
            .Setup(s => s.Delete(It.IsAny <Categoria>()))
            .Verifiable();

            repository
            .Setup(s => s.SaveAsync())
            .Returns(Task.Delay(1))
            .Verifiable();

            repository
            .Setup(s => s.GetSingle(It.IsAny <int>()))
            .Returns(entity);

            RemoverCategoria testClass = new RemoverCategoria(repository.Object);

            Notification note = await testClass.Executar(1);

            repository.Verify(v => v.Delete(entity));
            repository.Verify(v => v.SaveAsync());

            Assert.AreEqual(false, note.HasErrors);
        }