public void TestSetup()
        {
            Localizer.ResourceResolver = new MockResourceResolver();
            mainFormDebug   = new MainForm(true);
            fakeTradeServer = ProxyBuilder.Instance.GetImplementer <ITradeSharpServerTrade>();

            int currentSessionTag;

            methodAuthenticate  = ProxyBuilder.GetMethodName <ITradeSharpServerTrade>(a => a.Authenticate("", "", "", 0, 0, out currentSessionTag));
            methodSelectAccount = ProxyBuilder.GetMethodName <ITradeSharpServerTrade>(a => a.SelectAccount(null, 0));

            TradeSharpServerTradeProxy.fakeProxy = fakeTradeServer;
        }
Exemplo n.º 2
0
        public void Setup()
        {
            NewsMaker.ClearNewsFolder();

            fakeTradeServer  = ProxyBuilder.Instance.GetImplementer <ITradeSharpServerTrade>();
            fakeTradeAccount = ProxyBuilder.Instance.GetImplementer <ITradeSharpAccount>();

            Account ac;
            var     methodName = ProxyBuilder.GetMethodName <ITradeSharpAccount>(a => a.GetAccountInfo(1, false, out ac));

            ((IMockableProxy)fakeTradeAccount).MockMethods.Add(methodName,
                                                               new GetAccountInfoDel((int accountId, bool needEquityInfo, out Account account) =>
            {
                account = accounts.FirstOrDefault(a => a.ID == accountId);
                return(RequestStatus.OK);
            }));

            TradeSharpServerTradeProxy.fakeProxy = fakeTradeServer;
        }
        public void TestSetup()
        {
            #region Запоминиаем имена методов, которые будем мОчить разными реализациями в ходе тестов
            List <MarketOrder>   voidOrdersList;
            List <BalanceChange> voidBalanceChangesList;
            getHistoryOrdersName  = ProxyBuilder.GetMethodName <ITradeSharpAccount>(a => a.GetHistoryOrders(null, null, out voidOrdersList));
            getMarketOrdersName   = ProxyBuilder.GetMethodName <ITradeSharpAccount>(a => a.GetMarketOrders(0, out voidOrdersList));
            getBalanceChangesName = ProxyBuilder.GetMethodName <ITradeSharpAccount>(a => a.GetBalanceChanges(0, null, out voidBalanceChangesList));
            #endregion


            fakeTradeAccount = ProxyBuilder.Instance.GetImplementer <ITradeSharpAccount>();
            TradeSharpAccount.Initialize(fakeTradeAccount);

            // Инициализируем словарь котировок
            dailyQuoteStorage = new DailyQuoteStorage();
            dailyQuoteStorage.InitializeFake(QuoteMaker.MakeQuotesForQuoteDailyStorage(null));

            SetupMockMethodImplementation();
        }
