Exemple #1
0
        public async Task CategoryIncomeAdd_TryingAddNewObjectToDB_ShouldBeAbleReturnIdEquals8()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.CategoryIncome> >(It.IsAny <List <Models.CategoryIncome> >()))
            .Returns(It.IsAny <List <Entities.CategoryIncome> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()))
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            mockRepo.Setup(y => y.SaveAsync())
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            categoryIncomeEntityLists = new List <Entities.CategoryIncome>
            {
                new Entities.CategoryIncome {
                    Id = 8, Description = "New category Expense was added"
                }
            };
            var sut = new CategoryIncomeService(mockRepo.Object, mockMapper.Object);

            // Act
            var resultOfAddCategoryIncome = await sut.AddCategoryIncome(categoryIncomeModelLists);

            await context.CategoryIncomes.AddRangeAsync(categoryIncomeEntityLists);

            await context.SaveChangesAsync();

            var isAddedNewObject = queryDBInMemory.GetAsync(8);

            // Assert
            Assert.AreEqual(8, isAddedNewObject.Result.Id, "New object was not added, require id=8");
            Assert.IsTrue(resultOfAddCategoryIncome, "Add and Save should return true. Object i added to Database");
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()),
                Times.Once, "AddRangeAsync should run once");
            mockRepo.Verify(
                x => x.SaveAsync(), Times.Once, "SaveAsync should run once");
        }
Exemple #2
0
        public async Task AddCategoryIncome_ShouldRunAddRangeAsyncOnlyOnce()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.CategoryIncome> >(It.IsAny <List <Models.CategoryIncome> >()))
            .Returns(It.IsAny <List <Entities.CategoryIncome> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()))
            .Returns(() => Task.Run(() => { })).Verifiable();

            var sut = new CategoryIncomeService(mockRepo.Object, mockMapper.Object);

            // Act
            await sut.AddCategoryIncome(categoryIncomeModelLists);

            // Assert
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()),
                Times.Once, "AddRangeAsync should run once");
        }
Exemple #3
0
        public async Task AddCategoryIncome_ShouldNotBeAbleToAddCategoryIncome()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.CategoryIncome> >(It.IsAny <List <Models.CategoryIncome> >()))
            .Returns(It.IsAny <List <Entities.CategoryIncome> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()))
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            mockRepo.Setup(y => y.SaveAsync())
            .Returns(() => Task.Run(() => { return(false); })).Verifiable();

            var sut = new CategoryIncomeService(mockRepo.Object, mockMapper.Object);

            // Act
            var resultOfAddCategoryIncome = await sut.AddCategoryIncome(categoryIncomeModelLists);

            // Assert
            Assert.IsFalse(resultOfAddCategoryIncome, "Save should return false");
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.CategoryIncome> >()), Times.Once, "AddRangeAsync should run once");
            mockRepo.Verify(
                x => x.SaveAsync(), Times.Once, "SaveAsync should run once");
        }