コード例 #1
0
        public void AddAsync_ShouldThrowNullReferenceException()
        {
            mockUnitOfWork.Setup(x => x.SaveChangesAsync()).Verifiable();
            mockRepo.Setup(x => x.Add(It.IsAny <MemberFee>())).Verifiable();

            MemberFeeService memberFeeService = new MemberFeeService(mockUnitOfWork.Object);

            Func <Task> act = async() => await memberFeeService.AddAsync(null);

            mockUnitOfWork.Verify(x => x.SaveChangesAsync(), Times.Never());
            mockRepo.Verify(x => x.Add(It.IsAny <MemberFee>()), Times.Never());
            act.Should().Throw <NullReferenceException>();
        }
コード例 #2
0
        public void AddAsync_ShouldThrowInvalidArgumentException()
        {
            mockUnitOfWork.Setup(x => x.SaveChangesAsync()).Verifiable();
            mockRepo.Setup(x => x.Add(It.IsAny <MemberFee>())).Verifiable();

            MemberFeeService memberFeeService = new MemberFeeService(mockUnitOfWork.Object);

            Func <Task> act = async() => await memberFeeService.AddAsync(new MemberFeeDto()
            {
                FeeDate = new DateTime(2020, 2, 20), FeeAmount = 500
            });

            mockUnitOfWork.Verify(x => x.SaveChangesAsync(), Times.Never());
            mockRepo.Verify(x => x.Add(It.IsAny <MemberFee>()), Times.Never());
            act.Should().Throw <InvalidArgumentException>();
        }
コード例 #3
0
        public void AddAsync_ShouldAddMemberFee()
        {
            mockUnitOfWork.Setup(x => x.SaveChangesAsync()).Verifiable();
            mockRepo.Setup(x => x.Add(It.IsAny <MemberFee>())).Verifiable();
            mockRepo.Setup(x => x.GetAllAsync(It.IsAny <Expression <Func <MemberFee, bool> > >()))
            .ReturnsAsync((Expression <Func <MemberFee, bool> > expression) => fakeMemberFees);

            MemberFeeService memberFeeService = new MemberFeeService(mockUnitOfWork.Object);

            var result = memberFeeService.AddAsync(new MemberFeeDto()
            {
                FeeDate = new DateTime(2022, 7, 20), FeeAmount = 500
            });

            mockRepo.Verify(x => x.Add(It.IsAny <MemberFee>()), Times.Once());
            mockUnitOfWork.Verify(x => x.SaveChangesAsync(), Times.Once());
        }