Exemple #1
0
        public void SetUp()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("testsettings.json")
                                .AddUserSecrets <PublishWithAzureTopicTest>()
                                .Build();

            if (string.IsNullOrEmpty(configuration["azureTopicSender:sendConnectionString"]))
            {
                Assert.Ignore("Azure Service Bus settings not found in user secrets.");
            }

            var services = new ServiceCollection();

            services.AddEventsContext <TestEventsContext>(options =>
            {
                options.UseAzureTopicEventReceiver(configuration.GetSection("azureTopicReceiver"));
                options.UseAzureTopicEventSender(configuration.GetSection("azureTopicSender"));
            });
            services.AddSingleton <SubscribingService>();

            _serviceProvider = services.BuildServiceProvider();

            _testEventsContext           = _serviceProvider.GetRequiredService <TestEventsContext>();
            _eventsScope                 = _serviceProvider.CreateScope().ServiceProvider.GetRequiredService <EventsScope>();
            _eventReceiversHostedService = _serviceProvider.GetRequiredService <IHostedService>();
        }
Exemple #2
0
        public void AddWithEventsAttachedTo_ShouldReplaceServiceDescriptorsWithFactoryThatAttachesTheService(
            [Values] ServiceDescriptorImplementation serviceDescriptorImplementation
            )
        {
            var serviceProviderMock          = new Mock <IServiceProvider>(MockBehavior.Strict);
            var eventsContextMock            = new Mock <TestEventsContext>(MockBehavior.Strict);
            var scopedAppServiceProviderMock = new Mock <IScopedAppServiceProvider>(MockBehavior.Strict);
            var eventsScope = new EventsScope(scopedAppServiceProviderMock.Object);

            eventsContextMock
            .Setup(x => x.Attach(It.IsAny <TestService1>(), eventsScope))
            .Verifiable();

            serviceProviderMock
            .Setup(x => x.GetService(typeof(TestEventsContext)))
            .Returns(eventsContextMock.Object)
            .Verifiable();

            serviceProviderMock
            .Setup(x => x.GetService(typeof(EventsScope)))
            .Returns(eventsScope)
            .Verifiable();

            _serviceCollection.AddWithEventsAttachedTo <TestEventsContext>(() =>
            {
                switch (serviceDescriptorImplementation)
                {
                case ServiceDescriptorImplementation.Type:
                    _serviceCollection.AddSingleton <TestService1>();
                    break;

                case ServiceDescriptorImplementation.Factory:
                    _serviceCollection.AddSingleton(x => new TestService1());
                    break;

                case ServiceDescriptorImplementation.Instance:
                    _serviceCollection.AddSingleton(new TestService1());
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        nameof(serviceDescriptorImplementation),
                        serviceDescriptorImplementation,
                        null
                        );
                }
            });

            var factory = _serviceCollection.First().ImplementationFactory;

            var service = factory(serviceProviderMock.Object);

            Assert.That(service, Is.Not.Null);

            serviceProviderMock.Verify();
            eventsContextMock.Verify();
        }
Exemple #3
0
 public AppDbContext(
     AppEventsContext appEventsContext,
     EventsScope eventsScope,
     DbContextOptions <AppDbContext> options
     ) : base(options)
 {
     _appEventsContext = appEventsContext;
     _eventsScope      = eventsScope;
 }
Exemple #4
0
        public void SetUp()
        {
            var services = new ServiceCollection();

            services.AddEventsContext <TestEventsContext>(options => { });

            var serviceProvider = services.BuildServiceProvider();

            _testEventsContext = serviceProvider.GetService <TestEventsContext>();
            _eventsScope       = serviceProvider.CreateScope().ServiceProvider.GetRequiredService <EventsScope>();
        }
Exemple #5
0
        public static TestEntity AttachAndRaiseEvent(EventsContext eventsContext, EventsScope eventsScope)
        {
            var entity = new TestEntity
            {
                Id = _defaultTestEntityId
            };

            eventsContext.Attach(entity, eventsScope);

            entity.RaiseEvent(_defaultTestEventArgsValue);

            return(entity);
        }
Exemple #6
0
        private void SetUpContext(TestRunParameters testRunParameters)
        {
            var services = new ServiceCollection();

            services.AddEventsContext <TestEventsContext>(options => { });

            services.AddSingleton(testRunParameters);

            services.AddScoped <ScopedSubscribingService>();
            services.AddSingleton <SingletonSubscribingService>();
            _serviceProvider = services.BuildServiceProvider();

            _entity = new TestEntity();

            var serviceScope = _serviceProvider.CreateScope();

            _scopedSubscribingService    = serviceScope.ServiceProvider.GetRequiredService <ScopedSubscribingService>();
            _singletonSubscribingService = serviceScope.ServiceProvider.GetRequiredService <SingletonSubscribingService>();
            _context     = serviceScope.ServiceProvider.GetRequiredService <TestEventsContext>();
            _eventsScope = serviceScope.ServiceProvider.GetRequiredService <EventsScope>();

            _context.Attach(_entity, _eventsScope);
        }
