Пример #1
0
        /// <summary>
        /// Add content to children collection
        /// </summary>
        private void OnContentChanged(object oldContent, object newContent)
        {
            if (newContent is View newContentView)
            {
                if (_actualContentElement != null && Children.Contains(_actualContentElement))
                {
                    Children.Remove(_actualContentElement);
                }

                _actualContentElement = newContentView;

                if (_actualContentElement != null && Children.Contains(_actualContentElement) == false)
                {
                    Children.Add(_actualContentElement);
                }

                ContentCreated?.Invoke(this, new EventArgs());
            }
            else if (oldContent is View oldContentView)
            {
                if (_actualContentElement != null && Children.Contains(_actualContentElement))
                {
                    Children.Remove(_actualContentElement);
                }

                _actualContentElement = null;
            }
            else if (_actualContentElement != null)
            {
                _actualContentElement.BindingContext = newContent;
            }
        }
Пример #2
0
        public void Should_not_create_job_if_too_old()
        {
            var e = new ContentCreated {
                SchemaId = new NamedId <Guid>(Guid.NewGuid(), "my-schema"), AppId = new NamedId <Guid>(Guid.NewGuid(), "my-event")
            };

            var now = SystemClock.Instance.GetCurrentInstant();

            var ruleConfig   = new Rule(new ContentChangedTrigger(), new WebhookAction());
            var ruleEnvelope = Envelope.Create(e);

            ruleEnvelope.SetTimestamp(now.Minus(Duration.FromDays(3)));

            var actionData        = new RuleJobData();
            var actionDescription = "MyDescription";

            var eventName = "MySchemaCreatedEvent";

            A.CallTo(() => clock.GetCurrentInstant())
            .Returns(now);

            A.CallTo(() => ruleTriggerHandler.Triggers(A <Envelope <AppEvent> > .Ignored, ruleConfig.Trigger))
            .Returns(true);

            A.CallTo(() => ruleActionHandler.CreateJob(A <Envelope <AppEvent> > .Ignored, eventName, ruleConfig.Action))
            .Returns((actionDescription, actionData));

            var job = sut.CreateJob(ruleConfig, ruleEnvelope);

            Assert.Null(job);
        }
Пример #3
0
        public async Task Should_not_create_job_if_too_old()
        {
            var @event = new ContentCreated {
                SchemaId = NamedId.Of(Guid.NewGuid(), "my-schema"), AppId = NamedId.Of(Guid.NewGuid(), "my-event")
            };

            var now = SystemClock.Instance.GetCurrentInstant();

            var ruleConfig   = ValidRule();
            var ruleEnvelope = Envelope.Create(@event);

            ruleEnvelope.SetTimestamp(now.Minus(Duration.FromDays(3)));

            A.CallTo(() => clock.GetCurrentInstant())
            .Returns(now);

            A.CallTo(() => ruleTriggerHandler.Triggers(A <Envelope <AppEvent> > .Ignored, ruleConfig.Trigger))
            .Returns(true);

            A.CallTo(() => ruleActionHandler.CreateJobAsync(A <EnrichedEvent> .Ignored, ruleConfig.Action))
            .Returns((actionDescription, actionData));

            var job = await sut.CreateJobAsync(ruleConfig, ruleEnvelope);

            Assert.Null(job);
        }
Пример #4
0
        /// <summary>
        /// Create content with content template
        /// </summary>
        private void OnContentTemplateChanged(DataTemplate oldContentTemplate, DataTemplate newContentTemplate)
        {
            if (ContentCreateEvent != ContentCreateEvents.Default)
            {
                return;
            }

            if (Content == null || Content is View == false)
            {
                if (_actualContentElement != null && Children.Contains(_actualContentElement))
                {
                    Children.Remove(_actualContentElement);
                    _actualContentElement = null;
                }

                if (newContentTemplate != null)
                {
                    _actualContentElement = newContentTemplate.CreateContent() as View;

                    if (Content != null)
                    {
                        _actualContentElement.BindingContext = Content;
                    }

                    Children.Add(_actualContentElement);

                    ContentCreated?.Invoke(this, new EventArgs());
                }
            }
            else
            {
                // Do nothing with template
            }
        }
Пример #5
0
        public async Task Should_load_content_from_created_event()
        {
            var eventData1 = new EventData();
            var eventData2 = new EventData();

            var event1 = new ContentCreated {
                Data = new NamedContentData(), AppId = new NamedId <Guid>(appId, "my-app")
            };
            var event2 = new ContentStatusChanged();

            var events = new List <StoredEvent>
            {
                new StoredEvent("0", 0, eventData1),
                new StoredEvent("1", 1, eventData2)
            };

            A.CallTo(() => eventStore.GetEventsAsync(streamName))
            .Returns(events);

            A.CallTo(() => formatter.Parse(eventData1, true))
            .Returns(new Envelope <IEvent>(event1));
            A.CallTo(() => formatter.Parse(eventData2, true))
            .Returns(new Envelope <IEvent>(event2));

            var data = await sut.LoadAsync(appId, id, 3);

            Assert.Same(event1.Data, data);
        }
        public void Should_calculate_name_for_created()
        {
            var @event = new ContentCreated {
                SchemaId = schemaMatch
            };

            Assert.Equal("MySchema1Created", sut.GetName(@event));
        }
