public void SerializeTest()
        {
            var ass1 = new Asset
            {
                Quantity     = 1,
                RelatedStock = new Stock("GOOGL", "GOOGLE")
            };
            var assets = new Dictionary <string, Asset>
            {
                { ass1.RelatedStock.Symbol, ass1 }
            };

            var updateMessage = new PortfolioUpdateMessage
            {
                Assets         = assets,
                PortfolioID    = 1,
                WriteAuthority = true
            };

            var serializedMessage = MessageFactory.GetMessage(updateMessage.Encode(), false) as PortfolioUpdateMessage;

            Assert.AreEqual(updateMessage.PortfolioID, serializedMessage.PortfolioID);
            Assert.AreEqual(updateMessage.WriteAuthority, serializedMessage.WriteAuthority);
            Assert.AreEqual(updateMessage.Assets.Count, serializedMessage.Assets.Count);
            Assert.AreEqual(updateMessage.Assets.ContainsKey("GOOGL"), serializedMessage.Assets.ContainsKey("GOOGL"));
            Assert.AreEqual(updateMessage.Assets["GOOGL"].Quantity, serializedMessage.Assets["GOOGL"].Quantity);
            Assert.AreEqual(updateMessage.Assets["GOOGL"].RelatedStock.Name, serializedMessage.Assets["GOOGL"].RelatedStock.Name);
        }
        public void DefaultConstructorTest()
        {
            var updateMessage = new PortfolioUpdateMessage();

            Assert.AreEqual(updateMessage.PortfolioID, 0);
            Assert.IsFalse(updateMessage.WriteAuthority);
            Assert.AreEqual(updateMessage.Assets.Count, 0);
        }
Exemple #3
0
        public void RequestSingleTimeoutThenSucceed()
        {
            int portfolioId = 42;
            var testStock   = new Stock("TST", "Test Stock");
            var vStock      = new ValuatedStock(("1984-02-22,11.0289,11.0822,10.7222,10.7222,197402").Split(','), testStock);

            var conv     = new InitiateTransactionConversation(portfolioId);
            int requests = 0;

            //setup response message and mock
            var mock = new Mock <InitTransactionStartingState>(conv, vStock, 1)
            {
                CallBase = true
            };

            mock.Setup(prep => prep.Prepare()).Verifiable();                           //ensure DoPrepare is called.
            mock.Setup(st => st.OnHandleMessage(It.IsAny <Envelope>(), 0)).CallBase(); //Skip mock's HandleMessage override.
            mock.Setup(st => st.Send())                                                //Pretend message is sent and response comes back...
            .Callback(() => {
                if (++requests > 1)
                {
                    var responseMessage = new PortfolioUpdateMessage()
                    {
                        ConversationID = conv.Id
                    };
                    var responseEnv = new Envelope(responseMessage);
                    ConversationManager.ProcessIncomingMessage(responseEnv);
                }
            }).CallBase().Verifiable();

            //execute test
            conv.SetInitialState(mock.Object as InitTransactionStartingState);

            Assert.IsTrue(conv.CurrentState is InitTransactionStartingState);
            mock.Verify(state => state.Prepare(), Times.Never);
            mock.Verify(state => state.Send(), Times.Never);

            ConversationManager.AddConversation(conv);

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

            Thread.Sleep((int)(Config.GetInt(Config.DEFAULT_TIMEOUT) * 1.5));

            Assert.IsFalse(conv.CurrentState is InitTransactionStartingState);
            Assert.IsTrue(conv.CurrentState is ConversationDoneState);
            mock.Verify(state => state.Prepare(), Times.Once);
            mock.Verify(state => state.Send(), Times.AtLeast(2));
            mock.Verify(state => state.HandleTimeout(), Times.AtLeast(1));
        }
        public void AssetConstructorTest()
        {
            var ass1 = new Asset
            {
                Quantity     = 1,
                RelatedStock = new Stock("GOOGL", "GOOGLE")
            };
            var assets = new Dictionary <string, Asset>
            {
                { ass1.RelatedStock.Symbol, ass1 }
            };

            var updateMessage = new PortfolioUpdateMessage(assets);

            Assert.AreEqual(updateMessage.PortfolioID, 0);
            Assert.IsFalse(updateMessage.WriteAuthority);
            Assert.AreEqual(updateMessage.Assets.Count, 1);
        }
