public void SetUp() { this.existUserId = 0; this.notExistUserId = 1; this.userIdThatHasNotBorrowOrders = 2; this.existBorrowOrderId = 0; this.notExistBorrowOrderId = 1; this.existBorrowOrders = new List <BorrowOrder>() { new BorrowOrder() { Id = 0 }, new BorrowOrder() { Id = 1 }, new BorrowOrder() { Id = 2 } }; this.validBorrowOrder = new BorrowOrder() { Id = 0 }; this.invalidBorrowOrder = new BorrowOrder() { Id = 1 }; this.mockBorrowOrderRepository = new Mock <IBorrowOrderRepository>(); this.mockBorrowOrderRepository.Setup(c => c.CreateBorrowOrder(this.existUserId, It.IsAny <BorrowOrder>())) .ReturnsAsync(true); this.mockBorrowOrderRepository.Setup(c => c.CreateBorrowOrder(this.notExistUserId, It.IsAny <BorrowOrder>())) .ReturnsAsync(false); this.mockBorrowOrderRepository.Setup(c => c.DeleteBorrowOrder(this.existUserId, this.existBorrowOrderId)) .ReturnsAsync(true); this.mockBorrowOrderRepository.Setup(c => c.DeleteBorrowOrder(this.existUserId, this.notExistBorrowOrderId)) .ReturnsAsync(false); this.mockBorrowOrderRepository.Setup(c => c.DeleteBorrowOrder(this.notExistUserId, this.existBorrowOrderId)) .ReturnsAsync(false); this.mockBorrowOrderRepository.Setup(c => c.DeleteBorrowOrder(this.notExistUserId, this.notExistBorrowOrderId)) .ReturnsAsync(false); this.mockBorrowOrderRepository.Setup(c => c.GetBorrowOrders(this.notExistUserId)) .ReturnsAsync((IList <BorrowOrder>)null); this.mockBorrowOrderRepository.Setup(c => c.GetBorrowOrders(this.existUserId)) .ReturnsAsync(this.existBorrowOrders); this.mockBorrowOrderRepository.Setup(c => c.GetBorrowOrders(this.userIdThatHasNotBorrowOrders)) .ReturnsAsync(new List <BorrowOrder>()); this.mockBorrowOrderValidator = new Mock <IBorrowOrderValidator_OLD>(); this.mockBorrowOrderValidator.Setup(c => c.ValidateAsync(this.validBorrowOrder)).ReturnsAsync(true); this.mockBorrowOrderValidator.Setup(c => c.ValidateAsync(this.invalidBorrowOrder)).ReturnsAsync(false); this.mockBorrowOrderValidator.Setup(c => c.ValidateAsync(null)).ThrowsAsync(new ArgumentNullException()); this.subject = new BorrowOrderController(this.mockBorrowOrderRepository.Object, this.mockBorrowOrderValidator.Object); }
public async Task <Value> CreateBorrowOrder(BorrowOrder borrowOrder) { if (borrowOrder == null) { throw new ArgumentNullException("borrowOrder"); } long userId = this.GetUserIdFromRequest(); return ((await this.borrowOrderValidator.ValidateAsync(borrowOrder) && await this.borrowOrderRepository.CreateBorrowOrder(userId, borrowOrder)) ? new Value((int)ValueType.Success) : new Value((int)ValueType.BadData)); }