public async Task ReadPdfById_Master_Null()
        {
            var items = new HashSet <GarmentShippingNoteItemModel> {
                new GarmentShippingNoteItemModel("", 1, "", 1)
            };
            var model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.DN, "", DateTimeOffset.Now, 1, "", "", 1, "", "", 1, items);

            var repoMock = new Mock <IGarmentShippingNoteRepository>();

            repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(model);

            var httpMock = new Mock <IHttpClientService>();

            httpMock.Setup(s => s.GetAsync(It.Is <string>(i => i.Contains("master/garment-buyers"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            httpMock.Setup(s => s.GetAsync(It.Is <string>(i => i.Contains("master/account-banks"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError));

            var spMock = GetServiceProvider(repoMock.Object);

            spMock.Setup(s => s.GetService(typeof(IHttpClientService)))
            .Returns(httpMock.Object);

            var service = GetService(spMock.Object);

            var result = await service.ReadPdfById(1);

            Assert.NotNull(result);
        }
        public void GenerateExcel_Success()
        {
            var model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.DN, "", DateTimeOffset.Now, 1, "A99", "", 1, "", "", 1, null);

            var model1 = new GarmentShippingNoteItemModel("", 1, "", 1);

            var repoMock = new Mock <IGarmentShippingNoteRepository>();

            repoMock.Setup(s => s.ReadAll())
            .Returns(new List <GarmentShippingNoteModel>()
            {
                model
            }.AsQueryable());

            var repoMock1 = new Mock <IGarmentShippingNoteItemRepository>();

            repoMock1.Setup(s => s.ReadAll())
            .Returns(new List <GarmentShippingNoteItemModel>()
            {
                model1
            }.AsQueryable());

            var service = GetService(GetServiceProvider(repoMock.Object, repoMock1.Object).Object);

            var result = service.GenerateExcel(model.BuyerCode, DateTime.MinValue, DateTime.MaxValue, 7);

            Assert.NotNull(result);
        }
        public async Task ReadPdfById_Success_IDR()
        {
            var items = new HashSet <GarmentShippingNoteItemModel> {
                new GarmentShippingNoteItemModel("", 1, "IDR", 1)
            };
            var model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.CN, "", DateTimeOffset.Now, 1, "", "", "", "", DateTimeOffset.Now, 1, "", "", 1, items);

            var repoMock = new Mock <IGarmentShippingNoteRepository>();

            repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(model);

            var httpMock = new Mock <IHttpClientService>();

            httpMock.Setup(s => s.GetAsync(It.Is <string>(i => i.Contains("master/garment-buyers"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new { data = new Buyer() }))
            });

            var spMock = GetServiceProvider(repoMock.Object);

            spMock.Setup(s => s.GetService(typeof(IHttpClientService)))
            .Returns(httpMock.Object);

            var service = GetService(spMock.Object);

            var result = await service.ReadPdfById(1);

            Assert.NotNull(result);
        }
示例#4
0
        public Task <int> UpdateAsync(int id, GarmentShippingNoteModel model)
        {
            var modelToUpdate = _dbSet
                                .Include(i => i.Items)
                                .FirstOrDefault(s => s.Id == id);

            modelToUpdate.SetDate(model.Date, _identityProvider.Username, UserAgent);
            modelToUpdate.SetReceiptDate(model.ReceiptDate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetTotalAmount(model.TotalAmount, _identityProvider.Username, UserAgent);
            modelToUpdate.SetDescription(model.Description, _identityProvider.Username, UserAgent);
            modelToUpdate.SetReceiptNo(model.ReceiptNo, _identityProvider.Username, UserAgent);

            foreach (var itemToUpdate in modelToUpdate.Items)
            {
                var item = model.Items.FirstOrDefault(m => m.Id == itemToUpdate.Id);
                if (item != null)
                {
                    itemToUpdate.SetDescription(item.Description, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetCurrencyId(item.CurrencyId, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetCurrencyCode(item.CurrencyCode, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetAmount(item.Amount, _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());
        }
        private GarmentShippingCreditNoteViewModel MapToViewModel(GarmentShippingNoteModel model)
        {
            GarmentShippingCreditNoteViewModel viewModel = new GarmentShippingCreditNoteViewModel
            {
                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,

                noteNo      = model.NoteNo,
                date        = model.Date,
                description = model.Description,
                receiptNo   = model.ReceiptNo,
                receiptDate = model.ReceiptDate,
                buyer       = new Buyer
                {
                    Id   = model.BuyerId,
                    Code = model.BuyerCode,
                    Name = model.BuyerName
                },
                totalAmount = model.TotalAmount,

                items = (model.Items ?? new List <GarmentShippingNoteItemModel>()).Select(i => new GarmentShippingNoteItemViewModel
                {
                    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,

                    description = i.Description,
                    currency    = new Currency
                    {
                        Id   = i.CurrencyId,
                        Code = i.CurrencyCode
                    },
                    amount = i.Amount
                }).ToList()
            };

            return(viewModel);
        }
示例#6
0
        public Task <int> InsertAsync(GarmentShippingNoteModel model)
        {
            model.FlagForCreate(_identityProvider.Username, UserAgent);

            foreach (var item in model.Items)
            {
                item.FlagForCreate(_identityProvider.Username, UserAgent);
            }

            _dbSet.Add(model);

            return(_dbContext.SaveChangesAsync());
        }
        private GarmentShippingNoteModel MapToModel(GarmentShippingCreditNoteViewModel viewModel)
        {
            var items = (viewModel.items ?? new List <GarmentShippingNoteItemViewModel>()).Select(i =>
            {
                i.currency = i.currency ?? new Currency();
                return(new GarmentShippingNoteItemModel(i.description, i.currency.Id.GetValueOrDefault(), i.currency.Code, i.amount)
                {
                    Id = i.Id
                });
            }).ToList();

            viewModel.buyer = viewModel.buyer ?? new Buyer();
            GarmentShippingNoteModel model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.CN, GenerateNo(), viewModel.date.GetValueOrDefault(), viewModel.buyer.Id, viewModel.buyer.Code, viewModel.buyer.Name, viewModel.description, viewModel.receiptNo, viewModel.receiptDate.GetValueOrDefault(), 0, null, null, viewModel.totalAmount, items);

            return(model);
        }
        public void Read_Success()
        {
            var model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.DN, "", DateTimeOffset.Now, 1, "", "", 1, "", "", 1, new List <GarmentShippingNoteItemModel>());

            var repoMock = new Mock <IGarmentShippingNoteRepository>();

            repoMock.Setup(s => s.ReadAll())
            .Returns(new List <GarmentShippingNoteModel>()
            {
                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 <GarmentShippingNoteItemModel>()
            {
                new GarmentShippingNoteItemModel("", 1, "", 1)
            };
            var model = new GarmentShippingNoteModel(GarmentShippingNoteTypeEnum.DN, "", DateTimeOffset.Now, 1, "", "", 1, "", "", 1, items);

            var repoMock = new Mock <IGarmentShippingNoteRepository>();

            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);
        }