Пример #7
0
        protected void On(ContentCreated @event)
        {
            SchemaId = @event.SchemaId;

            Data = @event.Data;

            AppId = @event.AppId;
        }
Пример #8
0
        } // ScAddPartMeta

        // ******************************************************************************
        public void ScAddPMcontentCreated(string partId, string dtValueAsStr)
        // Code History:
        // 2010-12-11,2014-02-26 mws
        {
            var contentCreated = new ContentCreated();

            contentCreated.thisValue = dtValueAsStr;
            AddNarPropertyToWrapper1(PropsWrapping1.PartMeta, partId, contentCreated);
        } // ScAddPMcontentCreated
Пример #9
0
        public void Should_replace_schema_information_from_event()
        {
            var @event = new ContentCreated {
                SchemaId = schemaId
            };

            var result = sut.FormatString("Name $SCHEMA_NAME has id $SCHEMA_ID", AsEnvelope(@event));

            Assert.Equal($"Name my-schema has id {schemaId.Id}", result);
        }
Пример #10
0
        public void Should_create_route_data()
        {
            var @event = new ContentCreated {
                AppId = appId
            };

            var result = sut.ToRouteData(AsEnvelope(@event));

            Assert.True(result is JObject);
        }
Пример #11
0
        public void Should_replace_app_information_from_event()
        {
            var @event = new ContentCreated {
                AppId = appId
            };

            var result = sut.FormatString("Name $APP_NAME has id $APP_ID", AsEnvelope(@event));

            Assert.Equal($"Name my-app has id {appId.Id}", result);
        }
Пример #12
0
        public void Should_format_email_and_display_name_from_client()
        {
            var @event = new ContentCreated {
                Actor = new RefToken("client", "android")
            };

            var result = sut.FormatString("From $USER_NAME ($USER_EMAIL)", AsEnvelope(@event));

            Assert.Equal($"From client:android (client:android)", result);
        }
Пример #13
0
        public void Should_create_route_data_from_event()
        {
            var @event = new ContentCreated {
                AppId = appId
            };

            var result = sut.ToRouteData(AsEnvelope(@event), "MyEventName");

            Assert.Equal("MyEventName", result["type"]);
        }
Пример #14
0
        protected Task On(ContentCreated @event, EnvelopeHeaders headers)
        {
            return(ForSchemaAsync(@event.SchemaId.Id, (collection, schemaEntity) =>
            {
                return collection.CreateAsync(@event, headers, x =>
                {
                    SimpleMapper.Map(@event, x);

                    x.SetData(schemaEntity.Schema, @event.Data);
                });
            }));
        }
Пример #15
0
        public void Should_return_undefined_if_user_failed_to_resolve()
        {
            A.CallTo(() => userResolver.FindByIdOrEmailAsync("123"))
            .Throws(new InvalidOperationException());

            var @event = new ContentCreated {
                Actor = new RefToken("subject", "123")
            };

            var result = sut.FormatString("From $USER_NAME ($USER_EMAIL)", AsEnvelope(@event));

            Assert.Equal($"From UNDEFINED (UNDEFINED)", result);
        }
Пример #16
0
        public void Should_create_route_data()
        {
            var appId = Guid.NewGuid();

            var @event = new ContentCreated
            {
                AppId = new NamedId <Guid>(appId, "my-app")
            };

            var result = sut.ToRouteData(AsEnvelope(@event));

            Assert.True(result is JObject);
        }
Пример #17
0
        public void Should_format_email_and_display_name_from_user()
        {
            A.CallTo(() => userResolver.FindByIdOrEmailAsync("123"))
            .Returns(user);

            var @event = new ContentCreated {
                Actor = new RefToken("subject", "123")
            };

            var result = sut.FormatString("From $USER_NAME ($USER_EMAIL)", AsEnvelope(@event));

            Assert.Equal($"From me ([email protected])", result);
        }
        public void Should_not_trigger_precheck_if_schema_id_does_not_match()
        {
            TestForTrigger(handleAll: false, schemaId: schemaNonMatch, condition: null, action: ctx =>
            {
                var @event = new ContentCreated {
                    SchemaId = schemaMatch
                };

                var result = sut.Trigger(Envelope.Create <AppEvent>(@event), ctx);

                Assert.False(result);
            });
        }
        public void Should_trigger_precheck_if_handling_all_events()
        {
            TestForTrigger(handleAll: true, schemaId: schemaMatch, condition: null, action: ctx =>
            {
                var @event = new ContentCreated {
                    SchemaId = schemaMatch
                };

                var result = sut.Trigger(Envelope.Create <AppEvent>(@event), ctx);

                Assert.True(result);
            });
        }
        public void Should_trigger_precheck_if_condition_is_empty()
        {
            TestForTrigger(handleAll: false, schemaId: schemaMatch, condition: string.Empty, action: ctx =>
            {
                var @event = new ContentCreated {
                    SchemaId = schemaMatch
                };

                var result = sut.Trigger(Envelope.Create <AppEvent>(@event), ctx);

                Assert.True(result);
            });
        }