Exemple #7
0
        private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e)
        {
            if (e.type == EventType.Repaint)
            {
                mousePosition = e.mousePosition;
            }

            if (Event.current.keyCode == KeyCode.Delete)
            {
                for (var i = 0; i < SelectedNodes.Count; i++)
                {
                    RemoveNode(SelectedNodes[SelectedNodes.Count - 1].NodeData, editorEvents);
                }
            }

            for (var i = 0; i < Nodes.Count; i++)
            {
                var nodeRect     = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY);
                var deleteRect   = Nodes[i].GetDeleteRect(EditorData.GetConstellationEditorConfig());
                var questionRect = Nodes[i].GetQuestionRect(EditorData.GetConstellationEditorConfig());
                var resizeRect   = Nodes[i].GetResizeRect(EditorData.GetConstellationEditorConfig());

                if (nodeRect.Contains(mousePosition))
                {
                    if (mousePressed)
                    {
                        requestRepaint();
                        if (e.control || SelectedNodes.Count == 0)
                        {
                            SelectedNodes.Add(Nodes[i]);
                            Nodes[i].SelectedNode();
                        }
                        else if (SelectedNodes.Count <= 1)
                        {
                            foreach (var selectedNodes in SelectedNodes)
                            {
                                selectedNodes.UnselectNode();
                            }
                            SelectedNodes.Clear();
                            SelectedNodes.Add(Nodes[i]);
                            Nodes[i].SelectedNode();
                        }

                        for (var j = 0; j < Nodes[i].GetInputs().Length; j++)
                        {
                            var inputRect = Nodes[i].GetInputRect(j, EditorData.GetConstellationEditorConfig());
                            if (inputRect.Contains(mousePosition))
                            {
                                Links.AddLinkFromInput(Nodes[i].GetInputs()[j],
                                                       (ConstellationEditorEvents.EditorEventType editorEventType, string message) =>
                                {
                                    editorEvents(editorEventType, message);
                                    if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded)
                                    {
                                        UpdateGenericNodeByLinkGUID(message);
                                    }
                                });
                            }
                        }

                        for (var j = 0; j < Nodes[i].GetOutputs().Length; j++)
                        {
                            var outputRect = Nodes[i].GetOuptputRect(j, EditorData.GetConstellationEditorConfig());
                            if (outputRect.Contains(mousePosition))
                            {
                                Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j],
                                                        (ConstellationEditorEvents.EditorEventType editorEventType, string message) =>
                                {
                                    editorEvents(editorEventType, message);
                                    if (editorEventType == ConstellationEditorEvents.EditorEventType.LinkAdded)
                                    {
                                        UpdateGenericNodeByLinkGUID(message);
                                    }
                                });
                            }
                        }

                        if (deleteRect.Contains(mousePosition) && mouseButtonDown)
                        {
                            RemoveNode(Nodes[i].NodeData, editorEvents);
                            return;
                        }

                        if (questionRect.Contains(mousePosition) && mouseButtonDown)
                        {
                            editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName());
                            return;
                        }

                        for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++)
                        {
                            var attributeRect = Nodes[i].GetParameterRect(j, EditorData.GetConstellationEditorConfig());
                            if (attributeRect.Contains(mousePosition))
                            {
                                editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Attribute edited");
                                currentEventScope = EventsScope.EditingAttributes;
                                return;
                            }
                        }

                        if (mouseButtonDown)
                        {
                            if (resizeRect.Contains(mousePosition))
                            {
                                currentEventScope = EventsScope.Resizing;
                                return;
                            }
                            editorEvents(ConstellationEditorEvents.EditorEventType.AddToUndo, "Node moved");
                            SetNodeToFirst(Nodes[i]);
                            currentEventScope = EventsScope.Dragging;
                            return;
                        }
                    }
                }
                else if (mousePressed && e.mousePosition.x != mouseClickStartPosition.x && e.mousePosition.y != mouseClickStartPosition.y)
                {
                    currentEventScope = EventsScope.Selecting;
                }
            }

            if (e.MouseUp() && e.button != 2)
            {
                foreach (var node in SelectedNodes)
                {
                    node.UnselectNode();
                }
                SelectedNodes.Clear();
            }
        }
