public async Task CalculateDiscountNullRequestUserIdArgumentNullException() { var productRepository = new ProductRepository(null); var userRepository = new UserRepository(null); var service = new DiscountService(productRepository, userRepository); var request = new ProductLookUpModel(); request.ProductId = "1"; request.UserId = ""; request.TodayDate = "2020-05-01"; await Assert.ThrowsAsync <ArgumentNullException>(() => service.CalculateDiscount(request, null)); }
public async Task GetUserByIdUserNotFoundArgumentNullException() { var mock = new Mock <IUserRepository>(); mock.Setup(u => u.GetUserById(It.IsAny <string>())) .Returns(Task.FromResult <User>(null)); var productRepository = new ProductRepository(null); var service = new DiscountService(productRepository, mock.Object); var request = new ProductLookUpModel(); request.ProductId = "1"; request.UserId = "1"; await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetUserById("1")); }
public async Task GetProductByIdProductNotFoundArgumentNullException() { var mock = new Mock <IProductRepository>(); mock.Setup(u => u.GetProductById(It.IsAny <string>())) .Returns(Task.FromResult <Product>(null)); var userRepository = new UserRepository(null); var service = new DiscountService(mock.Object, userRepository); var request = new ProductLookUpModel(); request.ProductId = "1"; request.UserId = "1"; request.TodayDate = "2020-05-01"; await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetProductById("1")); }
public async Task CalculateDiscountNullRequestTodayDateArgumentNullException() { var mock = new Mock <IProductRepository>(); var mock2 = new Mock <IUserRepository>(); mock.Setup(u => u.GetProductById(It.IsAny <string>())) .Returns(Task.FromResult(testProduct)); mock2.Setup(u => u.GetUserById(It.IsAny <string>())) .Returns(Task.FromResult(testUser)); var service = new DiscountService(mock.Object, mock2.Object); var request = new ProductLookUpModel(); request.ProductId = "1"; request.UserId = "1"; request.TodayDate = ""; await Assert.ThrowsAsync <ArgumentNullException>(() => service.CalculateDiscount(request, null)); }
public async Task CalculateDiscountProductCannotBeNull() { var mock = new Mock <IProductRepository>(); var mock2 = new Mock <IUserRepository>(); mock.Setup(u => u.GetProductById(It.IsAny <string>())) .Returns(Task.FromResult(testProduct)); mock2.Setup(u => u.GetUserById(It.IsAny <string>())) .Returns(Task.FromResult(testUser)); var service = new DiscountService(mock.Object, mock2.Object); var request = new ProductLookUpModel(); request.ProductId = "1"; request.UserId = "1"; request.TodayDate = "2020-05-01"; var product = await service.CalculateDiscount(request, null); Assert.True(product != null); }
public override async Task <ProductModel> CalculateDiscount(ProductLookUpModel request, ServerCallContext context) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.ProductId)) { throw new ArgumentNullException(nameof(request.ProductId)); } if (string.IsNullOrEmpty(request.UserId)) { throw new ArgumentNullException(nameof(request.UserId)); } if (string.IsNullOrEmpty(request.TodayDate)) { throw new ArgumentNullException(nameof(request.TodayDate)); } var product = await GetProductById(request.ProductId); var user = await GetUserById(request.UserId); var todayDate = DateTime.Parse(request.TodayDate); if (todayDate == DateTime.MinValue) { throw new ArgumentNullException(nameof(request)); } CalculateProducstDiscount(product, user, todayDate); return(product.ParseToProductModel()); }