示例#1
0
        public void LoadAllInvoices()
        {
            const int      nbrOfInvoice = 150;
            List <Invoice> invoices     = InvoiceHelper.CreateInvoices(nbrOfInvoice, 35);

            var mock = new Mock <IRepository <Invoice> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetAll()).Returns(invoices.AsQueryable);

            var mockInvoiceRows = new Mock <IRepository <InvoiceRow> >();

            var invoiceDataAccess = new InvoiceDataAccess(mock.Object, mockInvoiceRows.Object);

            invoices.ForEach(invoiceDataAccess.SaveInvoice);

            List <Invoice> repoInvoices = invoiceDataAccess.LoadAllInvoices();

            Assert.AreEqual(nbrOfInvoice, repoInvoices.Count);

            invoices.ForEach(source =>
            {
                Invoice inv = repoInvoices.Find(i => i.Id == source.Id);
                InvoiceHelper.ValidateInvoice(source, inv);
                repoInvoices.Remove(inv);
            });

            Assert.AreEqual(0, repoInvoices.Count);
        }
示例#2
0
        public void TestSaveMultipleInvoice()
        {
            List <Invoice> invoices = InvoiceHelper.CreateInvoices(150, 35);

            var mock = new Mock <IRepository <Invoice> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetQuery()).Returns(invoices.AsQueryable);

            var invoiceDataAccess = new InvoiceDataAccess(mock.Object, null);

            invoices.ForEach(invoiceDataAccess.SaveInvoice);
            invoices.ForEach(i =>
            {
                Invoice repoInvoice = invoiceDataAccess.LoadInvoice(i.Id);
                InvoiceHelper.ValidateInvoice(i, repoInvoice);
            });
        }
示例#3
0
        public void TestSaveInvoice()
        {
            Invoice invoice = InvoiceHelper.CreateInvoices(1, 5)[0];

            var mock = new Mock <IRepository <Invoice> >();

            mock.Setup(repo => repo.SaveChanges());
            mock.Setup(repo => repo.GetQuery()).Returns(new List <Invoice> {
                invoice
            }.AsQueryable);

            var invoiceDataAccess = new InvoiceDataAccess(mock.Object, null);

            invoiceDataAccess.SaveInvoice(invoice);

            Invoice repoInvoice = invoiceDataAccess.LoadInvoice(invoice.Id);

            InvoiceHelper.ValidateInvoice(invoice, repoInvoice);
        }
        public void SaveTest()
        {
            var invoiceToSave = InvoiceHelper.CreateInvoices(1, 1)[0];

            var personDataAccessMock  = new Mock <IPersonDataAccess>();
            var companyDataAccessMock = new Mock <ICompanyDataAccess>();
            var invoiceDataAccessMock = new Mock <IInvoiceDataAccess>();

            invoiceDataAccessMock.Setup(iA => iA.LoadInvoice(invoiceToSave.Id)).Returns(invoiceToSave);
            companyDataAccessMock.Setup(cA => cA.LoadAllCompanies()).Returns(new List <Company>());
            personDataAccessMock.Setup(pA => pA.LoadAllPeople()).Returns(new List <Person>());

            var viewModel = new RegistrateInvoiceViewModel(invoiceDataAccessMock.Object, companyDataAccessMock.Object, personDataAccessMock.Object)
            {
                InvoiceName = invoiceToSave.InvoiceName
            };

            viewModel.Invoices.AddRange(invoiceToSave.InvoiceRows);
            viewModel.Save();

            var loadedInvoice = invoiceDataAccessMock.Object.LoadInvoice(invoiceToSave.Id);

            InvoiceHelper.ValidateInvoice(invoiceToSave, loadedInvoice);
        }