コード例 #1
0
        public async Task Can_edit_client()
        {
            var organization = new Organization {
                Id = 1
            };
            var residency = new Residency {
                Id = 2, Organization = organization, OrganizationId = organization.Id
            };
            var identifierTypes = new[] { new ClientIdentifierType {
                                              Id = 1, Name = "foo"
                                          } };
            var client = new Client {
                Id = 42, Residencies = new[] { residency }, Identifiers = Enumerable.Empty <ClientIdentifier>().ToList()
            };
            var command = GetCommand(add: false);

            tentantOrganizationProvider.GetTenantOrganization().Returns(organization);

            context.Clients = Substitute.For <IDbSet <Client>, IDbAsyncEnumerable <Client> >()
                              .Initialize(new [] { client }.AsQueryable());

            context.ClientIdentifierTypes = Substitute.For <IDbSet <ClientIdentifierType>, IDbAsyncEnumerable <ClientIdentifierType> >()
                                            .Initialize(identifierTypes.AsQueryable());

            context.Payees = Substitute.For <IDbSet <Payee>, IDbAsyncEnumerable <Payee> >()
                             .Initialize(Enumerable.Empty <Payee>().AsQueryable());

            var result = await handler.Handle(command);

            Assert.IsInstanceOfType(result, typeof(SuccessResult));


            context.Received().SaveChangesAsync()
            .IgnoreAwaitForNSubstituteAssertion();
        }
コード例 #2
0
        public async Task <ICommandResult> Handle(ToggleClientIsActiveCommand command)
        {
            Logger.Trace("Handle");

            var organization = tenantOrganizationProvider.GetTenantOrganization();
            var client       = await clients.GetById(command.ClientId.Value)
                               .FirstOrDefaultAsync();

            if (client != null && organization != null)
            {
                client.Residencies
                .Where(r => r.OrganizationId == organization.Id)
                .ForEach(r =>
                {
                    r.IsActive = !r.IsActive;
                });

                await context.SaveChangesAsync();

                Logger.Info("Handle::Success Id:{0} IsActive:Toggled", client.Id);
                return(new SuccessResult(client.Id));
            }

            return(new FailureResult("Client {0} not found.".FormatWith(command.ClientId)));
        }
コード例 #3
0
        private async Task <ICommandResult> Add(AddOrEditClientCommand message)
        {
            Logger.Trace("Add");

            var organization = tenantOrganizationProvider.GetTenantOrganization();
            var client       = message.Editor.BuildClient(context);
            var residency    = client.AddResidency(organization);

            message.Editor.UpdateResidency(residency, context);

            context.Clients.Add(client);

            await context.SaveChangesAsync();

            Logger.Info("Add::Success Id:{0}", client.Id);

            return(new SuccessResult(client.Id));
        }
コード例 #4
0
        protected override void OnBeforeInsert(DbEntityEntry entry, IBelongToOrganization item, InterceptionContext context)
        {
            Logger.Trace("OnBeforeInsert");

            if (item.Organization == null)
            {
                item.Organization = tenantOrganizationProvider.GetTenantOrganization();
            }

            base.OnBeforeInsert(entry, item, context);
        }
コード例 #5
0
 public void Init()
 {
     organization = new Organization {
         Id = 42
     };
     tentantOrganizationProvider = Substitute.For <ITenantOrganizationProvider>();
     tentantOrganizationProvider.GetTenantOrganization().Returns(organization);
     context = Substitute.For <ApplicationDbContext>();
     handler = new AddOrEditClientCommandHandler(context, tentantOrganizationProvider)
     {
         Logger = Substitute.For <ILogger>()
     };
 }
コード例 #6
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Logger.Trace("OnActionExecuting");

            var tenant = tenantOrganizationProvider.GetTenantOrganization();

            if (tenant == null)
            {
                return;
            }

            filterContext.Controller.ViewBag.Features =
                new FeatureChecker(tenant.Features.ToHashSet());
        }
コード例 #7
0
        public async Task Can_get_client_details()
        {
            var id           = 42;
            var organization = new Organization {
                Id = id
            };
            var client = new Client {
                Id = id
            };

            client.AddResidency(organization);
            var query = new ClientDetailsQuery(clientId: id);

            provider.GetTenantOrganization().Returns(organization);

            var items = new[] { client }.AsAsyncQueryable();

            clients.GetById(Arg.Is(client.Id)).Returns(items);

            var result = await handler.Handle(query);

            Assert.IsInstanceOfType(result, typeof(ClientDetails));
            Assert.AreEqual(result.Client.Id, client.Id);
        }
コード例 #8
0
        public void Init()
        {
            organization = new Organization {
                Id = 42
            };
            tenantOrganizationProvider = Substitute.For <ITenantOrganizationProvider>();
            tenantOrganizationProvider.GetTenantOrganization().Returns(organization);
            context = Substitute.For <ApplicationDbContext>();
            clients = Substitute.For <ISearch <Client> >();

            handler = new ToggleClientIsActiveCommandHandler(clients, context, tenantOrganizationProvider)
            {
                Logger = Substitute.For <ILogger>()
            };
        }
