示例#1
0
        public void ExternalDataIsSupplementedWithLocalDataWhenObservationsAreMissing()
        {
            DateTime startDate = new DateTime(2000, 1, 1);
            DateTime endDate = new DateTime(2000, 1, 3);
            var inst = new Instrument { ID = 1, Symbol = "SPY", AssetCategory = AssetClass.Stock, QDMSInstrumentID = 2 };

            var data = new List<OHLCBar>
            {
                new OHLCBar { Open = 1, High = 2, Low = 0, Close = 1, DT = new DateTime(2000,1,1)},
                new OHLCBar { Open = 1, High = 2, Low = 0, Close = 1, DT = new DateTime(2000,1,2)},
            };

            var ppSetStub = new DbSetStub<PriorPosition>();

            _contextMock.Setup(x => x.PriorPositions).Returns(ppSetStub);

            _externalSourceMock.Setup(
                x => x.GetData(It.IsAny<Instrument>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<BarSize>()))
                    .Returns(data);

            _datasourcer.GetData(inst, startDate, endDate);

            _contextMock.Verify(x => x.PriorPositions);
        }
        public void Arrange()
        {
            SetUp();

            Query = new GetEmployerAgreementPdfRequest {
                HashedAccountId = "123RED", HashedLegalAgreementId = "668YUT", UserId = "1234RFV"
            };

            _db = new Mock <EmployerAccountsDbContext>();
            var employerAgreement = new EmployerAgreement {
                Id = ExpectedEmployerAgreementId, Template = new AgreementTemplate {
                    PartialViewName = ExpectedAgreementFileName
                }
            };

            _employerAgreementDbSet = new DbSetStub <EmployerAgreement>(employerAgreement);
            _db.Setup(d => d.Agreements).Returns(_employerAgreementDbSet);

            _hashingService = new Mock <IHashingService>();
            _hashingService.Setup(x => x.DecodeValue("668YUT")).Returns(ExpectedEmployerAgreementId);

            _pdfService = new Mock <IPdfService>();
            _pdfService.Setup(x => x.SubsituteValuesForPdf(It.IsAny <string>())).ReturnsAsync(new MemoryStream());

            RequestHandler = new GetEmployerAgreementPdfQueryHandler(RequestValidator.Object, _pdfService.Object, _hashingService.Object, new Lazy <EmployerAccountsDbContext>(() => _db.Object));
        }
示例#3
0
        public void DataIsCachedBetweenRequests()
        {
            DateTime startDate = new DateTime(2000, 1, 1);
            DateTime endDate = new DateTime(2000, 1, 2);
            var inst = new Instrument { ID = 1, Symbol = "SPY", AssetCategory = AssetClass.Stock, QDMSInstrumentID = 2 };

            var data = new List<OHLCBar>
            {
                new OHLCBar { Open = 1, High = 2, Low = 0, Close = 1, DT = new DateTime(2000,1,1)},
                new OHLCBar { Open = 1, High = 2, Low = 0, Close = 1, DT = new DateTime(2000,1,2)},
            };

            var ppSetStub = new DbSetStub<PriorPosition>();

            _contextMock.Setup(x => x.PriorPositions).Returns(ppSetStub);

            _externalSourceMock.Setup(
                x => x.GetData(It.IsAny<Instrument>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<BarSize>()))
                    .Returns(data);

            _datasourcer.GetData(inst, startDate, endDate);

            //request a second time: should use cache instead of external source
            _datasourcer.GetData(inst, startDate, endDate);

            _externalSourceMock.Verify(x => x.GetData(
                It.IsAny<Instrument>(),
                It.IsAny<DateTime>(),
                It.IsAny<DateTime>(),
                It.IsAny<BarSize>()),
                Times.Once);
        }
