public void TestGetDigest()
        {
            Request request = new Request();
            
            List<CustomProperty> props = new List<CustomProperty>();

            props.Add(new CustomProperty("Subject", "This is a subject"));
            
            RoutingEntity sourceRouting = new RoutingEntity();

            RoutingItem item = new RoutingItem();
            item.Content = "*****@*****.**";
            
            sourceRouting.Items = new RoutingItem[] {item};
            request.Source = sourceRouting;
            request.Properties = props.ToArray();

            string digest1 = new RequestDigestProvider().GetDigest(request);
            //change the request, get a different digest value.

            request.Source.Items[0].Content = "*****@*****.**";
            string digest2 = new RequestDigestProvider().GetDigest(request);
            Assert.AreNotEqual(digest1,digest2);

            request.Properties[0].Value = "Change the subject";
            string digest3 = new RequestDigestProvider().GetDigest(request);
            Assert.AreNotEqual(digest1,digest2);
            Assert.AreNotEqual(digest2, digest3);

            //Empty subject is OK
            request.Properties[0].Value = string.Empty;

            string digest4 = new RequestDigestProvider().GetDigest(request);
            Assert.AreNotEqual(digest1,digest4);
        }
Exemplo n.º 2
0
		internal static RoutingEntity GetRoutingEntity(IUniversalRoutingEntity ure)
		{
			if (null == ure)
				throw new ArgumentNullException("ure");

			RoutingEntity routingEntity = new RoutingEntity();

			routingEntity.PolicyType = ure.PolicyType.ToString();
			routingEntity.RoutingType = ure.RoutingType;

			if (ure.Items != null && ure.Items.Count > 0)
			{
				routingEntity.Items = new Workshare.PolicyContent.RoutingItem[ure.Items.Count];
				int index = 0;
				foreach (IRoutingItem item in ure.Items)
				{
					Workshare.PolicyContent.RoutingItem routingItem = new Workshare.PolicyContent.RoutingItem();
					routingItem.Content = item.Content;

					if (item.Properties != null && item.Properties.Count > 0)
					{
						routingItem.Properties = new CustomProperty[item.Properties.Count];
						int propIndex = 0;
						foreach( string key in item.Properties.Keys)
						{
							routingItem.Properties[propIndex++] = new CustomProperty(key, item.Properties[key]);
						}
					}

					routingEntity.Items[index++] = routingItem;
				}
			}

			return routingEntity;
		}
		/// <summary>
		/// Create a basic ClientMail request.
		/// </summary>
		/// <remarks>
		/// Sets up the destination and source routing etc
		/// </remarks>
		/// <returns></returns>
		public static Request CreateRequest(CustomProperty[] properties)
		{
			Request request = new Request();

			request.PolicyType = PolicyType.ClientEmail.ToString();
			request.DateTime = DateTime.Now;

			request.Properties = properties;

			RoutingEntity source = new RoutingEntity();
			request.Source = source;

			source.PolicyType = request.PolicyType;
			source.RoutingType = Workshare.PolicyContent.RoutingTypes.Source;
			source.Properties = new CustomProperty[] { new CustomProperty(SMTPPropertyKeys.RequestChannel, RequestChannel.Outlook) };

			PolicyContent.RoutingItem item = new PolicyContent.RoutingItem();
			item.Content = "*****@*****.**";

			item.Properties = new CustomProperty[] { new CustomProperty(SMTPItemPropertyKeys.DisplayName, "lnpair"), 
				new CustomProperty(SMTPItemPropertyKeys.AddressType, AddressType.From) };

			source.Items = new PolicyContent.RoutingItem[] { item };

			// Populate the destination routing entity
			RoutingEntity dest = new RoutingEntity();
			request.Destination = source;

			dest.PolicyType = request.PolicyType;
			dest.RoutingType = Workshare.PolicyContent.RoutingTypes.Destination;
			dest.Properties = new CustomProperty[] { new CustomProperty(SMTPPropertyKeys.RequestChannel, RequestChannel.Outlook) };

			item = new PolicyContent.RoutingItem();
			item.Content = "*****@*****.**";

			item.Properties = new CustomProperty[] { new CustomProperty(SMTPItemPropertyKeys.DisplayName, "lnpair"), 
				new CustomProperty(SMTPItemPropertyKeys.AddressType, AddressType.From) ,
				new CustomProperty(SMTPItemPropertyKeys.Internal, bool.FalseString)};


			dest.Items = new PolicyContent.RoutingItem[] { item };

			return request;
		}