コード例 #9
0
        private async Task <ICommandResult> Add(AddOrEditRestitutionOrderCommand message)
        {
            Logger.Trace("Add");

            var organization = tenantOrganizationProvider.GetTenantOrganization();
            var client       = await clients.GetById(message.Editor.ClientId.Value)
                               .FirstAsync();

            var residency = client.Residencies
                            .First(r => r.OrganizationId == organization.Id);
            var order = message.Editor.BuildOrder(context, organization, residency);

            residency.Orders.Add(order);

            await context.SaveChangesAsync();

            Logger.Info("Add::Success Id:{0}", order.Id);

            return(new SuccessResult(order.Id));
        }
コード例 #10
0
        public async Task Can_get_payee_details()
        {
            var organizationId = 24;
            var organization = new Organization {Id = organizationId};

            tenantOrganizationProvider.GetTenantOrganization().Returns(organization);

            var payeeId = 42;
            var payee = new Payee {Id = payeeId, Organization = organization, OrganizationId = organizationId};
            var query = new PayeeDetailsQuery(payeeId: payeeId);

            payees.GetById(Arg.Is(payeeId))
                .Returns(new[] {payee}.AsAsyncQueryable());

            clients.All()
                .Returns(Enumerable.Empty<Client>().AsAsyncQueryable());

            var result = await handler.Handle(query);

            Assert.IsInstanceOfType(result, typeof(PayeeDetails));
            Assert.AreEqual(result.Payee.Id, payee.Id);
        }
コード例 #11
0
        public async Task <ClientEditorForm> Handle(ClientEditorFormQuery message)
        {
            Logger.Trace("Handle");

            var organization    = tenantOrganizationProvider.GetTenantOrganization();
            var identifierTypes = GetIdentifierTypes();

            if (message.ClientId.HasValue)
            {
                var client = await GetClient(message.ClientId.Value);

                if (client != null)
                {
                    return(ClientEditorForm.FromClient(client, organization, identifierTypes));
                }
            }

            return(new ClientEditorForm
            {
                IdentifierTypes = identifierTypes
            });
        }
コード例 #12
0
ファイル: QueryPayeeDetails.cs プロジェクト: ssdug/Gringotts
        public async Task <PayeeDetails> Handle(PayeeDetailsQuery query)
        {
            Logger.Trace("Handle::{0}", query.PayeeId);

            var organization = tenantOrganizationProvider.GetTenantOrganization();

            var payee = await payees.GetById(query.PayeeId)
                        .AsNoTracking()
                        .FirstOrDefaultAsync();

            if (payee != null)
            {
                return new PayeeDetails
                       {
                           Payee           = payee,
                           AttorneyClients = await GetAttorneyClients(payee, organization),
                           GuardianClients = await GetGuardianClients(payee, organization)
                       }
            }
            ;

            return(null);
        }
コード例 #13
0
        public async Task Can_get_form_for_client()
        {
            var organization = new Organization {
                Id = 1
            };
            var clientId        = 42;
            var identifierTypes = new[] { new ClientIdentifierType {
                                              Id = 1, Name = "foo"
                                          } };
            var client = new Client
            {
                Id          = clientId,
                Identifiers = new[]
                {
                    new ClientIdentifier {
                        ClientIdentifierType = identifierTypes.First()
                    }
                }
            };

            client.AddResidency(organization);

            var query = new ClientEditorFormQuery(clientId: clientId);

            tenantOrganizationProvider.GetTenantOrganization().Returns(organization);

            clients.GetById(Arg.Is(clientId)).Returns(new[] { client }.AsAsyncQueryable());

            this.identifierTypes.All.Returns(identifierTypes.AsEnumerable());

            var result = await handler.Handle(query);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ClientEditorForm));
            Assert.AreEqual(result.ClientId, client.Id);
        }
コード例 #14
0
ファイル: Searcher.cs プロジェクト: ssdug/Gringotts
        private Expression <Func <ExpenseCategory, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(category => category.OrganizationId == organization.Id);
        }
コード例 #15
0
        private Expression <Func <Client, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(client => client.Residencies.Any(r => r.OrganizationId == organization.Id));
        }
コード例 #16
0
        private Expression <Func <Payee, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(payee => payee.OrganizationId == organization.Id);
        }
コード例 #17
0
ファイル: Searcher.cs プロジェクト: ssdug/Gringotts
        private Expression <Func <Order, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(order => order.OrganizationId == organization.Id);
        }
コード例 #18
0
ファイル: Searcher.cs プロジェクト: ssdug/Gringotts
        private Expression <Func <Transaction, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(transaction => transaction.OrganizationId == organization.Id);
        }
コード例 #19
0
ファイル: Searcher.cs プロジェクト: ssdug/Gringotts
        private Expression <Func <Account, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(account => account.OrganizationId == organization.Id);
        }
コード例 #20
0
ファイル: Searcher.cs プロジェクト: ssdug/Gringotts
        private Expression <Func <Fund, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(fund => fund.OrganizationId == organization.Id);
        }
コード例 #21
0
        private Expression <Func <LivingUnit, bool> > FilterByOrganization()
        {
            var organization = tenantOrganizationProvider.GetTenantOrganization();

            return(unit => unit.OrganizationId == organization.Id);
        }
コード例 #22
0
 public FeatureService(ITenantOrganizationProvider organizationProvider)
 {
     checker = new FeatureChecker(organizationProvider.GetTenantOrganization().Features.ToArray());
 }