public async void Add_New_Ledger() { using (var scope = Factory.Services.CreateScope()) { var mapper = scope.ServiceProvider.GetRequiredService <IMapper>(); var responseService = scope.ServiceProvider.GetRequiredService <IResponseService <LedgerDto> >(); var ledgerDto = new LedgerDto { Code = RandomData.IntGenerate().ToString(), Title = RandomData.StringGenerator(), IsActive = true }; var ledger = mapper.Map <LedgerDto, Ledger>(ledgerDto); var legerRepositoryMock = new Mock <ILegerRepository>(); var unitOfWorkMock = new Mock <IUnitOfWork>(); legerRepositoryMock.Setup(c => c.AddAsync(ledger)).Returns(Task.CompletedTask); unitOfWorkMock.Setup(c => c.SaveChangesAsync()).ReturnsAsync(1); var ledgerService = new LedgerService(legerRepositoryMock.Object, mapper, responseService, unitOfWorkMock.Object); var result = await ledgerService.AddAsync(ledgerDto); result.ApplicationMessage.Should().BeEquivalentTo(UserMessage.Success); } }
public async void Add_Duplicate_Ledger_WithCode() { using (var scope = Factory.Services.CreateScope()) { var mapper = scope.ServiceProvider.GetRequiredService <IMapper>(); var responseService = scope.ServiceProvider.GetRequiredService <IResponseService <LedgerDto> >(); var ledgerDto = new LedgerDto { Code = RandomData.IntGenerate().ToString(), Title = RandomData.StringGenerator(), IsActive = true }; var legerRepositoryMock = new Mock <ILegerRepository>(); var unitOfWorkMock = new Mock <IUnitOfWork>(); legerRepositoryMock.Setup(c => c.ExistsAsync(It.IsAny <Expression <Func <Ledger, bool> > >())) .ReturnsAsync((Expression <Func <Ledger, bool> > pre) => { return(true); }); unitOfWorkMock.Setup(c => c.SaveChangesAsync()).ReturnsAsync(1); var ledgerService = new LedgerService(legerRepositoryMock.Object, mapper, responseService, unitOfWorkMock.Object); var result = await ledgerService.AddAsync(ledgerDto); result.ApplicationMessage.Should().BeEquivalentTo(UserMessage.Duplicated); } }
public async Task <ActionResult> Action(Ledger ledger) { ledger.UserID = UserHelperInfo.GetUserId(); ledger.IP = UserInfo.IP(); ledger.Agent = UserInfo.Agent(); var(IsTrue, ResponseMsg) = await _ledger.AddAsync(ledger); if (IsTrue) { return(RedirectToAction("Index")); } else { LedgerDTO model = new LedgerDTO { Ledgers = await _ledger.GetLedgersAsync() }; ViewBag.Message = ResponseMsg; return(View("Index", model.Ledgers)); } }