Ejemplo n.º 1
0
        public void SimpleSchema()
        {
            var language = new LanguageSchemaBuilder().Add <DemoAgg>().Build();

            language.Aggregates.Count.ShouldBe(1);

            Should.NotThrow(() => language.GetAggregate(typeof(DemoAgg)));
            var aggInfo = language.GetAggregate(typeof(DemoAgg));

            language.GetAggregate(typeof(DemoAgg)).ShouldBe(aggInfo);
            aggInfo.Type.ShouldBe(typeof(DemoAgg));
            aggInfo.Name.ShouldBe(nameof(DemoAgg));

            aggInfo.Commands.ShouldNotBeNull();
            aggInfo.Commands.Count.ShouldBe(1);
            var cmdInfo = aggInfo.Commands.Single();

            language.GetCommand(typeof(DemoAgg.Cmd)).ShouldBe(cmdInfo);
            language.FindCommand("DemoAgg", "Cmd").Type.ShouldBe(typeof(DemoAgg.Cmd));
            cmdInfo.Type.ShouldBe(typeof(DemoAgg.Cmd));
            cmdInfo.Name.ShouldBe(nameof(DemoAgg.Cmd));

            aggInfo.Views.ShouldNotBeNull();
            aggInfo.Views.Count.ShouldBe(1);
            var viewInfo = aggInfo.Views.Single();

            language.GetAggregateView(typeof(DemoAgg.View)).ShouldBe(viewInfo);
        }
Ejemplo n.º 2
0
        public void EmptySchema()
        {
            var schema = new LanguageSchemaBuilder().Build();

            schema.Aggregates.ShouldNotBeNull();
            schema.Aggregates.ShouldBeEmpty();

            Should.Throw <ArgumentNullException>(() => schema.GetAggregate(null));
            Should.Throw <ArgumentNullException>(() => schema.GetCommand(null));
            Should.Throw <ArgumentNullException>(() => schema.GetQuery(null));

            var anyTermType = typeof(Object); // no matter what it is because language is empty

            Should.Throw <ArgumentOutOfRangeException>(() => schema.GetAggregate(anyTermType));
            Should.Throw <ArgumentOutOfRangeException>(() => schema.GetCommand(anyTermType));
            Should.Throw <ArgumentOutOfRangeException>(() => schema.GetQuery(anyTermType));

            var anyTermName = "sdfsdf"; // no matter what it is because language is empty

            Should.Throw <LanguageSchemaException>(() => schema.FindCommand(anyTermName, anyTermName));
        }
Ejemplo n.º 3
0
        public void SimpleSchema()
        {
            var language = new LanguageSchemaBuilder().Add <DemoAgg>().Build();
            var logic    = new LogicSchemaBuilder(language)
                           .Add <DemoAggLogic>()
                           .Add <DemoSaga>()
                           .Add <DemoSvc>()
                           .Build();

            logic.Aggregates.Count.ShouldBe(1);
            logic.Sagas.Count.ShouldBe(1);
            logic.Services.Count.ShouldBe(1);

            var aggInfo = language.GetAggregate(typeof(DemoAgg));

            Should.NotThrow(() => logic.GetAggregate(aggInfo));
            var aggLogicInfo = logic.GetAggregate(aggInfo);

            logic.GetAggregate(aggInfo).ShouldBe(aggLogicInfo);
            aggLogicInfo.Type.ShouldBe(typeof(DemoAggLogic));
            aggLogicInfo.Name.ShouldBe(nameof(DemoAgg));

            aggLogicInfo.Events.ShouldNotBeNull();
            aggLogicInfo.Events.Count.ShouldBe(1);
            var aggEventInfo = aggLogicInfo.Events.Single();

            aggEventInfo.Type.ShouldBe(typeof(DemoAggLogic.AggEvent));
            aggEventInfo.Name.ShouldBe(nameof(DemoAggLogic.AggEvent));

            Should.NotThrow(() => logic.GetReactingSagas(aggEventInfo));
            var sagas = logic.GetReactingSagas(aggEventInfo);

            sagas.ShouldNotBeNull();
            sagas.Length.ShouldBe(1);
            var saga = sagas.Single();

            logic.Sagas.Single().ShouldBe(saga);
            saga.Type.ShouldBe(typeof(DemoSaga));
            saga.Name.ShouldBe(nameof(DemoSaga));
            saga.AggregateEvents.ShouldNotBeNull();
            saga.AggregateEvents.Count.ShouldBe(1);
            saga.AggregateEvents.Single().ShouldBe(aggEventInfo);

            var svc = logic.Services.Single();

            svc.Type.ShouldBe(typeof(DemoSvc));
            svc.Name.ShouldBe(nameof(DemoSvc));
        }