Exemple #5
0
        public void RequestSucceed()
        {
            int processIdId = 42;
            var username    = "******";
            var password    = "******";

            var conv = new CreatePortfolioRequestConversation(processIdId);

            //setup response message and mock
            var mock = new Mock <CreatePortfolioRequestState>(username, password, password, null, conv, null)
            {
                CallBase = true
            };

            mock.Setup(st => st.Send())//Pretend message is sent and response comes back...
            .Callback(() => {
                var responseMessage = new PortfolioUpdateMessage()
                {
                    ConversationID = conv.Id, MessageID = "responseMessageID1234"
                };
                var responseEnv = new Envelope(responseMessage);
                ConversationManager.ProcessIncomingMessage(responseEnv);
            }).CallBase().Verifiable();

            //execute test
            conv.SetInitialState(mock.Object as CreatePortfolioRequestState);

            Assert.IsTrue(conv.CurrentState is CreatePortfolioRequestState);
            mock.Verify(state => state.Prepare(), Times.Never);
            mock.Verify(state => state.Send(), Times.Never);

            ConversationManager.AddConversation(conv);

            Assert.IsFalse(conv.CurrentState is CreatePortfolioRequestState);
            Assert.IsTrue(conv.CurrentState is ConversationDoneState);
            mock.Verify(state => state.Prepare(), Times.Once);
            mock.Verify(state => state.Send(), Times.Once);
        }
Exemple #6
0
        public void RequestSucceed()
        {
            int portfolioId = 42;
            var testStock   = new Stock("TST", "Test Stock");
            var vStock      = new ValuatedStock(("1984-02-22,11.0289,11.0822,10.7222,10.7222,197402").Split(','), testStock);

            var conv = new InitiateTransactionConversation(portfolioId);

            //setup response message and mock
            var mock = new Mock <InitTransactionStartingState>(conv, vStock, 1)
            {
                CallBase = true
            };

            mock.Setup(st => st.Send())//Pretend message is sent and response comes back...
            .Callback(() => {
                var responseMessage = new PortfolioUpdateMessage()
                {
                    ConversationID = conv.Id, MessageID = "responseMessageID1234"
                };
                var responseEnv = new Envelope(responseMessage);
                ConversationManager.ProcessIncomingMessage(responseEnv);
            }).CallBase().Verifiable();

            //execute test
            conv.SetInitialState(mock.Object as InitTransactionStartingState);

            Assert.IsTrue(conv.CurrentState is InitTransactionStartingState);
            mock.Verify(state => state.Prepare(), Times.Never);
            mock.Verify(state => state.Send(), Times.Never);

            ConversationManager.AddConversation(conv);

            Assert.IsFalse(conv.CurrentState is InitTransactionStartingState);
            Assert.IsTrue(conv.CurrentState is ConversationDoneState);
            mock.Verify(state => state.Prepare(), Times.Once);
            mock.Verify(state => state.Send(), Times.Once);
        }
        public void InitializeTest()
        {
            var ass1 = new Asset
            {
                Quantity     = 1,
                RelatedStock = new Stock("GOOGL", "GOOGLE")
            };
            var assets = new Dictionary <string, Asset>
            {
                { ass1.RelatedStock.Symbol, ass1 }
            };

            var updateMessage = new PortfolioUpdateMessage
            {
                Assets         = assets,
                PortfolioID    = 1,
                WriteAuthority = true
            };

            Assert.AreEqual(updateMessage.PortfolioID, 1);
            Assert.IsTrue(updateMessage.WriteAuthority);
            Assert.AreEqual(updateMessage.Assets.Count, 1);
        }