Beispiel #1
0
 protected override void Given()
 {
     _request = new GetPortfolioRequest()
     {
         Id = _portfolioId
     };
 }
        public void SerilaizeTest()
        {
            var assets = new Dictionary <string, Asset>
            {
                { "CASH", new Asset() }
            };

            var acc = new Shared.PortfolioResources.Portfolio
            {
                Assets         = assets,
                Username       = "******",
                Password       = "******",
                WriteAuthority = true,
                PortfolioID    = 1
            };

            var m = new GetPortfolioRequest
            {
                Account = acc,
            };

            var serializedMessage = MessageFactory.GetMessage(m.Encode(), false) as GetPortfolioRequest;

            Assert.IsNotNull(serializedMessage);
            Assert.AreEqual(serializedMessage.Account.Assets.Count, 1);
            Assert.AreEqual(serializedMessage.Account.Password, "yolo");
            Assert.AreEqual(serializedMessage.Account.Username, "foohooboo");
            Assert.AreEqual(serializedMessage.Account.PortfolioID, 1);
            Assert.IsTrue(serializedMessage.Account.WriteAuthority);
        }
        public void InheritsMessageTest()
        {
            var newGetPortfolioRequest = new GetPortfolioRequest();

            Assert.AreEqual(0, newGetPortfolioRequest.SourceID);
            Assert.IsNull(newGetPortfolioRequest.ConversationID);
            Assert.IsNull(newGetPortfolioRequest.MessageID);
        }
        public void InitializeTest()
        {
            var acc = new Shared.PortfolioResources.Portfolio();

            var m = new GetPortfolioRequest
            {
                Account = acc
            };

            Assert.AreEqual(m.Account.Assets.Count, 0);
            Assert.IsNull(m.Account.Password);
        }
Beispiel #5
0
        public void RequestSucceed()
        {
            string PortName      = "IamAUsername";
            string PortPass      = "******";
            string RequestConvId = "5-567";
            string ClientIp      = "192.168.1.75";
            int    ClientPort    = 5655;

            PortfolioManager.TryToCreate(PortName, PortPass, out Portfolio preExistingPortfolio);

            var RequestMessage = new GetPortfolioRequest()
            {
                ConversationID = RequestConvId,
                MessageID      = RequestConvId,
                Account        = new Portfolio
                {
                    Username = PortName,
                    Password = PortPass
                }
            };

            Envelope IncomingRequest = new Envelope(RequestMessage, ClientIp, ClientPort);

            var localConv = ConversationManager.GetConversation(RequestConvId);

            Assert.IsNull(localConv);
            Assert.IsNull(mock);

            Assert.IsTrue(PortfolioManager.Portfolios.Count == 1);

            ConversationManager.ProcessIncomingMessage(IncomingRequest);

            localConv = ConversationManager.GetConversation(RequestConvId);
            Assert.IsNotNull(localConv.CurrentState.PreviousState.OutboundMessage.Contents as PortfolioUpdateMessage);
            Assert.IsNull(localConv.CurrentState.PreviousState.OutboundMessage.Contents as ErrorMessage);


            Assert.IsNotNull(localConv);

            Assert.IsTrue(localConv.CurrentState is ConversationDoneState);
            mock.Verify(state => state.Prepare(), Times.Once);
            mock.Verify(state => state.Send(), Times.Once);
            mock.Verify(state => state.HandleTimeout(), Times.Never);

            Assert.IsTrue(PortfolioManager.TryToRemove(preExistingPortfolio.PortfolioID));
        }
Beispiel #6
0
        static async Task Main()
        {
            var channel    = GrpcChannel.ForAddress(ServerAddress);
            var portfolios = channel.CreateGrpcService <IPortfolioService>();

            try
            {
                var request = new GetPortfolioRequest
                {
                    TraderId    = Guid.Parse("68CB16F7-42BD-4330-A191-FA5904D2E5A0"),
                    PortfolioId = 42
                };
                var response = await portfolios.Get(request);

                Console.WriteLine($"Portfolio contains {response.Items.Count} items.");
            }
            catch (RpcException e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Beispiel #7
0
        private static Conversation HandleGetPortfolio(Envelope e)
        {
            Conversation conv = null;

            GetPortfolioRequest m = e.Contents as GetPortfolioRequest;

            var user = m.Account.Username;
            var pass = m.Account.Password;

            if (PortfolioManager.TryToGet(user, pass, out Portfolio portfolio))
            {
                conv = new GetPortfoliolResponseConversation(m.ConversationID);
                conv.SetInitialState(new GetPortfolioReceiveState(e, conv));
            }
            else
            {
                conv = new SendErrorMessageConversation(m.ConversationID);
                conv.SetInitialState(new SendErrorMessageState("Invalid login credentials.", e, conv, null, Config.GetInt(Config.BROKER_PROCESS_NUM)));
            }

            return(conv);
        }
Beispiel #8
0
        public async Task <Portfolio> Get(GetPortfolioRequest request)
        {
            var portfolio = await _repository.GetAsync(request.TraderId, request.PortfolioId);

            return(portfolio);
        }
        public void DefaultConstructorTest()
        {
            var newGetPortfolioRequest = new GetPortfolioRequest();

            Assert.IsNull(newGetPortfolioRequest.Account);
        }