예제 #1
0
        public async Task BetService_AddAsync_WithInvalidModelReturnsErrors()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(m => m.BetRepository.Add(It.IsAny <Bet>()));
            mockUnitOfWork
            .Setup(m => m.LotRepository.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(
                new Lot
            {
                Id   = 1,
                Bets = new List <Bet>()
                {
                    new Bet {
                        Id = 1, Sum = 100
                    }
                },
            });
            var betService = new BetService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());
            var bet        = new BetModel
            {
                Id      = 1,
                LotId   = 1,
                UserId  = "3",
                BetDate = DateTime.UtcNow.AddDays(4),
                Sum     = 50
            };

            var result = await betService.AddAsync(bet);

            Assert.IsFalse(result.Succedeed);
            mockUnitOfWork.Verify(
                m => m.BetRepository.Add(It.IsAny <Bet>()),
                Times.Never);
            mockUnitOfWork.Verify(
                m => m.SaveAsync(),
                Times.Never);
        }
예제 #2
0
        public async Task BetService_AddAsync_AddsBet()
        {
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(m => m.BetRepository.Add(It.IsAny <Bet>()));
            mockUnitOfWork
            .Setup(m => m.LotRepository.GetByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(
                new Lot
            {
                Id   = 1,
                Bets = new List <Bet>(),
            });
            var betService = new BetService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());
            var bet        = new BetModel
            {
                Id      = 1,
                LotId   = 1,
                UserId  = "3",
                BetDate = DateTime.UtcNow.AddDays(4),
                Sum     = 100
            };

            var result = await betService.AddAsync(bet);

            Assert.IsTrue(result.Succedeed);
            mockUnitOfWork.Verify(
                m => m.BetRepository.Add(It.Is <Bet>(
                                             b => b.LotId == bet.LotId &&
                                             b.UserId == bet.UserId &&
                                             b.BetDate == bet.BetDate &&
                                             b.Sum == bet.Sum)),
                Times.Once);
            mockUnitOfWork.Verify(
                m => m.SaveAsync(),
                Times.Once);
        }