Exemple #8
0
        public void Draw(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents callback, ConstellationEditorStyles constellationEditorStyles, out Vector2 windowSize, out Vector2 scrollPosition)
        {
            mouseButtonDown = false;
            //scroll bar
            ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition, GUILayout.Width(windowSizeX), GUILayout.Height(windowSizeY));
            GUILayoutOption[] options = { GUILayout.Width(editorScrollSize.x), GUILayout.Height(editorScrollSize.y) };
            editorScrollSize = new Vector2(farNodeX + 400, farNodeY + 400);
            windowSize       = editorScrollSize;
            scrollPosition   = ScrollPosition;
            EditorGUILayout.LabelField("", options);
            var backgroundTint = Color.white;

            if (ConstellationScript.IsInstance && ConstellationScript.IsDifferentThanSource)
            {
                backgroundTint = Color.yellow;
            }
            background.DrawBackgroundGrid(windowSizeX, windowSizeY, ScrollPosition.x, ScrollPosition.y, backgroundTint);
            Event e = Event.current;
            var   mouseJustRelease = false;

            if (e.type == EventType.MouseUp && Event.current.button == 0 && mousePressed == true)
            {
                mouseJustRelease = true;
                mousePressed     = false;
            }
            else if (e.type == EventType.MouseDown && Event.current.button == 0)
            {
                mouseClickStartPosition = e.mousePosition;
                mousePressed            = true;
                mouseButtonDown         = true;
            }

            switch (currentEventScope)
            {
            case EventsScope.Generic:
                UpdateGenericEvents(requestRepaint, callback, e);
                break;

            case EventsScope.Resizing:
                UpdateResizeEvents(requestRepaint, callback, e);
                break;

            case EventsScope.Dragging:
                UpdateDragEvents(requestRepaint, callback, e);
                break;

            case EventsScope.EditingAttributes:
                break;

            case EventsScope.Selecting:
                UpdateSelectEvent(requestRepaint, constellationEditorStyles);
                break;
            }

            //Needs to be called after the event scope otherwise quit button event is overriden by the node drag event
            if (mouseJustRelease)
            {
                currentEventScope = EventsScope.Generic;
                for (var i = 0; i < Nodes.Count; i++)
                {
                    Nodes[i].LockNodeSize();
                    Nodes[i].LockNodePosition();
                }
            }
            DrawNodes(e);
            Links.DrawLinks(requestRepaint,
                            callback,
                            constellationEditorStyles);
            DrawDescriptions(e);
            EditorGUILayout.EndScrollView();
            if (Event.current.button == 2)
            {
                ScrollPosition -= Event.current.delta * 0.5f;
                requestRepaint();
            }
            var script = ConstellationScript.script;

            if (script.Nodes != null)
            {
                script.Nodes = script.Nodes.OrderBy(x => x.YPosition).ToList();
            }
            if (script.Links != null)
            {
                script.Links = script.Links.OrderBy(x => x.outputPositionY).ToList();
            }
        }
Exemple #9
0
        private void UpdateGenericEvents(ConstellationEditorEvents.RequestRepaint requestRepaint, ConstellationEditorEvents.EditorEvents editorEvents, Event e)
        {
            for (var i = 0; i < Nodes.Count; i++)
            {
                var nodeRect     = Nodes[i].GetNodeRect(out float positionOffsetX, out float positionOffsetY);
                var deleteRect   = Nodes[i].GetDeleteRect();
                var questionRect = Nodes[i].GetQuestionRect();
                var resizeRect   = Nodes[i].GetResizeRect();

                if (nodeRect.Contains(e.mousePosition))
                {
                    if (mousePressed)
                    {
                        requestRepaint();
                        if (e.control)
                        {
                            SelectedNodes.Add(Nodes[i]);
                            SetNodeToFirst(Nodes[i]);
                        }
                        else
                        {
                            SelectedNodes.Clear();
                            SelectedNodes.Add(Nodes[i]);
                        }

                        for (var j = 0; j < Nodes[i].GetInputs().Length; j++)
                        {
                            var inputRect = Nodes[i].GetInputRect(j);
                            if (inputRect.Contains(e.mousePosition))
                            {
                                Links.AddLinkFromInput(Nodes[i].GetInputs()[j], editorEvents);
                            }
                        }

                        for (var j = 0; j < Nodes[i].GetOutputs().Length; j++)
                        {
                            var outputRect = Nodes[i].GetOuptputRect(j);
                            if (outputRect.Contains(e.mousePosition))
                            {
                                Links.AddLinkFromOutput(Nodes[i].GetOutputs()[j], editorEvents);
                            }
                        }

                        if (deleteRect.Contains(e.mousePosition) && mouseButtonDown)
                        {
                            RemoveNode(Nodes[i].NodeData, editorEvents);
                            return;
                        }

                        if (questionRect.Contains(e.mousePosition) && mouseButtonDown)
                        {
                            editorEvents(ConstellationEditorEvents.EditorEventType.HelpClicked, Nodes[i].GetName());
                            return;
                        }

                        for (var j = 0; j < Nodes[i].GetAttributeDatas().Length; j++)
                        {
                            var attributeRect = Nodes[i].GetAttributeRect(j);
                            if (attributeRect.Contains(e.mousePosition))
                            {
                                currentEventScope = EventsScope.EditingAttributes;
                                return;
                            }
                        }

                        if (mouseButtonDown)
                        {
                            if (resizeRect.Contains(e.mousePosition))
                            {
                                currentEventScope = EventsScope.Resizing;
                                return;
                            }
                            SetNodeToFirst(Nodes[i]);
                            currentEventScope = EventsScope.Dragging;
                            return;
                        }
                    }
                }
            }
            if (mousePressed)
            {
                SelectedNodes.Clear();
            }
        }