public void Save_Stores_ProtocolLines_In_The_File()
        {
            string projectName = "projectName";
            string protocolName = "protocolName";

            OpcMockProtocol omp = new OpcMockProtocol(protocolName);
            string ompLine1 = "Set;tagPath1;tagValue1;192";
            string ompLine2 = "Set;tagPath2;tagValue2;192";
            omp.Append(new ProtocolLine(ompLine1));
            omp.Append(new ProtocolLine(ompLine2));

            string protocolFilePath = TestContext.TestDeploymentDir + Path.DirectorySeparatorChar + protocolName + FileExtensionContants.FileExtensionProtocol;

            ProtocolWriter protocolWriter = new ProtocolWriter(TestContext.TestDeploymentDir, projectName);

            protocolWriter.Save(omp);

            string expectedFileContent = ompLine1 + Environment.NewLine + ompLine2 + Environment.NewLine;

            string actualFileContent = File.ReadAllText(protocolFilePath);

            Assert.AreEqual(expectedFileContent, actualFileContent);

            File.Delete(protocolFilePath);
        }
        public void AddProtocolShould_Raise_DuplicateProtocolNameException_On_Duplicate_ProtocolName()
        {
            OpcMockProtocol protocolToAdd = new OpcMockProtocol(PROTOCOL_NAME);

            opcMockProject.AddProtocol(protocolToAdd);
            opcMockProject.AddProtocol(protocolToAdd);
        }
        public void AddProtocolShould_Add_A_Protocol_To_The_End_Of_The_List()
        {
            OpcMockProtocol protocolToAdd = new OpcMockProtocol(PROTOCOL_NAME);

            opcMockProject.AddProtocol(protocolToAdd);

            Assert.AreEqual(protocolToAdd, opcMockProject.Protocols[0]);
        }
        private void btnCreateProtocol_Click(object sender, EventArgs e)
        {
            OpcMockProtocol = new OpcMockProtocol(tbProtocolName.Text);

            this.DialogResult = DialogResult.OK;

            this.Hide();
        }
        private void btnCreateProtocol_Click(object sender, EventArgs e)
        {
            OpcMockProtocol = new OpcMockProtocol(tbProtocolName.Text);

            this.DialogResult = DialogResult.OK;

            this.Hide();
        }
        public void ProtocolsWithTheSameNameShould_Be_Equal()
        {
            ProtocolComparer pc = new ProtocolComparer();

            OpcMockProtocol omp1 = new OpcMockProtocol("omp1");
            OpcMockProtocol compare1 = new OpcMockProtocol("omp1");

            Assert.AreEqual(EQUALITY, pc.Compare(omp1, compare1));
        }
示例#7
0
        public void Adding_A_Line_Raises_LineAdded_Event()
        {
            bool eventRaised = false;

            OpcMockProtocol protocol = new OpcMockProtocol(PROTOCOL_NAME);

            protocol.OnProtocolLineAdded += delegate (object sender, ProtocolLineAddedArgs plaArgs) { eventRaised = true; };

            protocol.Append(new ProtocolLine("Set;tagPath;tagValue;192"));

            Assert.IsTrue(eventRaised);
        }
示例#8
0
        public void Append_For_StringArray_Appends_All_Lines()
        {
            OpcMockProtocol protocol = new OpcMockProtocol(PROTOCOL_NAME);

            string[] testArray = new string[] { "Set; tagPath1; tagValue; 192", "Set;tagPath2;tagValue;192", "Set;tagPath3;tagValue;192" };

            protocol.Append(testArray);

            Assert.AreEqual(new ProtocolLine("Set;tagPath1;tagValue;192"), protocol.Lines[0]);
            Assert.AreEqual(new ProtocolLine("Set;tagPath2;tagValue;192"), protocol.Lines[1]);
            Assert.AreEqual(new ProtocolLine("Set;tagPath3;tagValue;192"), protocol.Lines[2]);
        }
示例#9
0
        public void Add_Line_Appends_A_Line_At_The_End()
        {
            OpcMockProtocol omp = new OpcMockProtocol(PROTOCOL_NAME);

            string line1 = "Set;tagPath1;tagValue1;192";
            string lineEqualToLine1 = "Set;tagPath2;tagValue2;192";

            omp.Append(new ProtocolLine(line1));
            omp.Append(new ProtocolLine(lineEqualToLine1));

            ///PROPOSAL expose IEnumberable instead of List
            Assert.AreEqual(new ProtocolLine(lineEqualToLine1), omp.Lines[1]);
        }
示例#10
0
        /// <summary>
        /// Add a protocol to the project
        /// </summary>
        /// <param name="protocolToAdd"></param>
        /// <exception cref="OpcMock.DuplicateProtocolNameException">In case the project already contains a protocol with this name</exception>
        public void AddProtocol(OpcMockProtocol protocolToAdd)
        {
            if (Protocols.Contains(protocolToAdd))
            {
                throw new DuplicateProtocolNameException("Project already contains a protocol with this name.", protocolToAdd.Name);
            }

            Protocols.Add(protocolToAdd);

            if (null != OnProtocolAdded)
            {
                OnProtocolAdded(this, new ProtocolAddedArgs(protocolToAdd));
            }
        }
示例#11
0
        /// <summary>
        /// Add a protocol to the project
        /// </summary>
        /// <param name="protocolToAdd"></param>
        /// <exception cref="OpcMock.DuplicateProtocolNameException">In case the project already contains a protocol with this name</exception>
        public void AddProtocol(OpcMockProtocol protocolToAdd)
        {
            if (Protocols.Contains(protocolToAdd))
            {
                throw new DuplicateProtocolNameException("Project already contains a protocol with this name.", protocolToAdd.Name);
            }

            Protocols.Add(protocolToAdd);

            if (null != OnProtocolAdded)
            {
                OnProtocolAdded(this, new ProtocolAddedArgs(protocolToAdd));
            }
        }
