public async Task Cannot_add_Invoice_when_it_already_exists() { const string INVOICE_ID = "INV001"; const double NET_AMOUNT = 2000.00; const string DESCRIPTION = "Order 1 invoice"; const int GOODS_RECEIPT = 1; const string SUPPLIER = "SP1"; const string ACCOUNTING_STAFF_ID = "EMP21"; using (var context = new ProcurementDbContext(ContextOptions)) { InvoicesController invoicesController = new InvoicesController(context); var invoice = new InvoiceDTO { InvoiceId = INVOICE_ID, NetAmount = NET_AMOUNT, Description = DESCRIPTION, GoodsReceipt = GOODS_RECEIPT, Supplier = SUPPLIER, AccountingStaffId = ACCOUNTING_STAFF_ID }; try { await invoicesController.PostInvoice(invoice); } catch (Exception exception) { Assert.NotNull(exception); return; } Assert.True(false); } }
public async Task Can_add_new_Invoice_when_it_not_existing() { const string INVOICE_ID = "INV002"; const double NET_AMOUNT = 2000.00; const string DESCRIPTION = "Order 1 invoice"; const int GOODS_RECEIPT = 1; const string SUPPLIER = "SP1"; const string ACCOUNTING_STAFF_ID = "EMP21"; using (var context = new ProcurementDbContext(ContextOptions)) { InvoicesController invoicesController = new InvoicesController(context); var invoice = new InvoiceDTO { InvoiceId = INVOICE_ID, NetAmount = NET_AMOUNT, Description = DESCRIPTION, GoodsReceipt = GOODS_RECEIPT, Supplier = SUPPLIER, AccountingStaffId = ACCOUNTING_STAFF_ID }; var result = await invoicesController.PostInvoice(invoice); var viewResult = Assert.IsType <ActionResult <Invoice> >(result); var actionResult = Assert.IsType <CreatedAtActionResult>(viewResult.Result); var invoiceResult = Assert.IsType <Invoice>(actionResult.Value); Assert.Equal(INVOICE_ID, invoiceResult.InvoiceId); } }
public async Task Edit_Redirects() { var invoice = new Invoice(); // Arrange var mockRepo = new Mock <IInvoicesRepository>(); mockRepo.Setup(repo => repo.AddInvoiceAsync(invoice)) .ReturnsAsync(invoice); var controller = new InvoicesController(mockRepo.Object); // Act var invoiceViewModel = new EditInvoiceViewModel() { Invoice = new Invoice() { Id = 1 } }; var result = await controller.Edit(1, invoiceViewModel); // Assert var redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); }
public async Task Create_ReturnsViewResultWithCreateInvoiceViewModel() { var suppliers = new List <Supplier> { new Supplier() { Id = 1 } }; var subscribers = new List <Subscriber> { new Subscriber() { Id = 1 } }; // Arrange var mockRepo = new Mock <IInvoicesRepository>(); mockRepo.Setup(repo => repo.ListSuppliersAsync()).ReturnsAsync(suppliers); mockRepo.Setup(repo => repo.ListSubscribersAsync()).ReturnsAsync(subscribers); var controller = new InvoicesController(mockRepo.Object); // Act var result = await controller.Create(); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <CreateInvoiceViewModel>(viewResult.ViewData.Model); Assert.Equal(suppliers.First().Id, int.Parse(model.Suppliers.First().Value)); Assert.Equal(subscribers.First().Id, int.Parse(model.Subscribers.First().Value)); }
public async Task EditSingleInvoiceItems_ReturnsNotFoundResult() { var invoices = new List <Item> { new Item() { Id = 1, InvoiceId = 1 }, new Item() { Id = 2, InvoiceId = 1 } }; // Arrange var mockRepo = new Mock <IInvoicesRepository>(); mockRepo.Setup(repo => repo.GetNotExistingItems(invoices)).ReturnsAsync(invoices); var controller = new InvoicesController(mockRepo.Object); // Act var result = await controller.EditSingleInvoiceItems(invoices); // Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); var returnedItems = Assert.IsType <List <Item> >(notFoundObjectResult.Value); Assert.Equal(invoices.Count, returnedItems.Count); }
public async Task EditSingleInvoiceItems_ReturnsOk() { var invoices = new List <Item> { new Item() { Id = 1, InvoiceId = 1 }, new Item() { Id = 2, InvoiceId = 1 } }; // Arrange var mockRepo = new Mock <IInvoicesRepository>(); mockRepo.Setup(repo => repo.GetNotExistingItems(invoices)).ReturnsAsync(new List <Item>()); var controller = new InvoicesController(mockRepo.Object); // Act var result = await controller.EditSingleInvoiceItems(invoices); // Assert var okObjectResult = Assert.IsType <OkResult>(result); }
public void GetAllContainers_ShouldReturnContainers() { var dbContext = new Mock <IAppDbContext>(); dbContext.Setup(d => d.ExecuteStoredProcedure <DealInvoiceViewDTO>(It.IsAny <string>(), It.IsAny <object[]>())) .Returns <string, object[]>((query, parameters) => { List <DealInvoiceViewDTO> list = new List <DealInvoiceViewDTO>(); if (query.Contains("InvoicesList")) { list.Add(new DealInvoiceViewDTO { Id = 1 }); list.Add(new DealInvoiceViewDTO { Id = 2 }); list.Add(new DealInvoiceViewDTO { Id = 3 }); } return(list); }); var factory = new Mock <IDbContextFactory>(); factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object); var controller = new InvoicesController(factory.Object); var result = controller.GetInvoiceAll(1, DateTime.Now, DateTime.Now) as OkNegotiatedContentResult <IEnumerable <DealInvoiceViewDTO> >; Assert.IsNotNull(result); Assert.AreEqual(3, result.Content.Count()); }
public void Update_ShouldReturn_Success() { // Arrange int id = 1; mockInvoicesService.Setup(i => i.UpdateStatusAsync(id)); mockInvoicesService.Setup(i => i.GetById(id)).Returns(new InvoiceDto { Id = 1 }); InvoicesController controller = new InvoicesController(new DeliveryMessage(), mockInvoicesService.Object); bool operationSucceded = false; try { // Act controller.UpdateStatus(id); operationSucceded = true; } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } // Assert Assert.IsTrue(operationSucceded, errorMessage); }
public InvoicesControllerTests() { _customerDataService = A.Fake <ICustomerDataService>(); _invoiceDataService = A.Fake <IInvoiceDataService>(); _invoiceCustomerCommandHandler = A.Fake <ICommandHandler <InvoiceCustomerCommand> >(); _changeInvoiceStatusCommandHandler = A.Fake <ICommandHandler <ChangeInvoiceStatusCommand> >(); _sut = new InvoicesController(_customerDataService, _invoiceDataService, _invoiceCustomerCommandHandler, _changeInvoiceStatusCommandHandler); }
public void Setup() { mockIConverter = new Mock <IConverter>(); mockIUserService = new Mock <IUserService>(); mockIMapper = new Mock <IMapper>(); mockIFileService = new Mock <IFileService>(); mockInvoiceService = new Mock <IInvoiceService>(); controller = new InvoicesController(mockIMapper.Object, mockInvoiceService.Object, mockIFileService.Object, mockIUserService.Object, mockIConverter.Object); }
public InvoicesControllerTest() { invoiceRepositoryMock = new Mock <IRepository <Domain.Invoice> >(); getInvoiceMapperMock = new Mock <IModelDomainMapper <GetInvoice, Domain.Invoice> >(); updateInvoiceMapperMock = new Mock <IModelDomainMapper <UpdateInvoice, Domain.Invoice> >(); testSubject = new InvoicesController(invoiceRepositoryMock.Object, getInvoiceMapperMock.Object, updateInvoiceMapperMock.Object); }
public void SetUp() { realEstatesServiceMock = new Mock <IRealEstatesService>(); agenciesMock = new Mock <IAgenciesService>(); rolesServiceMock = new Mock <IUsersRolesService>(); usersServiceMock = new Mock <IUsersService>(); invoiceMock = new Mock <IInvoicesService>(); controller = new InvoicesController(usersServiceMock.Object, invoiceMock.Object, agenciesMock.Object); }
public static async Task <Stream> PrintInvoiceAsync(AuthenticationProvider authenticationProvider, string id) { try { return(await InvoicesController.PrintInvoiceFromIEAsync(authenticationProvider, id).ConfigureAwait(false)); } catch (Exception exception) { throw new Exception(exception.Message); } }
public async Task GetInvoice_Empty() { var repository = new Mock <IInvoiceRepository>(); var exchageService = new Mock <IExchangeService>(); var logger = TestHelper.CreateDefaultLogger(); var controler = new InvoicesController(repository.Object, exchageService.Object, logger.Object); var result = await controler.GetInvoice(new Guid()); Assert.IsInstanceOf <NotFoundResult>(result.Result); }
public async Task GetInvoices_Empty() { var repository = new Mock <IInvoiceRepository>(); var exchageService = new Mock <IExchangeService>(); var logger = TestHelper.CreateDefaultLogger(); var controler = new InvoicesController(repository.Object, exchageService.Object, logger.Object); var result = await controler.GetInvoices(); Assert.IsEmpty(result); }
public async Task PutInvoice_BadId() { var repository = new Mock <IInvoiceRepository>(); var exchageService = new Mock <IExchangeService>(); var logger = TestHelper.CreateDefaultLogger(); var controler = new InvoicesController(repository.Object, exchageService.Object, logger.Object); var result = await controler.PutInvoice(Guid.NewGuid(), new Invoice()); Assert.IsInstanceOf <BadRequestResult>(result); }
public void DetailsAction_Should_Return_View_For_ExistingInvoice() { // Arrange var controller = new InvoicesController(); // Act var result = controller.Details(1) as ViewResult; // Assert Assert.IsNotNull(result, "Expected View"); }
public void DetailsAction_Should_Return_NotFoundView_For_InvalidInvoice() { // Arrange var controller = new InvoicesController(); // Act var result = controller.Details(999) as ViewResult; // Assert Assert.AreEqual("NotFound", result.ViewBag); }
public void SourceDetail_OnExecute_ReturnSourceDetailType() { //Arrange InvoicesController controller = new InvoicesController(_repo, _logger); //Act var inputDataSource = controller.SourceDetail(); var requestResult = inputDataSource as OkObjectResult; //Assert Assert.IsInstanceOfType(requestResult, typeof(OkObjectResult)); }
public void Index_ShouldReturn_ViewAndListOfInvoices() { // Arrange var invoicesDtos = new List <InvoiceDto> { new InvoiceDto { Id = 1, PostOperatorName = "", Number = "1234567890123", SendDateTime = DateTime.Parse("2020.06.01"), Sender = "Sender 1", SenderAddress = "Sender 1 address", Recipient = "Recipient 1", RecipientAddress = "Recipient 1 Address", CurrentLocation = "Current location 1", ActualStatus = "Actual status 1" }, new InvoiceDto { Id = 2, PostOperatorName = "", Number = "1234567890124", SendDateTime = DateTime.Parse("2020.06.02"), Sender = "Sender 2", SenderAddress = "Sender 2 address", Recipient = "Recipient 1", RecipientAddress = "Recipient 1 Address", CurrentLocation = "Current location 1", ActualStatus = "Actual status 2" } }; mockInvoicesService.Setup(i => i.GetInvoicesByUserId("")).Returns(invoicesDtos); InvoicesController controller = new InvoicesController(new DeliveryMessage(), mockInvoicesService.Object); IEnumerable <InvoiceViewModel> invoiceViewModels = null; try { // Act result = controller.Index() as ViewResult; invoiceViewModels = (List <InvoiceViewModel>)result.ViewData.Model; } catch (Exception ex) { errorMessage = ex.Message + " | " + ex.StackTrace; } // Assert Assert.IsNotNull(result, errorMessage); Assert.IsNotNull(invoiceViewModels, errorMessage); }
public static async Task <string> GetInvoiceAsync(AuthenticationProvider authenticationProvider, Guid id) { try { // Inserir invoice do IE return(await InvoicesController.GetInvoiceFromIEAsync(authenticationProvider, id).ConfigureAwait(false)); } catch (Exception exception) { throw new Exception(exception.Message); } }
public InvoicesControllerTest() { invoiceRepositoryMock = new Mock <IRepository <Domain.Invoice> >(); getInvoiceMapperMock = new Mock <IModelDomainMapper <GetInvoice, Domain.Invoice> >(); updateInvoiceMapperMock = new Mock <IModelDomainMapper <UpdateInvoice, Domain.Invoice> >(); testSubject = new InvoicesController(invoiceRepositoryMock.Object, getInvoiceMapperMock.Object, updateInvoiceMapperMock.Object); testSubject.ControllerContext = new ControllerContext(new ActionContext(new DefaultHttpContext(), new RouteData(), new ControllerActionDescriptor())); }
public async Task DeleteConfirmed_Redirects() { // Arrange var mockRepo = new Mock <IInvoicesRepository>(); var controller = new InvoicesController(mockRepo.Object); // Act var result = await controller.DeleteConfirmed(1); // Assert var redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirect.ActionName); }
public async Task GetInvoice_Exists() { var repository = new Mock <IInvoiceRepository>(); repository.Setup(x => x.GetInvoiceById(It.IsAny <Guid>())) .ReturnsAsync(CreateTestInvoce()); var exchageService = new Mock <IExchangeService>(); var logger = TestHelper.CreateDefaultLogger(); var controler = new InvoicesController(repository.Object, exchageService.Object, logger.Object); var result = await controler.GetInvoice(new Guid()); Assert.IsTrue(TestHelper.AreEqualByJson(CreateTestInvoce(), result.Value)); }
public void Invoices_OnExecute_ReturnInvoices() { //Arrange InvoicesController controller = new InvoicesController(_repo, _logger); //Act var inputDataSource = controller.Invoices(); var requestResult = inputDataSource as OkObjectResult; List <Invoice> txnList = (List <Invoice>)requestResult.Value; //Assert Assert.AreEqual(3, txnList.Count); CollectionAssert.AreEqual(_repo.GetInvoices().ToList(), txnList, new InvoicesComparer()); }
public async void GetById_ReturnsNotFound_WhenInvoiceIsNull() { // Arrange var repoMock = new Mock <IRepository <Invoice> >(); repoMock.Setup(repo => repo.GetById(It.IsAny <int>())).ReturnsAsync(null as Invoice); var controller = new InvoicesController(repoMock.Object, _fakeAuth); // Act var result = await controller.Get(_testInvoice1.Id); // Assert Assert.IsType <NotFoundResult>(result); }
public async void GetById_CallsRepoGetByIdOnce() { // Arrange var repoMock = new Mock <IRepository <Invoice> >(); repoMock.Setup(repo => repo.GetById(It.IsAny <int>())).ReturnsAsync(_testInvoice1); var controller = new InvoicesController(repoMock.Object, _fakeAuth); // Act await controller.Get(_testInvoice1.Id); // Assert repoMock.Verify(repo => repo.GetById(It.IsAny <int>()), Times.Once); }
public void SourceDetail_OnExecute_ReturnSourceDetail() { //Arrange InvoicesController controller = new InvoicesController(_repo, _logger); //Act var inputDataSource = controller.SourceDetail(); var requestResult = inputDataSource as OkObjectResult; InputDataSource result = (InputDataSource)requestResult.Value; //Assert Assert.AreEqual(_repo.GetSourceDetails().InputDataSourceName, result.InputDataSourceName); Assert.AreEqual(_repo.GetSourceDetails().InputDataSourceType, result.InputDataSourceType); }
public async Task Can_get_all_Invoices_in_database() { using (var context = new ProcurementDbContext(ContextOptions)) { InvoicesController invoicesController = new InvoicesController(context); var result = await invoicesController.GetInvoice(); var viewResult = Assert.IsType <ActionResult <IEnumerable <Invoice> > >(result); var invoices = Assert.IsType <List <Invoice> >(viewResult.Value); Assert.Single(invoices); } }
public InvoiceXpressClient(HttpClient httpClient, IOptions <InvoiceXpressClientOptions> options, ILogger <InvoiceXpressClient> logger) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _apiUrl = options.Value.ApiBaseUrl; _apiKey = options.Value.ApiKey; _logger = logger; _httpClient = httpClient; Invoices = new InvoicesController(_httpClient, _apiKey, _logger); }