public void RetrieveMessageFromAnotherPersonQueue() { anotherPersonQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(AnotherPerson) }); Message[] messages = anotherPersonQueue.GetAllMessages(); StringBuilder builder = new StringBuilder(); var isOK = messages.Count() > 0 ? true : false; foreach (Message m in messages) { try { AnotherPerson person = new AnotherPerson(); var command = (AnotherPerson)m.Body; person.Name = command.Name; person.Age = command.Age; builder.Append(person.ToString() + "\n"); } catch (MessageQueueException ex) { } } messageTextBlock.Text += builder.ToString(); }
public void CreateMessage() { MessageQueue messageQueue = null; if (MessageQueue.Exists(@".\Private$\PersonQueue")) { messageQueue = new MessageQueue(@".\Private$\PersonQueue"); messageQueue.Label = "Person Queue"; } else { // Create the Queue MessageQueue.Create(@".\Private$\PersonQueue"); messageQueue = new MessageQueue(@".\Private$\PersonQueue"); messageQueue.Label = "Person Queue"; } if (MessageQueue.Exists(@".\Private$\AnotherPersonQueue")) { messageQueue = new MessageQueue(@".\Private$\AnotherPersonQueue"); messageQueue.Label = "AnotherPerson Queue"; } else { // Create the Queue MessageQueue.Create(@".\Private$\AnotherPersonQueue"); messageQueue = new MessageQueue(@".\Private$\AnotherPersonQueue"); messageQueue.Label = "AnotherPerson Queue"; } if (checkboxPerson.IsChecked == true) { messageQueue = new MessageQueue(@".\Private$\PersonQueue"); Person person = new Person(); person.FirstName = personFirstNameTxt.Text; person.LastName = personLastNameTxt.Text; person.Age = int.Parse(personAgeTxt.Text); messageQueue.Send(person); } else { messageQueue = new MessageQueue(@".\Private$\AnotherPersonQueue"); AnotherPerson person = new AnotherPerson(); person.Name = personFirstNameTxt.Text + " " + personLastNameTxt.Text; person.Age = int.Parse(personAgeTxt.Text); messageQueue.Send(person); } }
public void ReturnRightString_WhenChangeAnotherPerson() { var expectedResult = new StringBuilder(); expectedResult.Append("AnotherPerson\r\n\tAge = 13%\r\n\tParents = {\r\nPerson\r\n\t\t\tId = "); expectedResult.Append($"{Person.Id}\r\n\t\t\tName = Alex\r\n\t\t\tHeight = {Person.Height}"); expectedResult.Append("\r\n\t\t\tAge = 19\r\n\t\t\tParents = empty\r\n\t}\r\n"); var person = new AnotherPerson { Name = "Nikita", Age = 13, Parents = { Person } }; var printer = ObjectPrinter.For <AnotherPerson>() .Exclude(x => x.Name) .Printing <int>().Using(x => x + "%") .Exclude(typeof(Guid), typeof(double)); printer.PrintToString(person).Should().Be(expectedResult.ToString()); }
public void ShouldRecord_ValueEqualityComparisonsWorks() { var firstName = "Bill"; var lastName = "Jobs"; //Class var personc = new PersonClass(firstName, lastName); var samePersonc = new PersonClass(firstName, lastName); Assert.AreNotEqual(personc, samePersonc); //Records, Value-based equality var person = new Person(firstName, lastName); var samePerson = new Person(firstName, lastName); Assert.AreEqual(person, samePerson); Assert.IsTrue(person == samePerson); Assert.IsTrue(person.Equals(samePerson)); //different Records type with same value var anotherPerson = new AnotherPerson(firstName, lastName); var anotherPerson2 = anotherPerson with { FirstName = "Bill" }; Assert.AreNotEqual(person, anotherPerson); Assert.AreEqual(anotherPerson2, anotherPerson); //With-expressions and inheritance var student = new Student(firstName, lastName, 11); Person personSS = student; var personSS2 = student; Assert.AreNotEqual(person, student); Assert.AreEqual(personSS, personSS2); Assert.AreNotEqual(personSS, person); }