Exemplo n.º 1
0
        public void TestCreateMessageFromXML()
        {
            _logger.LogInformation("Testing CreateMessageFromXML");

            var dataFactory = new XMLDataFactory();

            XMLSupport.Models.Message message = dataFactory.MakeXMLMessage(2, "Testing", "Unit Test", "This is from Unit Testing");
            string time     = DateTime.Now.ToString();
            string location = "TestMethod5";

            _XMLClient.IsTestObject = true;
            bool result = _XMLClient.CreateMessageFromXML(message, time, location);

            if (result == true)
            {
                _logger.LogInformation("successfully ran CreateMessageFromXML");
            }
            else
            {
                _logger.LogWarning("failed to run CreateMessageFromXML");
            }


            // clean up test objects inserted
            result = _XMLClient.CleanUpTestMessages();
            if (result == true)
            {
                _logger.LogInformation("Successfully clean up test items");
            }
            else
            {
                _logger.LogWarning("Failed to clean up test items");
            }
        }
Exemplo n.º 2
0
        public void TestMethod3()
        {
            var     dataFactory = new XMLDataFactory();
            Context context     = dataFactory.MakeXMLContext();

            XMLSupport.Models.Message message = dataFactory.MakeXMLMessage(2, "Testing", "Unit Test", "This is from Unit Testing");
            context.MessageObj = message;

            string fileName = "c:\\src\\data\\context.xml";
            //var xmlServiceFactory = new xmlServiceFactory(_configuration, _logger);
            var serializer = new Serializer();

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Context));
            bool          result        = serializer.SerializeToFile(xmlSerializer, context, fileName);

            Assert.IsTrue(result, "Serialize to file successfully return");
        }
Exemplo n.º 3
0
        public void TestGetMessageXML()
        {
            _logger.LogInformation("Testing GetMessageXML");

            DateTime searchTime  = DateTime.Now;
            string   location    = "TestMessage10";
            string   newLocation = "TestMessage10New";
            string   fileName    = "c:\\src\\data\\getmessage.xml";
            string   fileName2   = "c:\\src\\data\\getmessage2.xml";


            Thread.Sleep(3000);

            var dataFactory = new XMLDataFactory();

            XMLSupport.Models.Message message = dataFactory.MakeXMLMessage(2, "Testing", "Unit Test", "This is from unit testing");
            DateTime testTime = DateTime.Now;
            string   time     = testTime.ToString();

            message.Time     = time;
            message.Location = newLocation;

            _XMLClient.IsTestObject = true;
            bool result = _XMLClient.CreateMessageFromXML(message, time, newLocation);

            if (result == true)
            {
                _logger.LogInformation("successfully ran CreateMessageFromXML");
            }
            else
            {
                _logger.LogWarning("failed to run CreateMessageFromXML");
            }

            var           serializer    = new Serializer();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(XMLSupport.Models.Message));

            XMLSupport.Models.Message messageOutput = _XMLClient.GetMessageXML(searchTime, location);
            if (messageOutput == null)
            {
                _logger.LogWarning("Message return is null");
            }
            else
            {
                _logger.LogInformation("MessageType is {messagetype} and expected {messagetype2}", messageOutput.MessageType, message.MessageType);
                _logger.LogInformation("ToName is {toname} and expected {toname2}", messageOutput.ToName, message.ToName);
                _logger.LogInformation("ToName is {fromname} and expected {fromname2}", messageOutput.FromName, message.FromName);
                _logger.LogInformation("Location is {location} and expected {location2}", messageOutput.Location, message.Location);

                result = serializer.SerializeToFile(xmlSerializer, messageOutput, fileName);
                if (result == true)
                {
                    _logger.LogInformation("successfully serialize message output to file");
                }
                else
                {
                    _logger.LogWarning("failed to serialize message output to file");
                }
            }

            // now search for same time as message receieve above
            searchTime    = testTime;
            messageOutput = _XMLClient.GetMessageXML(searchTime, location);
            if (messageOutput == null)
            {
                _logger.LogInformation("Message is null and success from GetMessageXML");
            }
            else
            {
                _logger.LogWarning("MessageType is {messagetype} and got {messagetype2}", messageOutput.MessageType, message.MessageType);
                _logger.LogInformation("ToName is {toname} and got {toname2}", messageOutput.ToName, message.ToName);
                _logger.LogInformation("ToName is {fromname} and got {fromname2}", messageOutput.FromName, message.FromName);
                _logger.LogWarning("Location is {location} and got {location2}", messageOutput.Location, message.Location);

                result = serializer.SerializeToFile(xmlSerializer, messageOutput, fileName2);
                if (result == true)
                {
                    _logger.LogInformation("successfully serialize message output to file");
                }
                else
                {
                    _logger.LogWarning("failed to serialize message output to file");
                }
            }

            // clean up test objects inserted
            result = _XMLClient.CleanUpTestMessages();
            if (result == true)
            {
                _logger.LogInformation("Successfully clean up test items");
            }
            else
            {
                _logger.LogWarning("Failed to clean up test items");
            }
        }