示例#4
0
        public void SetUp()
        {
            _inst = new Instrument {ID = 1, Multiplier = 1, AssetCategory = AssetClass.Stock};

            _t = new Trade
            {
                Orders = new List<Order>(),
                CashTransactions = new List<CashTransaction>(),
                FXTransactions = new List<FXTransaction>()
            };

            _dsMock = new Mock<IDataSourcer>();

            _dsMock.Setup(x => x.GetData(It.IsAny<Instrument>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<QDMS.BarSize>()))
                .Returns<Instrument, DateTime, DateTime, QDMS.BarSize>((a, b, c, d) => GenerateData(b, c));

            _contextMock = new Mock<IDBContext>();

            _dbSetStub = new DbSetStub<EquitySummary>();
            var equitySummaries = new List<EquitySummary> 
            { 
                new EquitySummary 
                { 
                    Date = new DateTime(2000,1,1),
                    Total = 10000
                }
            };
            _dbSetStub.AddRange(equitySummaries);
            _contextMock.SetupGet(x => x.EquitySummaries).Returns(_dbSetStub);

            _repository = new TradesRepository(_contextMock.Object, _dsMock.Object, 0.1m);
        }
        public RunOnceServiceTestsFixture()
        {
            _jobsDbSet = new DbSetStub <RunOnceJob>(_jobsList);
            EmployerAccountsDbContext = new Mock <EmployerAccountsDbContext>();
            EmployerAccountsDbContext.Setup(x => x.RunOnceJobs).Returns(_jobsDbSet);

            Logger = new Mock <ILogger>();

            RunOnceJobsService = new RunOnceJobsService(new Lazy <EmployerAccountsDbContext>(() => EmployerAccountsDbContext.Object), Logger.Object);
        }
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();

            _senderAccount = new Account
            {
                Id       = 333333,
                HashedId = "ABC123",
                Name     = "Sender"
            };

            _receiverAccount = new Account
            {
                Id       = 222222,
                HashedId = "XYZ987",
                Name     = "Receiver"
            };

            _receivedTransferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                                    .WithId(111111)
                                                    .WithSenderAccount(_senderAccount)
                                                    .WithReceiverAccount(_receiverAccount)
                                                    .WithStatus(TransferConnectionInvitationStatus.Pending)
                                                    .Build();

            _rejectedTransferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                                    .WithId(111111)
                                                    .WithSenderAccount(_senderAccount)
                                                    .WithReceiverAccount(_receiverAccount)
                                                    .WithStatus(TransferConnectionInvitationStatus.Rejected)
                                                    .Build();

            _transferConnectionInvitations = new List <TransferConnectionInvitation> {
                _receivedTransferConnectionInvitation, _rejectedTransferConnectionInvitation
            };
            _transferConnectionInvitationsDbSet = new DbSetStub <TransferConnectionInvitation>(_transferConnectionInvitations);

            _configurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <AccountMappings>();
                c.AddProfile <TransferConnectionInvitationMappings>();
                c.AddProfile <UserMappings>();
            });

            _db.Setup(d => d.TransferConnectionInvitations).Returns(_transferConnectionInvitationsDbSet);

            _handler = new GetReceivedTransferConnectionInvitationQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider);

            _query = new GetReceivedTransferConnectionInvitationQuery
            {
                AccountId = _receiverAccount.Id,
                TransferConnectionInvitationId = _receivedTransferConnectionInvitation.Id
            };
        }
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();

            _account = new Account
            {
                Id       = 333333,
                HashedId = "ABC123",
                Name     = "Account"
            };

            _sentTransferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                                .WithId(222222)
                                                .WithSenderAccount(_account)
                                                .WithReceiverAccount(new Account())
                                                .WithCreatedDate(DateTime.UtcNow)
                                                .Build();

            _receivedTransferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                                    .WithId(111111)
                                                    .WithSenderAccount(new Account())
                                                    .WithReceiverAccount(_account)
                                                    .WithCreatedDate(DateTime.UtcNow.AddDays(-1))
                                                    .Build();

            _transferConnectionInvitations = new List <TransferConnectionInvitation>
            {
                _sentTransferConnectionInvitation,
                _receivedTransferConnectionInvitation,
                new TransferConnectionInvitationBuilder()
                .WithSenderAccount(new Account())
                .WithReceiverAccount(new Account())
                .WithCreatedDate(DateTime.UtcNow.AddDays(-2))
                .Build()
            };

            _transferConnectionInvitationsDbSet = new DbSetStub <TransferConnectionInvitation>(_transferConnectionInvitations);

            _configurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <AccountMappings>();
                c.AddProfile <TransferConnectionInvitationMappings>();
                c.AddProfile <UserMappings>();
            });

            _db.Setup(d => d.TransferConnectionInvitations).Returns(_transferConnectionInvitationsDbSet);

            _handler = new GetTransferConnectionInvitationsQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider);

            _query = new GetTransferConnectionInvitationsQuery
            {
                AccountId = _account.Id
            };
        }
