/Release/02.00/src/Tests/RockBus.SubscriptionRepository.Tests/SubscriptionReposTransformationsTests.cs
# · C# · 217 lines · 179 code · 28 blank · 10 comment · 2 complexity · 551426a62c659e02e145cbf7faec8a01 MD5 · raw file
- using System;
- using System.Linq;
- using System.Transactions;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using RockBus.DataContracts;
- using RockBus.Logging.Trace;
- using RockBus.SubscriptionRepository.Db;
- using RockBus.SubscriptionRepository.Interfaces;
-
- namespace RockBus.SubscriptionRepository.Tests
- {
- /// <summary>
- /// This class contains unit tests for the persistence of transformation data.
- /// </summary>
- [TestClass]
- public class SubscriptionReposTransformationsTests
- {
- private static Db.SubscriptionRepository Repository { get; set; }
-
- [ClassInitialize]
- public static void ClassInitialize(TestContext tc)
- {
- DbSubscriptionRepositoryConfiguration config = new DbSubscriptionRepositoryConfiguration();
- Repository = new Db.SubscriptionRepository(new TraceLogger(), config);
- }
-
- [TestMethod]
- [TestCategory("SqlServerDbSubscriptionPersistence")]
- public void TestAddSubscriptionTransformation()
- {
- string id = Guid.NewGuid().ToString();
- AddOrUpdateSubscribersRequest request = this.CreateAddOrUpdateSubscribersRequest(id);
- Repository.ClearAllClients();
- Repository.AddOrUpdateSubscriberConfiguration(request.CreateSubscriberConfiguration());
- SubscriberConfiguration sc = Repository.GetSubscriberConfiguration();
-
- SubscriberInfo si = sc.EvaluationElementDictionary[id];
- Assert.AreEqual(3, si.PipelineInfoDictionary.Count);
- foreach (var sr in si.InfoDictionary.Values)
- {
- Assert.AreEqual(2, sr.Detail.RequestTransformationIds.Count);
- Assert.AreEqual(1, sr.Detail.ResponseTransformationIds.Count);
- }
- }
-
- [TestMethod]
- [TestCategory("SqlServerDbSubscriptionPersistence")]
- public void TestAddAdvertisedTransformation()
- {
- string id = Guid.NewGuid().ToString();
- AddOrUpdatePublishersRequest request = this.CreateAddOrUpdatePublishersRequest(id);
- Repository.ClearAllClients();
- Repository.AddOrUpdatePublisherConfiguration(request.CreatePublisherConfiguration());
- PublisherConfiguration pc = Repository.GetPublisherConfiguration();
-
- PublisherInfo pi = pc.EvaluationElementDictionary[id];
- Assert.AreEqual(3, pi.TransformationInfoDictionary.Count);
- foreach (var ai in pi.InfoDictionary.Values)
- {
- Assert.AreEqual(2, ai.Detail.RequestTransformationIds.Count);
- Assert.AreEqual(1, ai.Detail.ResponseTransformationIds.Count);
- }
- }
-
- private AddOrUpdateSubscribersRequest CreateAddOrUpdateSubscribersRequest(string id)
- {
- // Namespaces
- var nis = new[]
- {
- new NamespaceInfo("ns1", "http://somenamespace/"),
- };
-
- // Filters
- var fis = new[]
- {
- new FilterInfo("ActionFilter1", FilterTypeEnum.Action, "http://someaction/"),
- new FilterInfo("XPathFilter1", FilterTypeEnum.XPath, "//ns1:elem1/ns1:elem2/@ns1:attr1=3"),
- new FilterInfo("AndFilter1", "ActionFilter1", "XPathFilter1"),
- new FilterInfo("TopicFilter1", FilterTypeEnum.Topic, "sometopic"),
- };
-
- // Endpoint
- var ei = new EndpointInfo("Endpoint1", "http://someaddress/", EndpointNameEnum.BasicHttpEndpoint);
-
- SubscriberInfo si = new SubscriberInfo(id, nis, fis, new[] { ei });
-
- // Transformations
- si.PipelineInfoDictionary.Add(
- "RequestTransformation1",
- new TransformationInfo()
- {
- Id = "RequestTransformation1",
- TransformationType = TransformationTypeEnum.Xslt,
- TransformationData = "ReqTransformation1.xslt",
- });
- si.PipelineInfoDictionary.Add(
- "RequestTransformation2",
- new TransformationInfo()
- {
- Id = "RequestTransformation2",
- TransformationType = TransformationTypeEnum.Custom,
- TransformationData = "RockBus.Tests.Transformations.Test",
- CustomTypeName = "TestTransformation"
- });
- si.PipelineInfoDictionary.Add(
- "ResponseTransformation1",
- new TransformationInfo()
- {
- Id = "ResponseTransformation1",
- TransformationType = TransformationTypeEnum.Xslt,
- TransformationData = "RespTransformation.xslt",
- });
-
- // Subscriptions
- SubscriptionDetail sd = new SubscriptionDetail(Guid.NewGuid().ToString(), true, 1000, null, null);
- SubscriptionInfo sci = new SubscriptionInfo(si, sd, ei, fis);
-
- foreach (TransformationInfo ti in si.PipelineInfoDictionary.Values)
- {
- if (ti.Id.StartsWith("Request"))
- sci.Detail.RequestTransformationIds.Add(ti.Id);
- else
- sci.Detail.ResponseTransformationIds.Add(ti.Id);
- }
-
- si.InfoDictionary.TryAdd(sci.Detail.Id, sci);
-
- // SubscriptionConfiguration
- SubscriberConfiguration sc = new SubscriberConfiguration();
- sc.EvaluationElementDictionary.TryAdd(si.Id, si);
-
- // Request
- AddOrUpdateSubscribersRequest request = new AddOrUpdateSubscribersRequest(sc);
- return request;
- }
-
- private AddOrUpdatePublishersRequest CreateAddOrUpdatePublishersRequest(string id)
- {
- var tis = new[]
- {
- new TopicInfo()
- {
- Name = "Topic1",
- }
- };
-
- var nis = new[]
- {
- new NamespaceInfo("ns1", "http://somenamespace/"),
- };
-
- var fis = new[]
- {
- new FilterInfo("ActionFilter1", FilterTypeEnum.Action, "http://someaction/"),
- new FilterInfo("XPathFilter1", FilterTypeEnum.XPath, "//ns1:elem1/ns1:elem2/@ns1:attr1=3"),
- new FilterInfo("AndFilter1", "ActionFilter1", "XPathFilter1"),
- new FilterInfo("TopicFilter1", FilterTypeEnum.Topic, "sometopic"),
- };
-
- var ris = new[]
- {
- new ResponseInfo("Response1", "http://SomeAction", "<someOperation xmlns=\"http://somenamespace/\" />"),
- };
-
- PublisherInfo pi = new PublisherInfo(id, nis, fis, tis, ris);
-
-
- pi.TransformationInfoDictionary.Add(
- "RequestTransformation1",
- new TransformationInfo()
- {
- Id = "RequestTransformation1",
- TransformationType = TransformationTypeEnum.Xslt,
- TransformationData = "PubRequestTransformation.xslt"
- });
- pi.TransformationInfoDictionary.Add(
- "RequestTransformation2",
- new TransformationInfo()
- {
- Id = "RequestTransformation2",
- TransformationType = TransformationTypeEnum.Custom,
- TransformationData = "RockBus.Tests.Transformations.Test",
- CustomTypeName = "TestTransformation"
- });
- pi.TransformationInfoDictionary.Add(
- "ResponseTransformation1",
- new TransformationInfo()
- {
- Id = "ResponseTransformation1",
- TransformationType = TransformationTypeEnum.Xslt,
- TransformationData = "PubRespTransformation.xslt",
- });
-
-
- AdvertisementDetail pd = new AdvertisementDetail(Guid.NewGuid().ToString(), expiryDateTimeUtc: DateTime.MaxValue);
- AdvertisementInfo pci = new AdvertisementInfo(pi, pd);
- foreach (TransformationInfo ti in pi.TransformationInfoDictionary.Values)
- {
- if (ti.Id.StartsWith("Request"))
- pci.Detail.RequestTransformationIds.Add(ti.Id);
- else
- pci.Detail.ResponseTransformationIds.Add(ti.Id);
- }
-
- pci.TopicNames.Add("Topic1");
- pi.InfoDictionary.TryAdd(
- "Advertisement1",
- pci);
-
- PublisherConfiguration pc = new PublisherConfiguration();
- pc.EvaluationElementDictionary.TryAdd(pi.Id, pi);
-
- AddOrUpdatePublishersRequest request = new AddOrUpdatePublishersRequest(pc);
- return request;
- }
- }
- }