public void CreateFactor_WithValidData_Then_ReturnNotNull() { var factor = new Factor(1000); factor.AddFactorDetail(1, 1, 10); Assert.NotNull(factor); }
public async Task <int> Handle(CreateFactorCommand request, CancellationToken cancellationToken) { decimal totalValue = 0; if (request == null) { throw new ArgumentNullException("request"); } var products = await _salesDbContextReadOnly.Product .AsNoTracking() .Where(x => request.ProductIds.Contains(x.Id)) .ToListAsync(); if (!products.Any()) { throw new SalesException("Products not found!"); } foreach (var item in products) { totalValue = item.UnitPricing.Value + totalValue; } Factor factor = new Factor(totalValue); foreach (var item in products) { //for first selected product the quantity is 1 factor.AddFactorDetail(item.Id, 1, item.UnitPricing.Value); } await _factorRepository.CreateAsyncUoW(factor); await _factorRepository.SaveChangesAsync(); return(factor.Id); }
public void CreateFactor_WithInvalidPrice_Then_ReturnException() { var factor = new Factor(1000); Assert.Throws <SalesException>(() => factor.AddFactorDetail(1, 1, 0)); }