示例#8
0
        public void Arrange()
        {
            _hashingService = new Mock <IHashingService>();
            _validator      = new Mock <IValidator <GetNextUnsignedEmployerAgreementRequest> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <GetNextUnsignedEmployerAgreementRequest>())).ReturnsAsync(new ValidationResult());
            _db = new Mock <EmployerAccountsDbContext>();

            _accountLegalEntity      = new AccountLegalEntity();
            _accountLegalEntityDbSet = new DbSetStub <AccountLegalEntity>(_accountLegalEntity);

            _db.Setup(d => d.AccountLegalEntities).Returns(_accountLegalEntityDbSet);

            _handler = new GetNextUnsignedEmployerAgreementQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _hashingService.Object, _validator.Object);
        }
示例#9
0
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();

            _receiverAccount = new Account
            {
                Id             = 111111,
                PublicHashedId = "ABC123"
            };

            _senderAccount = new Account
            {
                Id             = 222222,
                PublicHashedId = "XYZ987"
            };

            _accounts = new List <Account> {
                _receiverAccount, _senderAccount
            };
            _accountsDbSet = new DbSetStub <Account>(_accounts);
            _transferConnectionInvitations      = new List <TransferConnectionInvitation>();
            _transferConnectionInvitationsDbSet = new DbSetStub <TransferConnectionInvitation>(_transferConnectionInvitations);
            _configurationProvider = new MapperConfiguration(c => c.AddProfile <AccountMappings>());
            _publicHashingService  = new Mock <IPublicHashingService>();

            _db.Setup(d => d.Accounts).Returns(_accountsDbSet);
            _db.Setup(d => d.TransferConnectionInvitations).Returns(_transferConnectionInvitationsDbSet);
            _publicHashingService.Setup(h => h.DecodeValue(_receiverAccount.PublicHashedId)).Returns(_receiverAccount.Id);

            var outParam = _receiverAccount.Id;

            _publicHashingService.Setup(
                h => h.TryDecodeValue(
                    _receiverAccount.PublicHashedId,
                    out outParam))
            .Returns(true);

            _handler = new SendTransferConnectionInvitationQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider, _publicHashingService.Object);

            _query = new SendTransferConnectionInvitationQuery
            {
                AccountId = _senderAccount.Id,
                ReceiverAccountPublicHashedId = _receiverAccount.PublicHashedId
            };
        }
        public SeedAccountUsersJobTestsFixture()
        {
            RunOnceService = new Mock <IRunOnceJobsService>();
            RunOnceService.Setup(x => x.RunOnce(It.IsAny <string>(), It.IsAny <Func <Task> >()))
            .Returns((string jobName, Func <Task> function) => function());

            AccountUsersRepository = new Mock <IAccountUsersRepository>();
            AccountUsersRepository.SetupInMemoryCollection(ReadStoreUsers);

            UsersToMigrate = new List <Membership> {
                UserOwnerRole, UserTranasactorRole, UserNoRole
            };
            _usersDbSet = new DbSetStub <Membership>(UsersToMigrate);

            EmployerAccountsDbContext = new Mock <EmployerAccountsDbContext>();
            EmployerAccountsDbContext.Setup(x => x.Memberships).Returns(_usersDbSet);

            Logger = new Mock <ILogger>();

            SeedAccountUsersJob =
                new SeedAccountUsersJob(RunOnceService.Object, AccountUsersRepository.Object, new Lazy <EmployerAccountsDbContext>(() => EmployerAccountsDbContext.Object), Logger.Object);
        }
示例#11
0
        public GetLegalEntityQueryTestsFixture()
        {
            Db = new Mock <EmployerAccountsDbContext>();

            LegalEntities      = new List <LegalEntity>();
            LegalEntitiesDbSet = new DbSetStub <LegalEntity>(LegalEntities);

            AccountLegalEntities      = new List <AccountLegalEntity>();
            AccountLegalEntitiesDbSet = new DbSetStub <AccountLegalEntity>(AccountLegalEntities);

            UserA = new User {
                Id = 1, Email = "*****@*****.**"
            };
            UserB = new User {
                Id = 2, Email = "*****@*****.**"
            };
            Users = new List <User> {
                UserA, UserB
            };
            UsersDbSet = new DbSetStub <User>(Users);

            Db.Setup(d => d.LegalEntities).Returns(LegalEntitiesDbSet);
            Db.Setup(d => d.AccountLegalEntities).Returns(AccountLegalEntitiesDbSet);
            Db.Setup(d => d.Users).Returns(UsersDbSet);

            Handler = new GetLegalEntityQueryHandler(new Lazy <EmployerAccountsDbContext>(() => Db.Object));

            SetAccount()
            .SetLegalEntity()
            .SetLegalAccountLegalEntity()
            .AddLegalEntityAgreement(1, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus.Removed, UserA.Id)
            .AddLegalEntityAgreement(1, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus.Signed, UserB.Id)
            .AddLegalEntityAgreement(2, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus.Signed, UserA.Id)
            .AddLegalEntityAgreement(3, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus.Pending)
            .AddLegalEntityAgreement(3, EmployerAccounts.Models.EmployerAgreement.EmployerAgreementStatus.Expired)
            .EvaluateSignedAndPendingAgreementIdsForAllAccountLegalEntities();
        }