示例#12
0
        public void Save(OpcMockProtocol opcMockProtocol)
        {
            string protocolFilePath = FolderPath + Path.DirectorySeparatorChar + opcMockProtocol.Name + FileExtensionContants.FileExtensionProtocol;

            File.Create(protocolFilePath).Close();

            StringBuilder fileContentBuilder = new StringBuilder();

            foreach (ProtocolLine pl in opcMockProtocol.Lines)
            {
                fileContentBuilder.Append(pl.ToString() + Environment.NewLine);
            }

            File.WriteAllText(protocolFilePath, fileContentBuilder.ToString());
        }
示例#13
0
        public void Save(OpcMockProtocol opcMockProtocol)
        {
            string protocolFilePath = FolderPath + Path.DirectorySeparatorChar + opcMockProtocol.Name + FileExtensionContants.FileExtensionProtocol;

            File.Create(protocolFilePath).Close();

            StringBuilder fileContentBuilder = new StringBuilder();

            foreach (ProtocolLine pl in opcMockProtocol.Lines)
            {
                fileContentBuilder.Append(pl.ToString() + Environment.NewLine);
            }

            File.WriteAllText(protocolFilePath, fileContentBuilder.ToString());
        }
示例#14
0
        public void Save_Creates_A_Protocol_File_In_The_FolderPath()
        {
            string projectName = "projectName";
            string protocolName = "protocolName";

            OpcMockProtocol opcMockProtocol = new OpcMockProtocol(protocolName);

            ProtocolWriter protocolWriter = new ProtocolWriter(TestContext.TestDeploymentDir, projectName);

            protocolWriter.Save(opcMockProtocol);

            string protocolFilePath = TestContext.TestDeploymentDir + Path.DirectorySeparatorChar + protocolName + FileExtensionContants.FileExtensionProtocol;

            Assert.IsTrue(File.Exists(protocolFilePath));

            File.Delete(protocolFilePath);
        }
示例#15
0
        public void AddProtocolShould_Not_Raise_OnProtocolAdded_Event_For_Duplicates()
        {
            bool eventRaised = false;

            try
            {
                OpcMockProtocol protocolToAdd = new OpcMockProtocol(PROTOCOL_NAME);

                opcMockProject.AddProtocol(protocolToAdd);

                //Add the handler only after the first addition otherwise eventRaised
                //is wrongly set to true
                opcMockProject.OnProtocolAdded += delegate (object sender, ProtocolAddedArgs paArgs) { eventRaised = true; };

                opcMockProject.AddProtocol(protocolToAdd);
            }
            catch (DuplicateProtocolNameException)
            {
                Assert.IsFalse(eventRaised);
            }
        }
示例#16
0
        private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (cbProtocols.SelectedIndex > 0)
            {
                ProtocolWriter protocolWriter = new ProtocolWriter(GetProjectFolderPath(), opcMockProject.Name);

                OpcMockProtocol currentProtocol = new OpcMockProtocol(cbProtocols.SelectedText);

                foreach (string line in tbProtocol.Lines)
                {
                    try
                    {
                        currentProtocol.Append(new ProtocolLine(line));
                    }
                    catch (ArgumentException)
                    {
                        //End of protocol reached
                    }
                }

                protocolWriter.Save(currentProtocol);
            }
        }
示例#17
0
 public void OpcMockProtocolConstructor_Should_Raise_ArgumentException_For_BlanksOnly_Name()
 {
     OpcMockProtocol omp = new OpcMockProtocol("    ");
 }
示例#18
0
        public void New_Protocol_Is_Created_With_A_Name()
        {
            OpcMockProtocol omp = new OpcMockProtocol(PROTOCOL_NAME);

            Assert.AreEqual(PROTOCOL_NAME, omp.Name);
        }
示例#19
0
        public void New_Protocol_Has_No_Lines()
        {
            OpcMockProtocol omp = new OpcMockProtocol(PROTOCOL_NAME);

            Assert.AreEqual(NEW_PROTOCOL_LINE_COUNT, omp.Lines.Count);
        }
示例#20
0
 public void Empty_Or_SpacesOnly_Name_Raises_ArgumentException()
 {
     OpcMockProtocol omp = new OpcMockProtocol(string.Empty);
 }
示例#21
0
 public ProtocolAddedArgs(OpcMockProtocol opcMockProtocol)
 {
     OpcMockProtocol = opcMockProtocol;
 }
示例#22
0
        public void ToString_Return_Name()
        {
            OpcMockProtocol omp = new OpcMockProtocol(PROTOCOL_NAME);

            Assert.AreEqual(PROTOCOL_NAME, omp.ToString());
        }
示例#23
0
        private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (cbProtocols.SelectedIndex > 0)
            {
                ProtocolWriter protocolWriter = new ProtocolWriter(GetProjectFolderPath(), opcMockProject.Name);

                OpcMockProtocol currentProtocol = new OpcMockProtocol(cbProtocols.SelectedText);

                foreach (string line in tbProtocol.Lines)
                {
                    try
                    {
                        currentProtocol.Append(new ProtocolLine(line));
                    }
                    catch (ArgumentException)
                    {
                        //End of protocol reached
                    }
                }

                protocolWriter.Save(currentProtocol);
            }
        }
示例#24
0
 public ProtocolAddedArgs(OpcMockProtocol opcMockProtocol)
 {
     OpcMockProtocol = opcMockProtocol;
 }