Tests: Add PaymentVariantServiceTest
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.Services;
|
||||
using Elwig.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Tests.UnitTests.ServiceTests {
|
||||
[TestFixture]
|
||||
public class PaymentVariantServiceTest {
|
||||
|
||||
private static async Task InitViewModel(PaymentVariantsViewModel vm) {
|
||||
using var ctx = new AppDbContext();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Not implemented yet")]
|
||||
public async Task Test_FillInputs() {
|
||||
var vm = new PaymentVariantsViewModel();
|
||||
await InitViewModel(vm);
|
||||
//await vm.FillInputs();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_CreatePaymentVariant() {
|
||||
HashSet<int> ids;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ids = await ctx.PaymentVariants.Where(v => v.Year == 2021).Select(v => v.AvNr).ToHashSetAsync();
|
||||
}
|
||||
PaymentVar? n = null;
|
||||
await Assert.DoesNotThrowAsync(async () => {
|
||||
n = await PaymentVariantService.CreatePaymentVariant(2021);
|
||||
});
|
||||
Assert.That(ids, Does.Not.Contain(n?.AvNr));
|
||||
using (var ctx = new AppDbContext()) {
|
||||
Assert.IsNotNull(await ctx.PaymentVariants.FindAsync(2021, n?.AvNr));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_Duplicate() {
|
||||
HashSet<int> ids;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
ids = await ctx.PaymentVariants.Where(v => v.Year == 2021).Select(v => v.AvNr).ToHashSetAsync();
|
||||
}
|
||||
Assert.That(ids, Does.Contain(4));
|
||||
PaymentVar? n = null;
|
||||
using (var ctx = new AppDbContext()) {
|
||||
var v = await ctx.PaymentVariants.FindAsync(2021, 4);
|
||||
await Assert.DoesNotThrowAsync(async () => {
|
||||
n = await PaymentVariantService.Duplicate(v!);
|
||||
});
|
||||
}
|
||||
Assert.That(ids, Does.Not.Contain(n?.AvNr));
|
||||
using (var ctx = new AppDbContext()) {
|
||||
Assert.IsNotNull(await ctx.PaymentVariants.FindAsync(2021, n?.AvNr));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Not implemented yet")]
|
||||
public async Task Test_UpdatePaymentVariant() {
|
||||
var vm = new PaymentVariantsViewModel();
|
||||
await InitViewModel(vm);
|
||||
//await vm.UpdatePaymentVariant();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_DeletePaymentVariant() {
|
||||
using (var ctx = new AppDbContext()) {
|
||||
Assert.IsNotNull(await ctx.PaymentVariants.FindAsync(2021, 3));
|
||||
}
|
||||
await Assert.DoesNotThrowAsync(async () => await PaymentVariantService.DeletePaymentVariant(2021, 3));
|
||||
using (var ctx = new AppDbContext()) {
|
||||
Assert.IsNull(await ctx.PaymentVariants.FindAsync(2021, 3));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_Calculate_Commit_Revert() {
|
||||
await Assert.DoesNotThrowAsync(async () => {
|
||||
await PaymentVariantService.Calculate(2021, 2);
|
||||
await PaymentVariantService.Commit(2021, 2);
|
||||
await PaymentVariantService.Revert(2021, 2);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGenerate_Summary_List() {
|
||||
var filename = Path.Combine(Path.GetTempPath(), "PaymentVariant.ods");
|
||||
Assert.That(!File.Exists(filename));
|
||||
InteractionService.NextSave = (_, _) => filename;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var v = await ctx.PaymentVariants.Where(v => v.Year == 2021 && v.AvNr == 2).SingleAsync();
|
||||
await PaymentVariantService.GenerateSummary(v, ExportMode.SaveList);
|
||||
using (Assert.EnterMultipleScope()) {
|
||||
Assert.IsNull(InteractionService.NextSave);
|
||||
Assert.That(File.Exists(filename));
|
||||
Assert.That(new FileInfo(filename).Length, Is.GreaterThan(0));
|
||||
}
|
||||
} finally {
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGenerate_Summary_Pdf() {
|
||||
var filename = Path.Combine(Path.GetTempPath(), "PaymentVariant.pdf");
|
||||
Assert.That(!File.Exists(filename));
|
||||
InteractionService.NextSave = (_, _) => filename;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var v = await ctx.PaymentVariants.Where(v => v.Year == 2021 && v.AvNr == 2).SingleAsync();
|
||||
await PaymentVariantService.GenerateSummary(v, ExportMode.SavePdf);
|
||||
using (Assert.EnterMultipleScope()) {
|
||||
Assert.IsNull(InteractionService.NextSave);
|
||||
Assert.That(File.Exists(filename));
|
||||
Assert.That(new FileInfo(filename).Length, Is.GreaterThan(0));
|
||||
}
|
||||
} finally {
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGenerate_Ebics() {
|
||||
var filename = Path.Combine(Path.GetTempPath(), "PaymentVariant.xml");
|
||||
Assert.That(!File.Exists(filename));
|
||||
InteractionService.NextSave = (_, _) => filename;
|
||||
try {
|
||||
await PaymentVariantService.GenerateEbics(2021, 2);
|
||||
using (Assert.EnterMultipleScope()) {
|
||||
Assert.IsNull(InteractionService.NextSave);
|
||||
Assert.That(File.Exists(filename));
|
||||
Assert.That(new FileInfo(filename).Length, Is.GreaterThan(0));
|
||||
}
|
||||
} finally {
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGenerate_AccountingList() {
|
||||
var filename = Path.Combine(Path.GetTempPath(), "PaymentVariant.ods");
|
||||
Assert.That(!File.Exists(filename));
|
||||
InteractionService.NextSave = (_, _) => filename;
|
||||
try {
|
||||
using var ctx = new AppDbContext();
|
||||
var v = await ctx.PaymentVariants.Where(v => v.Year == 2021 && v.AvNr == 2).SingleAsync();
|
||||
await PaymentVariantService.GenerateAccountingList(v.Year, v.AvNr, v.Name);
|
||||
using (Assert.EnterMultipleScope()) {
|
||||
Assert.IsNull(InteractionService.NextSave);
|
||||
Assert.That(File.Exists(filename));
|
||||
Assert.That(new FileInfo(filename).Length, Is.GreaterThan(0));
|
||||
}
|
||||
} finally {
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user