示例#12
0
        public void LastPriceFxDataIsInvertedWhenNecessary()
        {
            var inst = new Instrument { Symbol = "USD.CAD", ID = 1, AssetCategory = AssetClass.Cash };
            var startDate = new DateTime(2000, 1, 1);

            var fxrSetStub = new DbSetStub<FXRate>();
            fxrSetStub.Add(new FXRate { FromCurrencyID = 2, ToCurrencyID = 1, Date = startDate, Rate = 1.1m });

            var currencySetStub = new DbSetStub<Currency>();
            currencySetStub.Add(new Currency { ID = 2, Name = "CAD" });

            _contextMock.Setup(x => x.Currencies).Returns(currencySetStub);
            _contextMock.Setup(x => x.FXRates).Returns(fxrSetStub);

            decimal fxRate;
            var price = _datasourcer.GetLastPrice(inst, out fxRate);

            Assert.AreEqual(1m / 1.1m, price);
        }
示例#13
0
        public void IfExternalSourceHasNoDataLocalBackupIsUsedInstead()
        {
            DateTime startDate = new DateTime(2000, 1, 1);
            DateTime endDate = new DateTime(2000, 2, 1);
            var inst = new Instrument { ID = 1, Symbol = "SPY", AssetCategory = AssetClass.Stock, QDMSInstrumentID = 2};

            var ppSetStub = new DbSetStub<PriorPosition>();

            _contextMock.Setup(x => x.PriorPositions).Returns(ppSetStub);

            _externalSourceMock.Setup(
                x => x.GetData(It.IsAny<Instrument>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<BarSize>()))
                    .Returns(new List<OHLCBar>());
            
            _datasourcer.GetData(inst, startDate, endDate);

            _externalSourceMock.Verify(x => x.GetData(
                It.IsAny<Instrument>(),
                It.IsAny<DateTime>(),
                It.IsAny<DateTime>(),
                It.IsAny<BarSize>()));

            _contextMock.Verify(x => x.PriorPositions);
        }
示例#14
0
        public void CashInstrumentLocalRequestsUseFxRates()
        {
            DateTime startDate = new DateTime(2000, 1, 1);
            DateTime endDate = new DateTime(2000, 1, 3);
            var inst = new Instrument { ID = 1, Symbol = "EUR.USD", AssetCategory = AssetClass.Cash, QDMSInstrumentID = 2 };

            var fxrSetStub = new DbSetStub<FXRate>();

            var currencySetStub = new DbSetStub<Currency>();
            currencySetStub.Add(new Currency { ID = 2, Name = "EUR" });

            _contextMock.Setup(x => x.Currencies).Returns(currencySetStub);
            _contextMock.Setup(x => x.FXRates).Returns(fxrSetStub);

            _externalSourceMock.Setup(
                x => x.GetData(It.IsAny<Instrument>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<DateTime>(),
                    It.IsAny<BarSize>()))
                    .Returns(new List<OHLCBar>());

            _datasourcer.GetData(inst, startDate, endDate);

            _contextMock.Verify(x => x.FXRates);
        }
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();
            _employerCommitmentApi = new Mock <IEmployerCommitmentApi>();
            _hashingService        = new Mock <IHashingService>();

            _account1 = new Account
            {
                Id       = 111111,
                HashedId = "ABC123",
                Name     = "Account 1"
            };

            _account2 = new Account
            {
                Id       = 22222,
                HashedId = "ZYX987",
                Name     = "Account 2"
            };

            _sentTransferRequest = new TransferRequestSummary
            {
                HashedTransferRequestId          = "DEF456",
                HashedSendingEmployerAccountId   = _account1.HashedId,
                HashedReceivingEmployerAccountId = _account2.HashedId,
                TransferCost = 123.456m
            };

            _receivedTransferRequest = new TransferRequestSummary
            {
                HashedTransferRequestId          = "GHI789",
                HashedSendingEmployerAccountId   = _account2.HashedId,
                HashedReceivingEmployerAccountId = _account1.HashedId,
                TransferCost = 789.012m
            };

            _transferRequests = new List <TransferRequestSummary>
            {
                _sentTransferRequest,
                _receivedTransferRequest
            };

            _accounts = new List <Account>
            {
                _account1,
                _account2
            };

            _accountsDbSet = new DbSetStub <Account>(_accounts);

            _configurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <AccountMappings>();
            });

            _db.Setup(d => d.Accounts).Returns(_accountsDbSet);
            _employerCommitmentApi.Setup(c => c.GetTransferRequests(_account1.HashedId)).ReturnsAsync(_transferRequests);
            _hashingService.Setup(h => h.DecodeValue(_account1.HashedId)).Returns(_account1.Id);
            _hashingService.Setup(h => h.DecodeValue(_account2.HashedId)).Returns(_account2.Id);
            _hashingService.Setup(h => h.HashValue(_account1.Id)).Returns(_account1.HashedId);
            _hashingService.Setup(h => h.HashValue(_account2.Id)).Returns(_account2.HashedId);

            _handler = new GetTransferRequestsQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider, _employerCommitmentApi.Object, _hashingService.Object);

            _query = new GetTransferRequestsQuery
            {
                AccountId = _account1.Id
            };
        }