Exemplo n.º 4
0
		internal static IUniversalRoutingEntity GetUniversalRoutingEntity(RoutingEntity routingEntity)
		{
			if (null == routingEntity)
				return null;

			UniversalRoutingEntity routing = new UniversalRoutingEntity();
			routing.PolicyType = (PolicyType)Enum.Parse(typeof(PolicyType), routingEntity.PolicyType);
			routing.RoutingType = routingEntity.RoutingType;
			routing.Items = new Collection<IRoutingItem>();
			if (routingEntity.Items != null)
			{
				foreach (Workshare.PolicyContent.RoutingItem routingItem in routingEntity.Items)
				{
					Workshare.Policy.Routing.RoutingItem item =
						new Workshare.Policy.Routing.RoutingItem(routingItem.Content);

					item.Properties = new Dictionary<string, string>();

					if (routingItem.Properties != null)
					{
						foreach (CustomProperty custProp in routingItem.Properties)
						{
							item.Properties[custProp.Name] = custProp.Value;
						}
					}

					routing.Items.Add(item);
				}
			}

			routing.Properties = new Dictionary<string, string>();
			if (routingEntity.Properties != null)
			{
				foreach (CustomProperty property in routingEntity.Properties)
				{
					routing.Properties[property.Name] = property.Value;
				}
			}
			return routing;
		}
        public void GetDigestRoutingItemIsCaseInsensitive()
        {
            Request request = new Request();

            List<CustomProperty> props = new List<CustomProperty>();

            props.Add(new CustomProperty("Subject", "This is a subject"));

            RoutingEntity sourceRouting = new RoutingEntity();

            RoutingItem item = new RoutingItem();
            item.Content = "*****@*****.**";
            sourceRouting.Items = new RoutingItem[] { item };
            request.Source = sourceRouting;
            request.Properties = props.ToArray();

            string digest1 = new RequestDigestProvider().GetDigest(request);

            request.Source.Items[0].Content = request.Source.Items[0].Content.ToUpperInvariant();

            string digest2 = new RequestDigestProvider().GetDigest(request);

            Assert.AreEqual(digest1,digest2);
        }
        public void GetDigestMissingSubjectProperty()
        {
            Request request = new Request();

            request.Properties = new CustomProperty[0];//Invalid, this should cause the throw

            RoutingEntity sourceRouting = new RoutingEntity();
            sourceRouting.RoutingType = "Source";

            RoutingItem item = new RoutingItem();
            item.Content = "*****@*****.**";
            sourceRouting.Items = new RoutingItem[] { item };
            request.Source = sourceRouting;

            try
            {
                string digest = new RequestDigestProvider().GetDigest(request);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true, "Expecting method to throw this ArgumentException");
                return;
            }

            Assert.Fail("Should have thrown the ArgumentException");
        }
        public void GetDigestEmptyRoutingItem()
        {
            Request request = new Request();

            List<CustomProperty> props = new List<CustomProperty>();

            props.Add(new CustomProperty("Subject", "This is a subject"));
            request.Properties = props.ToArray();

            RoutingEntity sourceRouting = new RoutingEntity();

            RoutingItem item = new RoutingItem();
            item.Content = string.Empty;  //Invalid, this should cause the throw
            sourceRouting.Items = new RoutingItem[] { item };
            request.Source = sourceRouting;
            request.Properties = props.ToArray();

            try
            {
                string digest = new RequestDigestProvider().GetDigest(request);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true, "Expecting method to throw this ArgumentException");
                return;
            }

            Assert.Fail("Should have thrown the ArgumentException");
        }