Exemplo n.º 1
0
        /// <summary>
        /// Default construct which initializes the report.
        /// </summary>
        public TestSuiteState()
        {
            IDictionary <string, MessageTestState> messageTestStates = new Dictionary <string, MessageTestState>();

            foreach (ReferenceMessage referenceMessage in ReferenceMessageLoader.Current.ReferenceMessages.Values)
            {
                MessageTestState item = new MessageTestState();
                item.MessageName      = referenceMessage.MessageName;
                item.MessageFileName  = referenceMessage.MessageFileName;
                item.ReferenceMessage = referenceMessage.MessageValue;
                item.ReferenceString  = referenceMessage.StringValue;
                item.ReferenceBytes   = referenceMessage.ByteValue;
                messageTestStates.Add(item.MessageFileName, item);
            }

            MessageTestStates = messageTestStates;

            TestStates = new Dictionary <TestCategory, IDictionary <TestKey, TestState> >();
            TestStates.Add(TestCategory.MessageSerialization, new Dictionary <TestKey, TestState>());
            TestStates.Add(TestCategory.CandidateClientToReferenceServer, new Dictionary <TestKey, TestState>());
            TestStates.Add(TestCategory.ReferenceClientToCandidateServer, new Dictionary <TestKey, TestState>());
            TestStates.Add(TestCategory.CandidateServerToReferenceServer, new Dictionary <TestKey, TestState>());
            TestStates.Add(TestCategory.ReferenceServerToCandidateServer, new Dictionary <TestKey, TestState>());

            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.Connection);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.ObjectInjection);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.ObjectExamination);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.ObjectModification);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.ObjectInteraction);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.ObjectEjection);
            InitializeTestState(TestCategory.CandidateClientToReferenceServer, TestKey.Disconnection);
        }
        protected void VerifyButton_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                using (ZipFile zipFile = ZipFile.Read(FileUpload1.FileBytes))
                {
                    foreach (ZipEntry entry in zipFile.Entries)
                    {
                        string fileName = entry.FileName;
                        if (fileName.IndexOf('/') > -1)
                        {
                            fileName = fileName.Substring(fileName.LastIndexOf('/') + 1);
                        }

                        if (!IotContext.TestSuiteState.MessageTestStates.ContainsKey(fileName))
                        {
                            continue;
                        }

                        MessageTestState messageTestState = IotContext.TestSuiteState.MessageTestStates[fileName];

                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            entry.Extract(memoryStream);
                            byte[] sourceBytes = memoryStream.GetBuffer();
                            byte[] targetBytes = new byte[memoryStream.Length];
                            for (int i = 0; i < targetBytes.Length; i++)
                            {
                                targetBytes[i] = sourceBytes[i];
                            }
                            messageTestState.CandidateBytes    = targetBytes;
                            messageTestState.DifferenceIndexes = CompareUtil.FindFirstDifference(messageTestState.ReferenceBytes, messageTestState.CandidateBytes);
                            messageTestState.Result            = messageTestState.DifferenceIndexes.Count == 0;
                        }
                    }
                }
            }
        }