Пример #21
0
        public void Should_create_route_data_from_event()
        {
            var appId = Guid.NewGuid();

            var @event = new ContentCreated
            {
                AppId = new NamedId <Guid>(appId, "my-app")
            };

            var result = sut.ToRouteData(AsEnvelope(@event), "MyEventName");

            Assert.Equal("MyEventName", result["type"]);
        }
Пример #22
0
        public void Should_return_undefined_if_user_is_not_found()
        {
            A.CallTo(() => userResolver.FindByIdOrEmailAsync("123"))
            .Returns(Task.FromResult <IUser>(null));

            var @event = new ContentCreated {
                Actor = new RefToken("subject", "123")
            };

            var result = sut.FormatString("From $USER_NAME ($USER_EMAIL)", AsEnvelope(@event));

            Assert.Equal($"From UNDEFINED (UNDEFINED)", result);
        }
Пример #23
0
        public void Should_return_undefined_when_partition_not_found()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city", new ContentFieldData()
                              .AddValue("iv", "Berlin"))
            };

            var result = sut.FormatString("$CONTENT_DATA.city.de", AsEnvelope(@event));

            Assert.Equal("UNDEFINED", result);
        }
Пример #24
0
        public void Should_return_plain_value_when_found()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city", new ContentFieldData()
                              .AddValue("iv", "Berlin"))
            };

            var result = sut.FormatString("$CONTENT_DATA.city.iv", AsEnvelope(@event));

            Assert.Equal("Berlin", result);
        }
Пример #25
0
        public void Should_return_string_when_object()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city", new ContentFieldData()
                              .AddValue("iv", new JObject(
                                            new JProperty("name", "Berlin"))))
            };

            var result = sut.FormatString("$CONTENT_DATA.city.iv", AsEnvelope(@event));

            Assert.Equal(JObject.FromObject(new { name = "Berlin" }).ToString(Formatting.Indented), result);
        }
Пример #26
0
        public async Task Should_return_undefined_when_undefined()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city",
                              new ContentFieldData()
                              .AddValue("iv", JValue.CreateUndefined()))
            };

            var result = await sut.FormatStringAsync("$CONTENT_DATA.city.iv", AsEnvelope(@event));

            Assert.Equal("UNDEFINED", result);
        }
Пример #27
0
        public void Should_replacecontent_url_from_event()
        {
            var url = "http://content";

            A.CallTo(() => urlGenerator.GenerateContentUIUrl(appId, schemaId, contentId))
            .Returns(url);

            var @event = new ContentCreated {
                AppId = appId, ContentId = contentId, SchemaId = schemaId
            };

            var result = sut.FormatString("Go to $CONTENT_URL", AsEnvelope(@event));

            Assert.Equal($"Go to {url}", result);
        }
Пример #28
0
        public async Task Should_return_plain_value_from_object_when_found()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city",
                              new ContentFieldData()
                              .AddValue("iv", new JObject(
                                            new JProperty("name", "Berlin"))))
            };

            var result = await sut.FormatStringAsync("$CONTENT_DATA.city.iv.name", AsEnvelope(@event));

            Assert.Equal("Berlin", result);
        }
Пример #29
0
        public async Task Should_return_undefined_when_property_not_found()
        {
            var @event = new ContentCreated
            {
                Data =
                    new NamedContentData()
                    .AddField("city",
                              new ContentFieldData()
                              .AddValue("iv", new JObject(
                                            new JProperty("name", "Berlin"))))
            };

            var result = await sut.FormatStringAsync("$CONTENT_DATA.city.de.Name", AsEnvelope(@event));

            Assert.Equal("UNDEFINED", result);
        }
Пример #30
0
        protected Task On(ContentCreated @event, EnvelopeHeaders headers)
        {
            return(ForSchemaAsync(@event.AppId, @event.SchemaId.Id, (collection, schema) =>
            {
                return collection.CreateAsync(@event, headers, content =>
                {
                    content.SchemaId = @event.SchemaId.Id;

                    SimpleMapper.Map(@event, content);

                    var idData = @event.Data?.ToIdModel(schema.SchemaDef, true);

                    content.DataText = idData?.ToFullText();
                    content.IdData = idData;
                    content.ReferencedIds = idData?.ToReferencedIds(schema.SchemaDef);
                });
            }));
        }