public void TestCreate()
		{
			var header = new Header();
			Assert.IsNullOrEmpty(header.standart);
			Assert.IsNullOrEmpty(header.version);
			Assert.That(header.msg_type, Is.EqualTo(((sbyte) (HeaderAsknowEnumType.none))));
			Assert.That(header.msg_acknow, Is.EqualTo(((sbyte) (HeaderMessageEnumType.notification))));
		}
		public static Header Init()
		{
			var data = new Header();
			data.standart = StandartFieldDefault;
			data.version = VersionFieldDefault;
			data.time = DateTime.UtcNow;
			// TODO: Можно заполнить некоторые поля
			return data;
		}
		public void TestVersionFieldDefault()
		{
			var header = new Header();
			header.version = Header.VersionFieldDefault;

			var ackResult = header.Check(HeaderMessageEnumType.notification);
			Assert.IsNotNull(ackResult);
			Assert.That(ackResult.Count, Is.GreaterThanOrEqualTo(0));
			var ex = ErrorReceiptCode.InvalidAttribute_Version_in_Header_Format;
			var obj = ackResult.FirstOrDefault(p => p.errorcode == ex.errorcode);
			Assert.IsNull(obj);
		}
		public void TestInvalidAttribute_Version_in_Header_Format(
			[Values("Версия стандарта", "Допустимое значение")] string standart
			)
		{
			var header = new Header();
			header.standart = standart;

			var ackResult = header.Check(HeaderMessageEnumType.notification);
			Assert.IsNotNull(ackResult);
			Assert.That(ackResult.Count, Is.GreaterThanOrEqualTo(1));
			var ex = ErrorReceiptCode.InvalidAttribute_Version_in_Header_Format;
			var obj = ackResult.FirstOrDefault(p => p.errorcode == ex.errorcode);
			EqualTo(obj, ex);
		}
		private Notification ReturnNotification(Header header, Notification notification)
		{
			var msg_acknow = GetMsgAcknow(header);

			switch ( msg_acknow )
			{
				case HeaderAsknowEnumType.none:
					return null;
				case HeaderAsknowEnumType.always:
					return notification;
				case HeaderAsknowEnumType.only_when_errors:
					if ( (notification.Acknowledgement.AckResult == null) || (notification.Acknowledgement.AckResult.Count < 1) )
						return null;
					else
					{
						return notification;
					}
			}
			throw new ArgumentOutOfRangeException("msg_acknow", msg_acknow, "Unknown value");
		}
Exemple #6
0
		public static bool LoadFromFile(string fileName, out Header obj)
		{
			System.Exception exception = null;
			return LoadFromFile(fileName, out obj, out exception);
		}
Exemple #7
0
		public static bool LoadFromFile(string fileName, out Header obj, out System.Exception exception)
		{
			return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception);
		}
Exemple #8
0
		/// <summary>
		/// Deserializes xml markup from file into an Header object
		/// </summary>
		/// <param name="fileName">string xml file to load and deserialize</param>
		/// <param name="obj">Output Header object</param>
		/// <param name="exception">output Exception value if deserialize failed</param>
		/// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
		public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out Header obj, out System.Exception exception)
		{
			exception = null;
			obj = default(Header);
			try
			{
				obj = LoadFromFile(fileName, encoding);
				return true;
			}
			catch ( System.Exception ex )
			{
				exception = ex;
				return false;
			}
		}
Exemple #9
0
		public static bool Deserialize(string xml, out Header obj)
		{
			System.Exception exception = null;
			return Deserialize(xml, out obj, out exception);
		}
Exemple #10
0
		/// <summary>
		/// Deserializes workflow markup into an Header object
		/// </summary>
		/// <param name="xml">string workflow markup to deserialize</param>
		/// <param name="obj">Output Header object</param>
		/// <param name="exception">output Exception value if deserialize failed</param>
		/// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
		public static bool Deserialize(string xml, out Header obj, out System.Exception exception)
		{
			exception = null;
			obj = default(Header);
			try
			{
				obj = Deserialize(xml);
				return true;
			}
			catch ( System.Exception ex )
			{
				exception = ex;
				return false;
			}
		}
		public void TestInvalidAttribute_MsgType_in_Header_Format(
			[Values(-2, -1,10,20)]sbyte msg_type
			)
		{
			var header = new Header();
			header.msg_type = msg_type;

			var ackResult = header.Check(HeaderMessageEnumType.notification);
			Assert.IsNotNull(ackResult);
			Assert.That(ackResult.Count, Is.GreaterThanOrEqualTo(1));
			var ex = ErrorReceiptCode.InvalidAttribute_MsgType_in_Header_Format;
			var obj = ackResult.FirstOrDefault(p => p.errorcode == ex.errorcode);
			EqualTo(obj, ex);
		}
		public void TestRequiredAttribute_in_Header_Format6()
		{
			var header = new Header();
			header.to_organization = "to_organization";

			var ackResult = header.Check(HeaderMessageEnumType.notification);
			Assert.IsNotNull(ackResult);
			Assert.That(ackResult.Count, Is.GreaterThanOrEqualTo(1));
			var ex = ErrorReceiptCode.MissingRequiredAttribute_in_Header_Format;
			var arg0 = "to_organization";
			var obj = ackResult.FirstOrDefault(p => ((p.errorcode == ex.errorcode) && (p.Value.Contains(arg0))));
			Assert.IsNull(obj);
		}
		public void TestAttribute_MsgType_in_Header_Format(
			[Values(0, 1, 2, 3, 4)]sbyte msg_type
			)
		{
			var type = (HeaderMessageEnumType) Enum.ToObject(typeof(HeaderMessageEnumType), msg_type);

			var header = new Header();
			header.msg_type = msg_type;

			var ackResult = header.Check(type);
			Assert.IsNotNull(ackResult);
			Assert.That(ackResult.Count, Is.GreaterThanOrEqualTo(1));
			var ex = ErrorReceiptCode.InvalidAttribute_MsgType_in_Header_Format;
			var obj = ackResult.FirstOrDefault(p => p.errorcode == ex.errorcode);
			Assert.IsNull(obj);
		}
		private HeaderAsknowEnumType GetMsgAcknow(Header header)
		{
			if ( header == null )
				return HeaderAsknowEnumTypeDefault;

			try
			{
				return (HeaderAsknowEnumType) Enum.ToObject(typeof(HeaderAsknowEnumType), header.msg_acknow);
			}
			catch
			{
				// TODO: В стандарте отсутствует код ошибки 
				return HeaderAsknowEnumTypeDefault;
			}
		}