示例#16
0
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();

            _senderAccount1 = new Account
            {
                Id             = 111111,
                HashedId       = "ABC123",
                PublicHashedId = "321CBA",
                Name           = "Sender 1"
            };

            _senderAccount2 = new Account
            {
                Id             = 222222,
                HashedId       = "DEF456",
                PublicHashedId = "654FED",
                Name           = "Sender 2"
            };

            _receiverAccount = new Account
            {
                Id             = 333333,
                HashedId       = "GHI789",
                PublicHashedId = "987IHG",
                Name           = "Receiver"
            };

            _sentTransferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                                .WithId(111111)
                                                .WithSenderAccount(_receiverAccount)
                                                .WithReceiverAccount(new Account())
                                                .WithStatus(TransferConnectionInvitationStatus.Approved)
                                                .Build();

            _receivedTransferConnectionInvitation1 = new TransferConnectionInvitationBuilder()
                                                     .WithId(222222)
                                                     .WithSenderAccount(_senderAccount1)
                                                     .WithReceiverAccount(_receiverAccount)
                                                     .WithStatus(TransferConnectionInvitationStatus.Rejected)
                                                     .Build();

            _receivedTransferConnectionInvitation2 = new TransferConnectionInvitationBuilder()
                                                     .WithId(333333)
                                                     .WithSenderAccount(_senderAccount1)
                                                     .WithReceiverAccount(_receiverAccount)
                                                     .WithStatus(TransferConnectionInvitationStatus.Approved)
                                                     .Build();

            _receivedTransferConnectionInvitation3 = new TransferConnectionInvitationBuilder()
                                                     .WithId(444444)
                                                     .WithSenderAccount(_senderAccount2)
                                                     .WithReceiverAccount(_receiverAccount)
                                                     .WithStatus(TransferConnectionInvitationStatus.Approved)
                                                     .Build();

            _transferConnectionInvitations = new List <TransferConnectionInvitation>
            {
                _sentTransferConnectionInvitation,
                _receivedTransferConnectionInvitation3,
                _receivedTransferConnectionInvitation2,
                _receivedTransferConnectionInvitation1,
                new TransferConnectionInvitationBuilder()
                .WithSenderAccount(new Account())
                .WithReceiverAccount(new Account())
                .WithStatus(TransferConnectionInvitationStatus.Approved)
                .Build()
            };

            _transferConnectionInvitationsDbSet = new DbSetStub <TransferConnectionInvitation>(_transferConnectionInvitations);

            _configurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <TransferConnectionInvitationMappings>();
            });

            _db.Setup(d => d.TransferConnectionInvitations).Returns(_transferConnectionInvitationsDbSet);

            _handler = new GetTransferConnectionsQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider);

            _query = new GetTransferConnectionsQuery
            {
                HashedAccountId = _receiverAccount.HashedId
            };
        }