Exemplo n.º 4
0
        private void MakeMoq()
        {
            serverCats = new List <Contract.Entity.Subscription>
            {
                new Contract.Entity.Subscription
                {
                    Service     = 1,
                    PaidService = new PaidService
                    {
                        Comment = "Test signals",
                    },
                    AutoTradeSettings = new AutoTradeSettings
                    {
                        PercentLeverage = 50,
                        MaxLeverage     = 10,
                        MinVolume       = 10000,
                        StepVolume      = 5000,
                        TradeAuto       = true,
                    }
                }
            };

            fakeTradeServer  = ProxyBuilder.Instance.GetImplementer <ITradeSharpServerTrade>();
            fakeTradeAccount = ProxyBuilder.Instance.GetImplementer <ITradeSharpAccount>();


            WalletError walletError;
            var         bindToTradeSignal = ProxyBuilder.GetMethodName <ITradeSharpServerTrade>(a => a.SubscribeOnService(
                                                                                                    null, "", 0, false, false, null, out walletError));

            ((IMockableProxy)fakeTradeServer).MockMethods.Add(bindToTradeSignal,
                                                              new GetAccountInfoDel((ProtectedOperationContext secCtx, string userLogin, int serviceId, bool renewAuto,
                                                                                     bool unsb, AutoTradeSettings sets, out WalletError error) =>
            {
                error = WalletError.OK;
                // модифицировать подписки
                var indexExists = serverCats.FindIndex(c => c.Service == serviceId);
                if (indexExists >= 0)
                {
                    if (unsb)
                    {
                        serverCats.RemoveAt(indexExists);
                    }
                    else
                    {
                        var subs = new Contract.Entity.Subscription
                        {
                            Service           = serviceId,
                            AutoTradeSettings = sets,
                            RenewAuto         = renewAuto,
                            PaidService       = new PaidService
                            {
                                Id = serviceId
                            }
                        };
                        serverCats[indexExists] = subs;
                        serverCats.Add(subs);
                    }
                    return(true);
                }

                return(true);
            }));


            var getTradeSignalsSubscribed = ProxyBuilder.GetMethodName <ITradeSharpAccount>(a => a.GetSubscriptions(""));

            ((IMockableProxy)fakeTradeAccount).MockMethods.Add(getTradeSignalsSubscribed, new Func <string, List <Contract.Entity.Subscription> >(userLogin =>
            {
                return(userLogin == "Demo"
                   ? serverCats
                   : new List <Contract.Entity.Subscription>());
            }));
        }
        public void Setup()
        {
            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            // заглушки для диалогов - выбора пользователей
            UserServiceRegistrator.DialogBoxProvider = new TestDialogBoxProvider();

            // серверный (торговый) прокси
            fakeTradeServer = ProxyBuilder.Instance.GetImplementer <ITradeSharpServerTrade>();
            List <Account> accounts;
            var            getUserOwnedAccountsWithActualBalanceMethodName =
                ProxyBuilder.GetMethodName <ITradeSharpServerTrade>(a => a.GetUserOwnedAccountsWithActualBalance("",
                                                                                                                 null, false, out accounts));

            ((IMockableProxy)fakeTradeServer).MockMethods.Add(getUserOwnedAccountsWithActualBalanceMethodName,
                                                              new GetUserOwnedAccountsWithActualBalanceDel((string login, ProtectedOperationContext secCtx, bool realOnly,
                                                                                                            out List <Account> acts) =>
            {
                acts = new List <Account>
                {
                    new Account
                    {
                        Balance  = 12000,
                        Currency = "USD",
                        ID       = 51,
                        Group    = "Real"
                    },
                    new Account
                    {
                        Balance  = 2000,
                        Currency = "USD",
                        ID       = 52,
                        Group    = "Real"
                    }
                };
                return(AuthenticationResponse.OK);
            }));
            MainForm.serverProxyTrade = new TradeSharpServerTrade(fakeTradeServer);

            // кошельковый прокси
            fakeWalletManager = ProxyBuilder.Instance.GetImplementer <IWalletManager>();
            ((IMockableProxy)fakeWalletManager).MockMethods.Add(StronglyName.GetMethodName <IWalletManager>(
                                                                    w => w.GetUserWallet(null, null)),
                                                                new Func <ProtectedOperationContext, string, Wallet>(
                                                                    (context, s) => new Wallet
            {
                Balance  = 1005,
                Currency = "USD",
                User     = 50
            }));
            WalletError walletError;
            var         registerOrUpdateServiceMethodName =
                ProxyBuilder.GetMethodName <IWalletManager>(w => w.RegisterOrUpdateService(
                                                                null, null, out walletError));

            ((IMockableProxy)fakeWalletManager).MockMethods.Add(registerOrUpdateServiceMethodName,
                                                                new RegisterOrUpdateServiceDel(
                                                                    (ProtectedOperationContext ctx, PaidService service,
                                                                     out WalletError error) =>
            {
                error = WalletError.OK;
                return(true);
            }));
            TradeSharpWalletManager.Initialize(fakeWalletManager);
        }