private void Seed()
        {
            using var context = new DataContext(ContextOptions);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var addresses = FactoryService.CreateBatchOfAddresses();

            context.Addresses.AddRange(addresses);

            var customers = FactoryService.CreateBatchOfCustomers();

            context.Customers.AddRange(customers);

            var invoice = FactoryService.CreateInvoice();

            context.Invoices.AddRange(invoice);

            var newInstalls = new NewInstall()
            {
                Id       = 1,
                Customer = customers.FirstOrDefault(),
                Door     = new RollerShutterDoor()
            };

            context.NewInstalls.AddRange(newInstalls);

            context.SaveChanges();
        }
Esempio n. 2
0
        public void PrepareInvoiceHtmlToPdf_ReturnsFileNotFoundException()
        {
            using var context = new DataContext(ContextOptions);
            var    invoiceService = FactoryService.CreateInvoiceServiceWithFileNotFound(context);
            var    invoice        = FactoryService.CreateInvoice();
            var    customer       = FactoryService.CreateCustomer();
            string path           = string.Empty;

            Assert.Throws <FileNotFoundException>(() => invoiceService.PrepareInvoiceHtmlToPdf(invoice, customer, It.IsAny <string>()));
        }
        public async Task AddorUpdate_AddNewCustomer_ReturnsCustomer()
        {
            using var context = new DataContext(ContextOptions);
            var newCustomer     = FactoryService.CreateCustomer();
            var customerService = FactoryService.CreateCustomerService(context);
            var customer        = await customerService.AddorUpdate(newCustomer);

            Assert.Equal("Customer Four", customer.Name);
            Assert.True(customer.Id > 0);
        }
        public async Task GetCustomer_ReturnsNotFoundCustomer()
        {
            using var context = new DataContext(ContextOptions);
            var customerId      = 200;
            var customerService = FactoryService.CreateCustomerService(context);

            var customer = await customerService.GetCustomer(customerId);

            Assert.Null(customer);
        }
        public async Task GetCustomer_ReturnsFoundCustomer_WithoutAddress()
        {
            using var context = new DataContext(ContextOptions);
            var customerId      = 2;
            var customerService = FactoryService.CreateCustomerService(context);

            var customer = await customerService.GetCustomer(customerId);

            Assert.Equal("Customer Two", customer.Name);
            Assert.NotNull(customer.Address);
        }
Esempio n. 6
0
        public async Task GetInvoicesByJobId_ReturnsInvoices_WithJobItems()
        {
            using var context = new DataContext(ContextOptions);
            var jobId          = 1;
            var invoiceService = FactoryService.CreateInvoiceService(context);

            var invoices = await invoiceService.GetInvoicesByJobId(jobId);

            Assert.NotEmpty(invoices);
            Assert.NotEmpty(invoices.First().InvoiceItems);
            Assert.Equal(1, invoices.First().Id);
        }
Esempio n. 7
0
        public async Task UploadToAzureStorageAsync_SuccessfullyUploads_ReturnsFilename()
        {
            using var context = new DataContext(ContextOptions);
            var           invoiceService   = FactoryService.CreateInvoiceService(context);
            Mock <Stream> mockMemoryStream = new Mock <Stream>();
            Mock <BlobContainerClient> mockBlobContainerClient = new Mock <BlobContainerClient>();
            var blobContentInfo = BlobsModelFactory.BlobContentInfo(It.IsAny <ETag>(), It.IsAny <DateTimeOffset>(), It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <long>());
            Mock <Task <Response <BlobContentInfo> > > mockResponse = new Mock <Task <Response <BlobContentInfo> > >(blobContentInfo);
            string html = "<html><body></body></html>";

            mockBlobContainerClient.Setup(c => c.UploadBlobAsync(It.IsAny <string>(), mockMemoryStream.Object, CancellationToken.None)).Returns(mockResponse.Object);

            var result = await invoiceService.UploadToAzureStorageAsync(html, It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>());

            Assert.True(true);
        }
Esempio n. 8
0
        public void PrepareInvoiceHtmlToPdf_ReturnsHtmlString_WithReplacedText()
        {
            using var context = new DataContext(ContextOptions);
            var    invoiceService = FactoryService.CreateInvoiceService(context);
            var    invoice        = FactoryService.CreateInvoice();
            var    customer       = FactoryService.CreateCustomer();
            string name           = "{{invoiceitems.name}}";
            string price          = "{{invoiceitems.price}}";
            string subtotal       = "{{subtotal}}";
            string vattotal       = "{{vattotal}}";
            string total          = "{{total}}";

            string result = invoiceService.PrepareInvoiceHtmlToPdf(invoice, customer, It.IsAny <string>());

            Assert.DoesNotContain(name, result);
            Assert.DoesNotContain(price, result);
            Assert.DoesNotContain(subtotal, result);
            Assert.DoesNotContain(vattotal, result);
            Assert.DoesNotContain(total, result);
        }