public ServiceInfo EmitTopicMessage() { var status = ServiceInfoFactory.CreateServiceDefinition(new ServiceInfo { Port = Convert.ToInt32(ServiceConfig.Reader.Port) }); var topics = new TopicFactory(ConnectionConfig.GetFactoryDefault(), new JsonMessageSerializer(), new ConsoleLog(), status.Version); topics.PublishMessage(status, new string[] { Topics.Images, Topics.Text, Topics.Url, Topics.Video }); return status; }
public void Delete_InternallyDerivedTopic_Succeeds() { var root = TopicFactory.Create("Root", "Page"); var topic = TopicFactory.Create("Topic", "Page", root); var child = TopicFactory.Create("Child", "Page", topic); var derived = TopicFactory.Create("Derived", "Page", topic); derived.DerivedTopic = child; _topicRepository.Delete(topic, true); Assert.AreEqual<int>(0, root.Children.Count); }
public void Save_AttributeDescriptor_UpdatesContentType() { var contentType = TopicFactory.Create("Parent", "ContentTypeDescriptor") as ContentTypeDescriptor; var attributeList = TopicFactory.Create("Attributes", "List", contentType); var childContentType = TopicFactory.Create("Child", "ContentTypeDescriptor", contentType) as ContentTypeDescriptor; var attributeCount = childContentType.AttributeDescriptors.Count; var newAttribute = TopicFactory.Create("NewAttribute", "BooleanAttribute", attributeList) as BooleanAttribute; _topicRepository.Save(newAttribute); Assert.IsTrue(childContentType.AttributeDescriptors.Count > attributeCount); }
public void AsReadOnly_ReturnsReadOnlyTopicCollection() { var topics = new TopicCollection(); for (var i = 0; i < 10; i++) { topics.Add(TopicFactory.Create("Topic" + i, "Page")); } var readOnlyCollection = topics.AsReadOnly(); Assert.AreEqual<int>(10, readOnlyCollection.Count); Assert.AreEqual<string>("Topic0", readOnlyCollection.First().Key); }
public void Delete_IncomingRelationships_DeleteRelationships() { var root = TopicFactory.Create("Root", "Page"); var topic = TopicFactory.Create("Topic", "Page", root); var child = TopicFactory.Create("Child", "Page", topic); var related = TopicFactory.Create("Related", "Page", root); related.Relationships.SetTopic("Related", child); _topicRepository.Delete(topic, true); Assert.AreEqual<int>(0, related.Relationships.GetTopics("Related").Count); }
static TopicFactory StartStatsConsumer() { var consumer = new TopicFactory( ConnectionConfig.GetFactoryDefault(RegistrySettings.Reader.AmqpUri), new JsonMessageSerializer(), new ConsoleLog(), serviceDefinition.Version, RegistrySettings.RegistryStatsExchange); consumer.RetryMax = 10; consumer.StartConsumerInBackground("status", new StatsConsumer()); return consumer; }
public void GetValue_InheritFromDerived_ReturnsDerivedValue() { var topics = new Topic[5]; for (var i = 0; i <= 4; i++) { var topic = TopicFactory.Create("Topic" + i, "Container"); if (i > 0) topics[i - 1].DerivedTopic = topic; topics[i] = topic; } topics[4].Attributes.SetValue("Foo", "Bar"); Assert.AreEqual<string>("Bar", topics[0].Attributes.GetValue("Foo", null, true, true)); }
public void ExportWithChildren_TopicWithChild_IncludesChildren() { var topic = TopicFactory.Create("Test", "Container"); var childTopic = TopicFactory.Create("Child1", "Container", topic); var topicData = topic.Export( new() { IncludeChildTopics = true } ); Assert.AreEqual<int>(1, topicData.Children.Count); Assert.AreEqual(childTopic.GetUniqueKey(), topicData.Children.FirstOrDefault().UniqueKey); }
public void Parent_SetValue_UpdatesParentTopic() { var parentTopic = TopicFactory.Create("Parent", "ContentTypeDescriptor"); var childTopic = TopicFactory.Create("Child", "ContentTypeDescriptor"); parentTopic.Id = 5; childTopic.Parent = parentTopic; Assert.ReferenceEquals(parentTopic.Children["Child"], childTopic); Assert.AreEqual<int>( 5, Int32.Parse(childTopic.Attributes.GetValue("ParentId", "0"), NumberStyles.Integer, CultureInfo.InvariantCulture) ); }
public async Task Map_TopicReferences_ReturnsMappedModel() { var mappingService = new TopicMappingService(_topicRepository, new FakeViewModelLookupService()); var topicReference = _topicRepository.Load(11111); var topic = TopicFactory.Create("Test", "TopicReference"); topic.Attributes.SetInteger("TopicReferenceId", topicReference.Id); var target = (TopicReferenceTopicViewModel?)await mappingService.MapAsync(topic).ConfigureAwait(false); Assert.IsNotNull(target.TopicReference); Assert.AreEqual<string>(topicReference.Key, target.TopicReference.Key); }
public async Task Map_InheritAttribute_InheritsValue() { var grandParent = TopicFactory.Create("Grandparent", "Page"); var parent = TopicFactory.Create("Parent", "Page", grandParent); var topic = TopicFactory.Create("Test", "InheritedProperty", parent); grandParent.Attributes.SetValue("Property", "ValueA"); grandParent.Attributes.SetValue("InheritedProperty", "ValueB"); var viewModel = await _mappingService.MapAsync<InheritedPropertyTopicViewModel>(topic).ConfigureAwait(false); Assert.IsNull(viewModel.Property); Assert.AreEqual<string>("ValueB", viewModel.InheritedProperty); }
public void DerivedTopic_UpdateValue_ReturnsExpectedValue() { var topic = TopicFactory.Create("Topic", "Page"); var firstDerivedTopic = TopicFactory.Create("DerivedTopic", "Page"); var secondDerivedTopic = TopicFactory.Create("DerivedTopic", "Page", 1); var finalDerivedTopic = TopicFactory.Create("DerivedTopic", "Page", 2); topic.DerivedTopic = firstDerivedTopic; topic.DerivedTopic = secondDerivedTopic; topic.DerivedTopic = finalDerivedTopic; Assert.ReferenceEquals(topic.DerivedTopic, finalDerivedTopic); Assert.AreEqual<int>(2, topic.Attributes.GetInteger("TopicID", 0)); }
/*========================================================================================================================== | CONSTRUCTOR \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Initializes a new instance of the <see cref="AttributeValue"/> class, using the specified key/value pair. /// </summary> /// <param name="key"> /// The string identifier for the <see cref="AttributeValue"/> collection item key/value pair. /// </param> /// <param name="value"> /// The string value text for the <see cref="AttributeValue"/> collection item key/value pair. /// </param> /// <param name="isDirty"> /// An optional boolean indicator noting whether the <see cref="AttributeValue"/> collection item is a new value, and /// should thus be saved to the database when <see cref="ITopicRepository.Save(Topic, Boolean, Boolean)"/> is next called. /// </param> /// <requires /// description="The key must be specified for the key/value pair." exception="T:System.ArgumentNullException"> /// !String.IsNullOrWhiteSpace(key) /// </requires> public AttributeValue(string key, string?value, bool isDirty = true) { /*------------------------------------------------------------------------------------------------------------------------ | Validate input \-----------------------------------------------------------------------------------------------------------------------*/ TopicFactory.ValidateKey(key, false); /*------------------------------------------------------------------------------------------------------------------------ | Set local values \-----------------------------------------------------------------------------------------------------------------------*/ Key = key; Value = value; IsDirty = isDirty; EnforceBusinessLogic = true; }
public void GetValue_ExceedsMaxHops_ReturnsDefault() { var topics = new Topic[8]; for (var i = 0; i <= 7; i++) { var topic = TopicFactory.Create("Topic" + i, "Container"); if (i > 0) topics[i - 1].DerivedTopic = topic; topics[i] = topic; } topics[7].Attributes.SetValue("Foo", "Bar"); Assert.IsNull(topics[0].Attributes.GetValue("Foo", null, true, true)); }
static void StartTopicWorkers(params string[] topics) { foreach (var item in topics) { var consumer = new TopicFactory( ConnectionConfig.GetFactoryDefault(RegistrySettings.Reader.AmqpUri), new JsonMessageSerializer(), new ConsoleLog(), registryClient.ServiceDefinition.Version); consumer.RetryMax = 10; consumer.StartConsumerInBackground<ServiceInfo>(item, new TopicConsumer()); topicConsumers.Add(consumer); } }
public async Task Map_Dynamic_ReturnsNewModel() { var topic = TopicFactory.Create("Test", "Page"); topic.Attributes.SetValue("MetaTitle", "ValueA"); topic.Attributes.SetValue("Title", "Value1"); topic.Attributes.SetValue("IsHidden", "1"); var target = (PageTopicViewModel?)await _mappingService.MapAsync(topic).ConfigureAwait(false); Assert.AreEqual<string>("ValueA", target.MetaTitle); Assert.AreEqual<string>("Value1", target.Title); Assert.AreEqual<bool>(true, target.IsHidden); }
public ActionResult <IEnumerable <TopicView> > GetTopicsList() { return(Execute(() => { IEnumerable <Topic> topics = TopicService.GetAll().OrderBy(o => o.Path, StringComparer.InvariantCultureIgnoreCase).ThenBy(o => o.Name, StringComparer.InvariantCultureIgnoreCase); List <TopicView> topicViews = new List <TopicView>(); foreach (Topic topic in topics) { topicViews.Add(TopicFactory.CreateView(topic)); } return Ok(topicViews); })); }
public async Task Map_MapToParent_ReturnsMappedModel() { var topic = TopicFactory.Create("Test", "FlattenChildren"); topic.Attributes.SetValue("PrimaryKey", "Primary Key"); topic.Attributes.SetValue("AlternateKey", "Alternate Key"); topic.Attributes.SetValue("AncillaryKey", "Ancillary Key"); topic.Attributes.SetValue("AliasedKey", "Aliased Key"); var target = await _mappingService.MapAsync<MapToParentTopicViewModel>(topic).ConfigureAwait(false); Assert.AreEqual<string>("Test", target.Primary.Key); Assert.AreEqual<string>("Aliased Key", target.Alternate.Key); Assert.AreEqual<string>("Ancillary Key", target.Ancillary.Key); }
public async Task Map_FlattenAttribute_ReturnsFlatCollection() { var topic = TopicFactory.Create("Test", "FlattenChildren"); for (var i = 0; i < 5; i++) { var childTopic = TopicFactory.Create("Child" + i, "Page", topic); for (var j = 0; j < 5; j++) { TopicFactory.Create("GrandChild" + i + j, "FlattenChildren", childTopic); } } var target = await _mappingService.MapAsync<FlattenChildrenTopicViewModel>(topic).ConfigureAwait(false); Assert.AreEqual<int>(25, target.Children.Count); }
public void ExportWithLegacyTopicReferences_OutOfScope_SkipsReference() { var parentTopic = TopicFactory.Create("Root", "Container", 5); var topic = TopicFactory.Create("Topic", "Container", parentTopic); topic.Attributes.SetValue("SomeId", "5"); var topicData = topic.Export(); topicData.Attributes.TryGetValue("SomeId", out var someAttribute); topicData.References.TryGetValue("Some", out var someReference); Assert.IsNotNull(someAttribute); Assert.IsNull(someReference); }
public ActionResult AddTopic(TopicEntity Topic) { try { if (ModelState.IsValid) { ValidationFactory VF = new ValidationFactory(); TopicFactory AddTopic = new TopicFactory(); DataLayer.tblTopic NewTopic = new DataLayer.tblTopic(); DataLayer.tblChannel NewChannel = new DataLayer.tblChannel(); string Message = VF.TopicValidity(Topic.TopicName, null); if (Message != "Success") { ModelState.AddModelError("TopicName", Message); GetChannel(); return(View(Topic)); } else { NewTopic.TopicName = Topic.TopicName; NewTopic.ChannelId = Topic.ChannelId; NewTopic.CreatedDate = DateTime.Now; NewTopic.CreatedBy = null; NewTopic.UpdatedDate = null; NewTopic.UpdatedBy = null; NewTopic.IsActive = true; AddTopic.SaveTopic(NewTopic); return(RedirectToAction("Topic")); } } else { GetChannel(); return(View(Topic)); } } catch (Exception Ex) { GetChannel(); return(View()); } finally { GetChannel(); } }
// GET: Topic/Edit/5 public ActionResult EditTopic(long id) { try { TopicFactory EditTopic = new TopicFactory(); TopicEntity topic = new TopicEntity(); topic = EditTopic.GetTopicById(id); return(View(topic)); } catch { return(View()); } finally { GetChannel(); } }
public void IsVisible_ReturnsExpectedValue() { var hiddenTopic = TopicFactory.Create("HiddenTopic", "Page"); var disabledTopic = TopicFactory.Create("DisabledTopic", "Page"); var visibleTopic = TopicFactory.Create("VisibleTopic", "Page"); hiddenTopic.IsHidden = true; disabledTopic.IsDisabled = true; Assert.IsFalse(hiddenTopic.IsVisible()); Assert.IsFalse(hiddenTopic.IsVisible(true)); Assert.IsFalse(disabledTopic.IsVisible()); Assert.IsTrue(disabledTopic.IsVisible(true)); Assert.IsTrue(visibleTopic.IsVisible()); Assert.IsTrue(visibleTopic.IsVisible(true)); }
public void ExportWithLegacyTopicReferences_MissingTopicReference_SkipsReference() { var topic = TopicFactory.Create("Topic", "Container"); topic.Attributes.SetValue("InitialBid", "6"); var topicData = topic.Export(); topicData.Attributes.TryGetValue("InitialBid", out var initialBidAttribute); topicData.References.TryGetValue("InitialB", out var initialBReference); topicData.References.TryGetValue("InitialB", out var initialBidReference); Assert.IsNotNull(initialBidAttribute); Assert.IsNull(initialBReference); Assert.IsNull(initialBidReference); }
public void Export_ExcludesReservedAttributes() { var topic = TopicFactory.Create("Topic", "Container", 5); _ = TopicFactory.Create("ChildA", "Container", topic, 6); _ = TopicFactory.Create("ChildB", "Container", topic, 7); //Manually setting using non-standard casing to evaluate case insensitivity topic.Attributes.SetValue("parentId", "5"); topic.Attributes.SetValue("topicId", "6"); topic.Attributes.SetValue("anotherId", "8"); var topicData = topic.Export(); Assert.AreEqual<int>(1, topicData.Attributes.Count); Assert.AreEqual<string?>("8", topicData.Attributes.FirstOrDefault().Value); }
public void FindAllByAttribute_ReturnsCorrectTopics() { var parentTopic = TopicFactory.Create("ParentTopic", "Page", 1); var childTopic = TopicFactory.Create("ChildTopic", "Page", 5, parentTopic); var grandChildTopic = TopicFactory.Create("GrandChildTopic", "Page", 20, childTopic); var grandNieceTopic = TopicFactory.Create("GrandNieceTopic", "Page", 3, childTopic); var greatGrandChildTopic = TopicFactory.Create("GreatGrandChildTopic", "Page", 7, grandChildTopic); grandChildTopic.Attributes.SetValue("Foo", "Baz"); greatGrandChildTopic.Attributes.SetValue("Foo", "Bar"); grandNieceTopic.Attributes.SetValue("Foo", "Bar"); Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Bar").First(), grandNieceTopic); Assert.AreEqual<int>(2, parentTopic.FindAllByAttribute("Foo", "Bar").Count); Assert.ReferenceEquals(parentTopic.FindAllByAttribute("Foo", "Baz").First(), grandChildTopic); }
public void GetUnmatchedAttributes_EmptyArbitraryAttributes_ReturnsAttributes() { var topic = TopicFactory.Create("Test", "ContentTypeDescriptor", 1); topic.Attributes.SetValue("ArbitraryAttribute", "Value"); topic.Attributes.SetValue("ArbitraryAttribute", ""); topic.Attributes.SetValue("AnotherArbitraryAttribute", "Value"); topic.Attributes.SetValue("YetAnotherArbitraryAttribute", "Value"); topic.Attributes.SetValue("YetAnotherArbitraryAttribute", null); var attributes = _topicRepository.GetUnmatchedAttributesProxy(topic); Assert.IsTrue(attributes.Any(a => a.Key is "ArbitraryAttribute")); Assert.IsTrue(attributes.Any(a => a.Key is "YetAnotherArbitraryAttribute")); Assert.IsFalse(attributes.Any(a => a.Key is "AnotherArbitraryAttribute")); }
public void GetValue_InheritFromParent_ReturnsParentValue() { var topics = new Topic[8]; for (var i = 0; i <= 7; i++) { var topic = TopicFactory.Create("Topic" + i, "Container"); if (i > 0) topic.Parent = topics[i - 1]; topics[i] = topic; } topics[0].Attributes.SetValue("Foo", "Bar"); Assert.IsNull(topics[4].Attributes.GetValue("Foo", null)); Assert.AreEqual<string>("Bar", topics[7].Attributes.GetValue("Foo", true)); Assert.AreNotEqual<string>("Bar", topics[7].Attributes.GetValue("Foo", false)); }
public void AddTopic_IsDuplicate_StaysDirty() { var relationships = new NamedTopicCollection("Test"); var related1 = TopicFactory.Create("Topic", "Page"); var related2 = TopicFactory.Create("Topic", "Page"); relationships.Add(related1); try { relationships.Add(related2); } catch (ArgumentException) { //Expected due to duplicate key } Assert.IsTrue(relationships.IsDirty); }
public async Task Map_Slideshow_ReturnsDerivedViewModels() { var topic = TopicFactory.Create("Test", "Slideshow"); var slides = TopicFactory.Create("ContentItems", "List", topic); var childTopic1 = TopicFactory.Create("ChildTopic1", "Slide", slides); var childTopic2 = TopicFactory.Create("ChildTopic2", "Slide", slides); var childTopic3 = TopicFactory.Create("ChildTopic3", "Slide", slides); var childTopic4 = TopicFactory.Create("ChildTopic4", "ContentItem", slides); var target = await _mappingService.MapAsync<SlideshowTopicViewModel>(topic).ConfigureAwait(false); Assert.AreEqual<int>(4, target.ContentItems.Count); Assert.IsNotNull(GetChildTopic(target.ContentItems, "ChildTopic1")); Assert.IsNotNull(GetChildTopic(target.ContentItems, "ChildTopic2")); Assert.IsNotNull(GetChildTopic(target.ContentItems, "ChildTopic3")); Assert.IsNotNull(GetChildTopic(target.ContentItems, "ChildTopic4")); }
public async Task Map_FilterByContentType_ReturnsFilteredCollection() { var topic = TopicFactory.Create("Test", "Descendent"); var childTopic1 = TopicFactory.Create("ChildTopic1", "Descendent", topic); var childTopic2 = TopicFactory.Create("ChildTopic2", "DescendentSpecialized", topic); var childTopic3 = TopicFactory.Create("ChildTopic3", "DescendentSpecialized", topic); var childTopic4 = TopicFactory.Create("ChildTopic4", "DescendentSpecialized", childTopic3); var target = await _mappingService.MapAsync<DescendentTopicViewModel>(topic).ConfigureAwait(false); var specialized = target.Children.GetByContentType("DescendentSpecialized"); Assert.AreEqual<int>(2, specialized.Count); Assert.IsNotNull(GetChildTopic(specialized, "ChildTopic2")); Assert.IsNotNull(GetChildTopic(specialized, "ChildTopic3")); Assert.IsNull(GetChildTopic(specialized, "ChildTopic4")); }
public async Task Map_FilterByAttribute_ReturnsFilteredCollection() { var topic = TopicFactory.Create("Test", "Filtered"); var childTopic1 = TopicFactory.Create("ChildTopic1", "Page", topic); var childTopic2 = TopicFactory.Create("ChildTopic2", "Index", topic); var childTopic3 = TopicFactory.Create("ChildTopic3", "Page", topic); var childTopic4 = TopicFactory.Create("ChildTopic4", "Page", childTopic3); childTopic1.Attributes.SetValue("SomeAttribute", "ValueA"); childTopic2.Attributes.SetValue("SomeAttribute", "ValueA"); childTopic3.Attributes.SetValue("SomeAttribute", "ValueA"); childTopic4.Attributes.SetValue("SomeAttribute", "ValueB"); var target = await _mappingService.MapAsync<FilteredTopicViewModel>(topic).ConfigureAwait(false); Assert.AreEqual<int>(2, target.Children.Count); }
/*========================================================================================================================== | METHOD: FIND ALL BY ATTRIBUTE \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Retrieves a collection of topics based on an attribute name and value. /// </summary> /// <param name="topic">The instance of the <see cref="Topic"/> to operate against; populated automatically by .NET.</param> /// <param name="name">The string identifier for the <see cref="AttributeValue"/> against which to be searched.</param> /// <param name="value">The text value for the <see cref="AttributeValue"/> against which to be searched.</param> /// <returns>A collection of topics matching the input parameters.</returns> /// <requires description="The attribute name must be specified." exception="T:System.ArgumentNullException"> /// !String.IsNullOrWhiteSpace(name) /// </requires> /// <requires /// decription="The name should be an alphanumeric sequence; it should not contain spaces or symbols." /// exception="T:System.ArgumentException"> /// !name.Contains(" ") /// </requires> public static ReadOnlyTopicCollection <Topic> FindAllByAttribute(this Topic topic, string name, string value) { /*------------------------------------------------------------------------------------------------------------------------ | Validate contracts \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(topic, "The topic parameter must be specified."); Contract.Requires <ArgumentNullException>(!String.IsNullOrWhiteSpace(name), "The attribute name must be specified."); Contract.Requires <ArgumentNullException>(!String.IsNullOrWhiteSpace(value), "The attribute value must be specified."); TopicFactory.ValidateKey(name); /*------------------------------------------------------------------------------------------------------------------------ | Return results \-----------------------------------------------------------------------------------------------------------------------*/ return(topic.FindAll(t => !String.IsNullOrEmpty(t.Attributes.GetValue(name)) && t.Attributes.GetValue(name).IndexOf(value, StringComparison.InvariantCultureIgnoreCase) >= 0 )); }
static void Main(string[] args) { serviceDefinition = ServiceInfoFactory.CreateServiceDefinition(new ServiceInfo { Port = Convert.ToInt32(ServiceConfig.Reader.Port) }); var store = new RegistryDatabaseFactory(); store.Create(); store.ApplySchema(); store.r.Connection.Dispose(); if (args.Length == 0 || args.Contains("-ampq")) { serviceRegistryServer = new RpcServer<ServiceInfo>(ConnectionConfig.GetFactoryDefault(), RegistrySettings.RegistryQueue, RegisterService); serviceRegistryServer.StartInBackground(); statsConsumer = StartStatsConsumer(); Console.WriteLine("Registry AMPQ started"); } if (args.Length == 0 || args.Contains("-web")) { webServer = WebApp.Start<Startup>(url: ServiceConfig.Reader.GetBaseAddress()); Console.WriteLine("Web server started"); } Console.ReadLine(); if (statsConsumer != null) { statsConsumer.StopConsumer(); serviceRegistryServer.Stop(); } if (webServer != null) { webServer.Dispose(); } }
private void Sync() { var service = ServiceInfoFactory.CreateServiceDefinition(ServiceDefinition); var topics = new TopicFactory( ConnectionConfig.GetFactoryDefault(), new JsonMessageSerializer(), new ConsoleLog(), service.Version, RegistrySettings.RegistryStatsExchange); topics.PublishMessage(service, new string[] { "status" }); }