Esempio n. 1
0
        public async void Should_Not_Create_New_Version_When_Changing_Aml_And_Stir_Person_Data(PersonsListOperation operation)
        {
            string reference = GenerateReference("NotSentBothPerBoth");

            var generator = new TestTransactionsGenerator();

            generator.PrepareTransactionWithPersonsData(reference, AmlExportStatusEnum.NotSent, StirExportStatusEnum.NotSent);

            using (var context = new FirContext())
            {
                // run test
                TransactionService           readService       = new TransactionService(context);
                TransactionVersioningService versioningService = new TransactionVersioningService(context, readService);
                var transaction = await readService.LoadTransaction(reference, 1);

                switch (operation)
                {
                case PersonsListOperation.Add:
                    transaction.Disposers.List.Add(generator.CreatePerson(20, "created", AmlPersonsRole.AdditionalDisposer, StirPersonsRole.Disposer));
                    break;

                case PersonsListOperation.Modify:
                    transaction.Disposers.List.Single(p => p.PersonId == 8).PersonName = "new_aml_stir";
                    break;

                case PersonsListOperation.Delete:
                    transaction.Disposers.List.RemoveAll(p => p.PersonId == 8);
                    break;
                }
                await versioningService.SaveTransactionsVersionsAsync();

                // check results kept in memory
                CheckModifiedTransaction(transaction);
            }

            // check data saved in DB
            using (var context = new FirContext())
            {
                TransactionService service = new TransactionService(context);
                var saved = await service.LoadTransaction(reference, 1);

                CheckModifiedTransaction(saved);
            }

            void CheckModifiedTransaction(Transaction result)
            {
                CheckTransactionData(result, 1, true);
                CheckTransactionCoreData(result.Core, 1, true);
                CheckAmlData(result.Aml, 1, true, AmlExportStatusEnum.NotSent);
                CheckStirData(result.Stir, 1, true, StirExportStatusEnum.NotSent);

                switch (operation)
                {
                case PersonsListOperation.Add:
                    CheckPersonsData(result.Disposers, 1, true, 4);
                    result.Disposers.List.Select(p => p.PersonId).ToList().Should().BeEquivalentTo(new[] { 4, 6, 8, 20 });
                    break;

                case PersonsListOperation.Modify:
                    CheckPersonsData(result.Disposers, 1, true, 3);
                    result.Disposers.List.Select(p => p.PersonId).ToList().Should().BeEquivalentTo(new[] { 4, 6, 8 });
                    result.Disposers.List.Single(p => p.PersonId == 8).PersonName.Should().Be("new_aml_stir");
                    break;

                case PersonsListOperation.Delete:
                    CheckPersonsData(result.Disposers, 1, true, 2);
                    result.Disposers.List.Select(p => p.PersonId).ToList().Should().BeEquivalentTo(new[] { 4, 6 });
                    break;
                }
            }
        }
Esempio n. 2
0
        public async void Should_Modify_Set_Of_Transactions()
        {
            using (var context = new FirContext())
            {
                // run test
                _testOutputHelper.WriteLine($"Performing modifications on transactions [= START =] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
                TransactionService           readService       = new TransactionService(context);
                TransactionVersioningService versioningService = new TransactionVersioningService(context, readService);
                var transactions = await readService.LoadTransactionsWithRefereneMask(referencePrefix);

                foreach (var transaction in transactions)
                {
                    if (transaction.TransactionReference.Contains("Core"))
                    {
                        transaction.Core.PaymentDetails1 = "yyyy";
                    }
                    if (transaction.TransactionReference.Contains("Persons"))
                    {
                        // add new person
                        transaction.Disposers.List.Add(generator.CreatePerson(20, "created", AmlPersonsRole.AdditionalDisposer, StirPersonsRole.Disposer));
                        // upodate person
                        var modifiedPerson = transaction.Disposers.List.Single(p => p.PersonId == 8).PersonName = "new_aml_stir";
                        // delete persons
                        transaction.Disposers.List.RemoveAll(p => p.PersonId == 4 || p.PersonId == 6);
                    }
                    if (transaction.TransactionReference.Contains("Aml"))
                    {
                        transaction.Aml.AmlRelatedAttribure = "aMl#aMl";
                    }
                    if (transaction.TransactionReference.Contains("Stir"))
                    {
                        transaction.Stir.StirRelatedAttribure = "StiR";
                    }
                }
                _testOutputHelper.WriteLine($"Performing modifications on transactions [== END ==] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");

                _testOutputHelper.WriteLine($"Creating new transactions' versions and saving modified transactions [= START =] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
                await versioningService.SaveTransactionsVersionsAsync();

                _testOutputHelper.WriteLine($"Creating new transactions' versions and saving modified transactions [== END ==] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");

                _testOutputHelper.WriteLine($"Checking test results [= START =] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");

                transactions.Select(t => t.VersionNumber).Distinct().ToList()
                .Should().BeEquivalentTo(new[] { 2 }, "version number should change from 1 to 2 for every modified transaction");

                transactions.Where(t => t.TransactionReference.Contains("Core"))
                .Select(t => t.Core.PaymentDetails1).Distinct().ToList().Should().BeEquivalentTo(new[] { "yyyy" }, "core data should be modified in updated transactions");

                transactions.Where(t => t.TransactionReference.Contains("Person"))
                .SelectMany(t => t.Disposers.List.Select(l => l.PersonId)).Distinct().OrderBy(id => id).ToList().Should().BeEquivalentTo(new long[] { 8, 20 });

                transactions.Where(t => t.TransactionReference.Contains("Aml"))
                .Select(t => t.Aml.AmlRelatedAttribure).Distinct().ToList().Should().BeEquivalentTo(new[] { "aMl#aMl" }, "AML data should be modified in updated transactions");

                transactions.Where(t => t.TransactionReference.Contains("Stir"))
                .Select(t => t.Stir.StirRelatedAttribure).Distinct().ToList().Should().BeEquivalentTo(new[] { "StiR" }, "STIR data should be modified in updated transactions");

                _testOutputHelper.WriteLine($"Checking test results [== END ==] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
            }
        }