コード例 #1
0
        public async Task RemoveCategoryIncome_ShouldBeAbleToRemoveOneObjectWithIdEquals1()
        {
            // Arrange
            categoryIncomeEntityObj = new Entities.CategoryIncome {
                Id = 1, Description = "description1"
            };

            mockRepo.Setup(y => y.GetAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(categoryIncomeEntityObj));
            mockRepo.Setup(y => y.RemoveAsync(It.IsAny <Entities.CategoryIncome>()))
            .Returns(Task.FromResult(true));

            var sut       = new CategoryIncomeService(mockRepo.Object, null);
            var getEntity = await sut.GetAsync(1);

            // Act

            var isRemoved = await sut.RemoveAsync(getEntity);

            // Assert
            Assert.AreEqual(1, getEntity.Id, "GetAsync doesn't return correct Object");
            Assert.IsTrue(isRemoved, "RemoveAsync doesn't removed correct Object");
            mockRepo.Verify(x => x.GetAsync(1), Times.Once, "GetAsync should run once");
            mockRepo.Verify(x => x.RemoveAsync(getEntity),
                            Times.Once, "RemoveAsync should run once");
        }
コード例 #2
0
        public async Task GetCategoryIncome_ShouldBeAbleToReturnOneObjectWithIdEquals8()
        {
            // Arrange
            categoryIncomeEntityObj = new Entities.CategoryIncome {
                Id = 8, Description = "description8"
            };

            mockRepo.Setup(y => y.GetAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(categoryIncomeEntityObj));

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

            // Act
            var getAllEntities = await sut.GetAsync(8);

            // Assert
            Assert.AreEqual(8, getAllEntities.Id, "GetAsync doesn't return correct Object");
            mockRepo.Verify(x => x.GetAsync(8), Times.Once, "GetAsync should run once");
        }