Пример #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;
                }
            }
        }