Esempio n. 1
0
        public async void Should_Create_New_Version_For_Stir_When_Changing_Stir_Data()
        {
            string reference = GenerateReference("SentStirStir");

            // prepare test
            new TestTransactionsGenerator().PrepareTransactionWithStirData(reference, AmlExportStatusEnum.NotSent, StirExportStatusEnum.Sent, new int[] { 44, 55, 66 }, "xxxx");

            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);

                transaction.Stir.StirRelatedAttribure = "yyyy";
                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);
                // check data saved in DB
                var previous = await service.LoadTransaction(reference, 1);

                CheckTransactionData(previous, 1, false);
                CheckTransactionCoreData(previous.Core, 1, true);
                CheckPersonsData(previous.Disposers, 1, true, 3);
                CheckAmlData(previous.Aml, 1, true, AmlExportStatusEnum.NotSent);
                CheckStirData(previous.Stir, 1, false, StirExportStatusEnum.Sent);
                previous.Stir.StirRelatedAttribure.Should().Be("xxxx");

                var saved = await service.LoadTransaction(reference, 2);

                CheckModifiedTransaction(saved);
            }

            void CheckModifiedTransaction(Transaction result)
            {
                CheckTransactionData(result, 2, true);
                CheckTransactionCoreData(result.Core, 1, true);
                CheckPersonsData(result.Disposers, 1, true, 3);
                CheckAmlData(result.Aml, 1, true, AmlExportStatusEnum.NotSent);
                CheckStirData(result.Stir, 2, true, StirExportStatusEnum.NotSent);
                result.Stir.StirRelatedAttribure.Should().Be("yyyy");
            }
        }
Esempio n. 2
0
        public Modification_Of_Multiple_Transactions(ITestOutputHelper testOutputHelper)
        {
            _testOutputHelper = testOutputHelper;

            _testOutputHelper.WriteLine($"Preparing test transaction {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
            _testOutputHelper.WriteLine($"-> {numberOfCoreChanges} transactions with modification of CORE data");
            _testOutputHelper.WriteLine($"-> {numberOfPersonsChanges} transactions with modification of DISPOSERS data");
            _testOutputHelper.WriteLine($"-> {numberOfAmlChanges} transactions with modification of AML related data");
            _testOutputHelper.WriteLine($"-> {numberOfStirChanges} transactions with modification of STIR related data");

            // prepare test transactions
            referencePrefix = $"{DateTime.Now:yyyy-MM-dd hh:mm:ss.ffff}";

            List <Transaction> transactions = new List <Transaction>();

            for (int i = 0; i < numberOfCoreChanges; i++)
            {
                var referenceCore = $"{referencePrefix} Core {Guid.NewGuid()}".Substring(0, 40);
                var transaction   = generator.CreateTransactionWithCoreData(referenceCore, AmlExportStatusEnum.Sent, StirExportStatusEnum.Sent, new int[] { 4, 1, 2, 3 }, "xxxx");
                transactions.Add(transaction);
            }
            for (int i = 0; i < numberOfPersonsChanges; i++)
            {
                var referencePersons = $"{referencePrefix} Persons {Guid.NewGuid()}".Substring(0, 40);
                var transaction      = generator.CreateTransactionWithPersonsData(referencePersons, AmlExportStatusEnum.Sent, StirExportStatusEnum.Sent);
                transactions.Add(transaction);
            }
            for (int i = 0; i < numberOfAmlChanges; i++)
            {
                var referenceAml = $"{referencePrefix} Aml {Guid.NewGuid()}".Substring(0, 40);
                var transaction  = generator.CreateTransactionWithAmlData(referenceAml, AmlExportStatusEnum.Sent, StirExportStatusEnum.Sent, new int[] { 4, 1, 3 }, "xxxx");
                transactions.Add(transaction);
            }
            for (int i = 0; i < numberOfStirChanges; i++)
            {
                var referenceStir = $"{referencePrefix} Stir {Guid.NewGuid()}".Substring(0, 40);
                var transaction   = generator.CreateTransactionWithStirData(referenceStir, AmlExportStatusEnum.Sent, StirExportStatusEnum.Sent, new int[] { 4, 1, 3 }, "xxxx");
                transactions.Add(transaction);
            }

            _testOutputHelper.WriteLine($"Saving test transaction [= START =] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
            using (var context = new FirContext())
            {
                context.AddRange(transactions);
                context.SaveChanges();
            }
            _testOutputHelper.WriteLine($"Saving test transaction [== END ==] {DateTime.Now:dd.MM.yyyy HH:mm:ss.ffffff}");
        }
Esempio n. 3
0
        public async void Should_Not_Create_New_Version_When_Changing_Core_Data()
        {
            string reference = GenerateReference("NotSentCore");

            // prepare test transaction
            new TestTransactionsGenerator().PrepareTransactionWithCoreData(reference, AmlExportStatusEnum.NotSent, StirExportStatusEnum.NotSent, new int[] { 1, 2, 3 }, "xxxx");

            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);

                transaction.Core.PaymentDetails1 = "yyyy";
                await versioningService.SaveTransactionsVersionsAsync();

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

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

                CheckModifiedTransaction(saved);
            }

            void CheckModifiedTransaction(Transaction result)
            {
                CheckTransactionData(result, 1, true);
                CheckTransactionCoreData(result.Core, 1, true);
                CheckPersonsData(result.Disposers, 1, true, 3);
                CheckAmlData(result.Aml, 1, true, AmlExportStatusEnum.NotSent);
                CheckStirData(result.Stir, 1, true, StirExportStatusEnum.NotSent);
                result.Core.PaymentDetails1.Should().Be("yyyy");
            }
        }
        public async void Should_Load_Whole_Transaction_Object()
        {
            FirContext context = new FirContext();
            var        id      = (await context.Transactions.FirstAsync()).Id;

            var transaction = await context
                              .Transactions
                              .Include(t => t.Core)
                              .Include(t => t.Aml)
                              .Include(t => t.Stir)
                              .Include(t => t.Disposers).ThenInclude(l => l.List)
                              .Where(t => t.Id == id)
                              .FirstOrDefaultAsync();

            transaction.Should().NotBeNull();
            transaction.Core.Should().NotBeNull();
            transaction.Aml.Should().NotBeNull();
            transaction.Stir.Should().NotBeNull();
            transaction.Disposers.Should().NotBeNull();
            transaction.Disposers.List.Should().NotBeNull();
            transaction.Disposers.List.Count().Should().BeGreaterThan(0);
        }
Esempio n. 5
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. 6
0
 public TransactionVersioningService(FirContext dbContext, TransactionService transactionService)
 {
     _dbContext          = dbContext;
     _transactionService = transactionService;
 }
Esempio n. 7
0
 public TestTransactionsGenerator()
 {
     _dbContext                    = new FirContext();
     _transactionService           = new TransactionService(_dbContext);
     _transactionVersioningService = new TransactionVersioningService(_dbContext, _transactionService);
 }
Esempio n. 8
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}");
            }
        }
Esempio n. 9
0
 public TransactionService(FirContext dbContext)
 {
     _dbContext = dbContext;
 }