public async override Task Should_Success_ReadById() { string testName = GetCurrentMethod(); var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentShippingLocalSalesContractRepository repoSC = new GarmentShippingLocalSalesContractRepository(dbContext, serviceProvider); GarmentShippingLocalSalesContractDataUtil utilSC = new GarmentShippingLocalSalesContractDataUtil(repoSC); GarmentShippingLocalSalesContractModel dataSC = utilSC.GetModel(); var dataSalesContract = await repoSC.InsertAsync(dataSC); GarmentShippingLocalSalesNoteRepository repo = new GarmentShippingLocalSalesNoteRepository(dbContext, serviceProvider); GarmentShippingLocalSalesNoteDataUtil salesNoteDataUtil = new GarmentShippingLocalSalesNoteDataUtil(repo, utilSC); GarmentShippingLocalSalesNoteModel data = salesNoteDataUtil.GetModel(); data.LocalSalesContractId = dataSC.Id; var dataLocalSalesNote = await repo.InsertAsync(data); GarmentShippingLocalSalesDORepository repoLocalSalesDO = new GarmentShippingLocalSalesDORepository(dbContext, serviceProvider); GarmentShippingLocalSalesDODataUtil LocalSalesDODataUtil = new GarmentShippingLocalSalesDODataUtil(repoLocalSalesDO, salesNoteDataUtil); GarmentShippingLocalSalesDOModel dataLocalSalesDO = LocalSalesDODataUtil.GetModel(); dataLocalSalesDO.SetLocalSalesNoteId(data.Id, "test", "unitTest"); var result = await repoLocalSalesDO.InsertAsync(dataLocalSalesDO); var results = repoLocalSalesDO.ReadByIdAsync(dataLocalSalesDO.Id); Assert.NotNull(results); }
public async Task Should_Success_RejectShipping_Data() { string testName = GetCurrentMethod() + "Update"; var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentShippingLocalSalesContractRepository repoSC = new GarmentShippingLocalSalesContractRepository(dbContext, serviceProvider); GarmentShippingLocalSalesContractDataUtil utilSC = new GarmentShippingLocalSalesContractDataUtil(repoSC); GarmentShippingLocalSalesContractModel dataSC = utilSC.GetModel(); var dataSalesContract = await repoSC.InsertAsync(dataSC); GarmentShippingLocalSalesNoteRepository repo = new GarmentShippingLocalSalesNoteRepository(dbContext, serviceProvider); GarmentShippingLocalSalesNoteDataUtil salesNoteDataUtil = new GarmentShippingLocalSalesNoteDataUtil(repo, utilSC); GarmentShippingLocalSalesNoteModel oldModel = salesNoteDataUtil.GetModel(); oldModel.LocalSalesContractId = dataSC.Id; await repo.InsertAsync(oldModel); var model = repo.ReadAll().FirstOrDefault(); var data = await repo.ReadByIdAsync(model.Id); data.SetIsRejectedShipping(true, data.LastModifiedBy, data.LastModifiedAgent); data.SetRejectedReason("reject!", data.LastModifiedBy, data.LastModifiedAgent); var result = await repo.RejectShippingAsync(data.Id, data); Assert.NotEqual(0, result); }
public async override Task Should_Success_Update() { string testName = GetCurrentMethod(); var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentShippingLocalSalesContractRepository repoSC = new GarmentShippingLocalSalesContractRepository(dbContext, serviceProvider); GarmentShippingLocalSalesContractDataUtil utilSC = new GarmentShippingLocalSalesContractDataUtil(repoSC); GarmentShippingLocalSalesContractModel dataSC = utilSC.GetModel(); var dataSalesContract = await repoSC.InsertAsync(dataSC); GarmentShippingLocalSalesNoteRepository repo = new GarmentShippingLocalSalesNoteRepository(dbContext, serviceProvider); GarmentShippingLocalSalesNoteDataUtil salesNoteDataUtil = new GarmentShippingLocalSalesNoteDataUtil(repo, utilSC); GarmentShippingLocalSalesNoteModel data = salesNoteDataUtil.GetModel(); data.LocalSalesContractId = dataSC.Id; var dataLocalSalesNote = await repo.InsertAsync(data); GarmentShippingLocalSalesDORepository repoLocalSalesDO = new GarmentShippingLocalSalesDORepository(dbContext, serviceProvider); GarmentShippingLocalSalesDORepository repoLocalSalesDO2 = new GarmentShippingLocalSalesDORepository(dbContext, serviceProvider); GarmentShippingLocalSalesDODataUtil LocalSalesDODataUtil = new GarmentShippingLocalSalesDODataUtil(repoLocalSalesDO, salesNoteDataUtil); GarmentShippingLocalSalesDOModel oldModel = LocalSalesDODataUtil.GetModel(); oldModel.SetLocalSalesNoteId(data.Id, "test", "unitTest"); await repoLocalSalesDO.InsertAsync(oldModel); var model = repoLocalSalesDO.ReadAll().FirstOrDefault(); var modelToUpdate = await repoLocalSalesDO.ReadByIdAsync(model.Id); modelToUpdate.SetDate(oldModel.Date.AddDays(1), oldModel.LastModifiedBy, oldModel.LastModifiedAgent); modelToUpdate.SetTo("Updated " + oldModel.To, oldModel.LastModifiedBy, oldModel.LastModifiedAgent); modelToUpdate.SetStorageDivision("Updated " + oldModel.StorageDivision, oldModel.LastModifiedBy, oldModel.LastModifiedAgent); modelToUpdate.SetRemark("Updated " + oldModel.Remark, oldModel.LastModifiedBy, oldModel.LastModifiedAgent); foreach (var item in oldModel.Items) { item.SetDescription("Updated " + item.Description, item.LastModifiedBy, item.LastModifiedAgent); item.SetGrossWeight(1 + item.GrossWeight, item.LastModifiedBy, item.LastModifiedAgent); item.SetNettWeight(1 + item.NettWeight, item.LastModifiedBy, item.LastModifiedAgent); } GarmentShippingLocalSalesDOItemModel newItem = new GarmentShippingLocalSalesDOItemModel(2, 2, 2, "a", "", "", 2, 2, "", 2, 2, "", 2, 2); oldModel.Items.Add(newItem); var result = await repoLocalSalesDO2.UpdateAsync(modelToUpdate.Id, modelToUpdate); Assert.NotEqual(0, result); oldModel.Items.Remove(oldModel.Items.First()); var result2 = await repoLocalSalesDO2.UpdateAsync(oldModel.Id, oldModel); Assert.NotEqual(0, result2); }
public Task <int> InsertAsync(GarmentShippingLocalSalesContractModel model) { model.FlagForCreate(_identityProvider.Username, UserAgent); foreach (var item in model.Items) { item.FlagForCreate(_identityProvider.Username, UserAgent); } _dbSet.Add(model); return(_dbContext.SaveChangesAsync()); }
public async Task Should_Success_Update_Data() { string testName = GetCurrentMethod() + "Update"; var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentShippingLocalSalesContractRepository repoSC = new GarmentShippingLocalSalesContractRepository(dbContext, serviceProvider); GarmentShippingLocalSalesContractDataUtil utilSC = new GarmentShippingLocalSalesContractDataUtil(repoSC); GarmentShippingLocalSalesContractModel dataSC = utilSC.GetModel(); var dataSalesContract = await repoSC.InsertAsync(dataSC); GarmentShippingLocalSalesNoteRepository repo = new GarmentShippingLocalSalesNoteRepository(dbContext, serviceProvider); GarmentShippingLocalSalesNoteDataUtil salesNoteDataUtil = new GarmentShippingLocalSalesNoteDataUtil(repo, utilSC); GarmentShippingLocalSalesNoteModel oldModel = salesNoteDataUtil.GetModel(); oldModel.LocalSalesContractId = dataSC.Id; await repo.InsertAsync(oldModel); var model = repo.ReadAll().FirstOrDefault(); var data = await repo.ReadByIdAsync(model.Id); data.SetDate(data.Date.AddDays(1), data.LastModifiedBy, data.LastModifiedAgent); data.SetTempo(model.Tempo + 1, data.LastModifiedBy, data.LastModifiedAgent); data.SetDispositionNo(model.DispositionNo + 1, data.LastModifiedBy, data.LastModifiedAgent); data.SetUseVat(!model.UseVat, data.LastModifiedBy, data.LastModifiedAgent); data.SetRemark(model.Remark + 1, data.LastModifiedBy, data.LastModifiedAgent); data.SetPaymentType(model.PaymentType + 1, data.LastModifiedBy, data.LastModifiedAgent); data.SetPaymentType(model.PaymentType + 1, data.LastModifiedBy, data.LastModifiedAgent); data.SetRejectedReason(null, data.LastModifiedBy, data.LastModifiedAgent); data.SetIsRejectedShipping(false, data.LastModifiedBy, data.LastModifiedAgent); data.SetIsRejectedFinance(false, data.LastModifiedBy, data.LastModifiedAgent); foreach (var item in data.Items) { item.SetProductId(item.ProductId + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetProductCode(item.ProductCode + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetProductName(item.ProductName + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetQuantity(item.Quantity + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetUomId(item.UomId + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetUomUnit(item.UomUnit + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetPrice(item.Price + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetPackageUomUnit(item.PackageUomUnit + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetPackageUomId(item.PackageUomId + 1, data.LastModifiedBy, data.LastModifiedAgent); item.SetPackageQuantity(item.PackageQuantity + 1, data.LastModifiedBy, data.LastModifiedAgent); } var result = await repo.UpdateAsync(data.Id, data); Assert.NotEqual(0, result); }
public Task <int> UpdateAsync(int id, GarmentShippingLocalSalesContractModel model) { var modelToUpdate = _dbSet .Include(i => i.Items) .FirstOrDefault(s => s.Id == id); modelToUpdate.SetBuyerAddress(model.BuyerAddress, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerCode(model.BuyerCode, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerId(model.BuyerId, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerName(model.BuyerName, _identityProvider.Username, UserAgent); modelToUpdate.SetBuyerNPWP(model.BuyerNPWP, _identityProvider.Username, UserAgent); modelToUpdate.SetIsUsed(model.IsUsed, _identityProvider.Username, UserAgent); modelToUpdate.SetIsUseVat(model.IsUseVat, _identityProvider.Username, UserAgent); modelToUpdate.SetSellerAddress(model.SellerAddress, _identityProvider.Username, UserAgent); modelToUpdate.SetSellerName(model.SellerName, _identityProvider.Username, UserAgent); modelToUpdate.SetSellerNPWP(model.SellerNPWP, _identityProvider.Username, UserAgent); modelToUpdate.SetSellerPosition(model.SellerPosition, _identityProvider.Username, UserAgent); modelToUpdate.SetSubTotal(model.SubTotal, _identityProvider.Username, UserAgent); modelToUpdate.SetVatId(model.VatId, _identityProvider.Username, UserAgent); modelToUpdate.SetVatRate(model.VatRate, _identityProvider.Username, UserAgent); foreach (var itemToUpdate in modelToUpdate.Items) { var item = model.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id); if (item != null) { itemToUpdate.SetProductId(item.ProductId, _identityProvider.Username, UserAgent); itemToUpdate.SetProductCode(item.ProductCode, _identityProvider.Username, UserAgent); itemToUpdate.SetProductName(item.ProductName, _identityProvider.Username, UserAgent); itemToUpdate.SetQuantity(item.Quantity, _identityProvider.Username, UserAgent); itemToUpdate.SetUomId(item.UomId, _identityProvider.Username, UserAgent); itemToUpdate.SetUomUnit(item.UomUnit, _identityProvider.Username, UserAgent); itemToUpdate.SetPrice(item.Price, _identityProvider.Username, UserAgent); itemToUpdate.SetRemainingQuantity(item.RemainingQuantity, _identityProvider.Username, UserAgent); } else { itemToUpdate.FlagForDelete(_identityProvider.Username, UserAgent); } } foreach (var item in model.Items.Where(w => w.Id == 0)) { modelToUpdate.Items.Add(item); } return(_dbContext.SaveChangesAsync()); }
public void Read_Success() { var model = new GarmentShippingLocalSalesContractModel("", DateTimeOffset.Now, 1, "", "", "", "", "", "", 1, "", "", "", "", true, 1, false, new List <GarmentShippingLocalSalesContractItemModel>()); var repoMock = new Mock <IGarmentShippingLocalSalesContractRepository>(); repoMock.Setup(s => s.ReadAll()) .Returns(new List <GarmentShippingLocalSalesContractModel>() { model }.AsQueryable()); var service = GetService(GetServiceProvider(repoMock.Object).Object); var result = service.Read(1, 25, "{}", "{}", null); Assert.NotEmpty(result.Data); }
public async Task ReadById_Success() { var items = new List <GarmentShippingLocalSalesContractItemModel>() { new GarmentShippingLocalSalesContractItemModel(1, "", "", 1, 1, "", 1) }; var model = new GarmentShippingLocalSalesContractModel("", DateTimeOffset.Now, 1, "", "", "", "", "", "", 1, "", "", "", "", true, 1, false, items); var item = new GarmentShippingLocalSalesContractItemModel(); var repoMock = new Mock <IGarmentShippingLocalSalesContractRepository>(); repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>())) .ReturnsAsync(model); var service = GetService(GetServiceProvider(repoMock.Object).Object); var result = await service.ReadById(1); Assert.NotNull(result); }
public async override Task Should_Success_Insert() { string testName = GetCurrentMethod(); var dbContext = DbContext(testName); var serviceProvider = GetServiceProviderMock(dbContext).Object; GarmentShippingLocalSalesContractRepository repoSC = new GarmentShippingLocalSalesContractRepository(dbContext, serviceProvider); GarmentShippingLocalSalesContractDataUtil utilSC = new GarmentShippingLocalSalesContractDataUtil(repoSC); GarmentShippingLocalSalesContractModel dataSC = utilSC.GetModel(); var dataSalesContract = await repoSC.InsertAsync(dataSC); GarmentShippingLocalSalesNoteRepository repo = new GarmentShippingLocalSalesNoteRepository(dbContext, serviceProvider); GarmentShippingLocalSalesNoteDataUtil salesNoteDataUtil = new GarmentShippingLocalSalesNoteDataUtil(repo, utilSC); GarmentShippingLocalSalesNoteModel data = salesNoteDataUtil.GetModel(); data.LocalSalesContractId = dataSC.Id; var result = await repo.InsertAsync(data); Assert.NotEqual(0, result); }
private GarmentShippingLocalSalesContractViewModel MapToViewModel(GarmentShippingLocalSalesContractModel model) { GarmentShippingLocalSalesContractViewModel viewModel = new GarmentShippingLocalSalesContractViewModel { Active = model.Active, Id = model.Id, CreatedAgent = model.CreatedAgent, CreatedBy = model.CreatedBy, CreatedUtc = model.CreatedUtc, DeletedAgent = model.DeletedAgent, DeletedBy = model.DeletedBy, DeletedUtc = model.DeletedUtc, IsDeleted = model.IsDeleted, LastModifiedAgent = model.LastModifiedAgent, LastModifiedBy = model.LastModifiedBy, LastModifiedUtc = model.LastModifiedUtc, salesContractNo = model.SalesContractNo, salesContractDate = model.SalesContractDate, transactionType = new TransactionType { id = model.TransactionTypeId, code = model.TransactionTypeCode, name = model.TransactionTypeName }, buyer = new Buyer { Id = model.BuyerId, Code = model.BuyerCode, Name = model.BuyerName, npwp = model.BuyerNPWP, Address = model.BuyerAddress }, isUseVat = model.IsUseVat, isUsed = model.IsUsed, sellerAddress = model.SellerAddress, sellerName = model.SellerName, sellerNPWP = model.SellerNPWP, sellerPosition = model.SellerPosition, subTotal = model.SubTotal, items = (model.Items ?? new List <GarmentShippingLocalSalesContractItemModel>()).Select(i => new GarmentShippingLocalSalesContractItemViewModel { Active = i.Active, Id = i.Id, CreatedAgent = i.CreatedAgent, CreatedBy = i.CreatedBy, CreatedUtc = i.CreatedUtc, DeletedAgent = i.DeletedAgent, DeletedBy = i.DeletedBy, DeletedUtc = i.DeletedUtc, IsDeleted = i.IsDeleted, LastModifiedAgent = i.LastModifiedAgent, LastModifiedBy = i.LastModifiedBy, LastModifiedUtc = i.LastModifiedUtc, product = new ProductViewModel { id = i.ProductId, code = i.ProductCode, name = i.ProductName }, quantity = i.Quantity, uom = new UnitOfMeasurement { Id = i.UomId, Unit = i.UomUnit }, price = i.Price, remainingQuantity = i.RemainingQuantity }).ToList() }; return(viewModel); }