Example #1
0
        private Task MessageParserToEventsAsync(string message)
        {
            Task <bool> t1 = new TaskFactory <bool>().StartNew(() =>
            {
                var userResponseObject = FIXMLManager.ParseUserResponseMessege(message);
                if (userResponseObject != null)
                {
                    UserResponseEvent?.Invoke(userResponseObject);
                    return(true);
                }
                return(false);
            });

            Task <bool> t2 = new TaskFactory <bool>().StartNew(() =>
            {
                var rejectResponseObject = FIXMLManager.ParseBusinessMessageRejectMessage(message);
                if (rejectResponseObject != null)
                {
                    BusinessMessageRejectEvent?.Invoke(rejectResponseObject);
                    return(true);
                }
                return(false);
            });

            return(Task.WhenAll <bool>(new Task <bool>[] { t1, t2 }).ContinueWith(resultList =>
            {
                if (resultList.Result.All(x => x == false))
                {
                    UnknownMessageTypeEvent?.Invoke(message);
                }
            }));
        }
        public void Nol3BusinessMessageRejectIParsedProperlyfromResponse()
        {
            string currentID;

            //prepare config
            using (var IDGen = IdGenerator.GetIDGenerator())
            {
                currentID = IDGen.CurrentID;

                Nol3ConfigurationManager.SaveConfiguration(new Tools.Model.Nol3Configuration
                {
                    ID       = Convert.ToInt32(IDGen.ID),
                    Login    = "******",
                    Password = "******"
                });
            }
            string response;

            using (var client =
                       Nol3.SendRequestSynch(
                           new Nol3Request(
                               FIXMLManager.GenerateRequestMessage <UserRequest>(
                                   new UserRequest {
                UserRequestType = 666
            }
                                   ))))
            {
                response = Nol3.ReciveResponse(client);
            }

            var userResponseObject = FIXMLManager.ParseBusinessMessageRejectMessage(response);

            Assert.That(userResponseObject, Is.TypeOf <BusinessMessageReject>());
            Assert.That(userResponseObject.BusinessRejectReason, Is.EqualTo(BusinessRejectReason.XMLParsingError));
            Assert.That(userResponseObject.Text, Is.EqualTo("UserReqID have to be integer"));
        }