当前位置: 首页>>代码示例>>C#>>正文


C# EventPublisher.Publish方法代码示例

本文整理汇总了C#中EventPublisher.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# EventPublisher.Publish方法的具体用法?C# EventPublisher.Publish怎么用?C# EventPublisher.Publish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventPublisher的用法示例。


在下文中一共展示了EventPublisher.Publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Context

			protected override void Context()
			{
				EventPublisher publisher = new EventPublisher();

				publisher.Publish(new EventData("1st"));
				publisher.Publish(new EventData("2nd"));

				eventData = publisher.GetMostRecentPublication<EventData>();
			}
开发者ID:derickbailey,项目名称:appcontroller.cf,代码行数:9,代码来源:CachedEventDataSpecs.cs

示例2: Main

        private static void Main(string[] args)
        {
            var testEventHappened = new TestEventHappened
            {
                Message = "Hello Eventing World!"
            };
            var eventPublisher = new EventPublisher<TestEventHappened>();

            eventPublisher.Publish<object>(testEventHappened);
        }
开发者ID:rajeshdlabz,项目名称:leanandmean,代码行数:10,代码来源:Program.cs

示例3: EventEnvelopeCannotBeNull

            public void EventEnvelopeCannotBeNull()
            {
                var messageFactory = new Mock<ICreateMessages>();
                var messageBus = new Mock<ISendMessages<EventEnvelope>>();
                var publisher = new EventPublisher(messageFactory.Object, messageBus.Object);

                var ex = Assert.Throws<ArgumentNullException>(() => publisher.Publish(HeaderCollection.Empty, null));

                Assert.Equal("payload", ex.ParamName);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:10,代码来源:EventPublisherTests.cs

示例4: HeadersCanBeNull

            public void HeadersCanBeNull()
            {
                var messageFactory = new Mock<ICreateMessages>();
                var messageBus = new Mock<ISendMessages<EventEnvelope>>();
                var publisher = new EventPublisher(messageFactory.Object, messageBus.Object);

                publisher.Publish(null, EventEnvelope.Empty);

                messageFactory.Verify(mock => mock.Create(null, EventEnvelope.Empty), Times.Once);
                messageBus.Verify(mock => mock.Send(It.IsAny<Message<EventEnvelope>>()), Times.Once);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:11,代码来源:EventPublisherTests.cs

示例5: EventPublisherPublish_UnitTest_RegisteredType_FindsSubjectAndInvokesOnNext

        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_UnitTest_RegisteredType_FindsSubjectAndInvokesOnNext()
        // ReSharper restore InconsistentNaming
        {
            var memo = new DesignValidationMemo();

            var publisher = new EventPublisher();
            var subscription = publisher.GetEvent<DesignValidationMemo>().Subscribe(m => Assert.AreSame(memo, m));

            publisher.Publish(memo);
            subscription.Dispose();
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:12,代码来源:EventPublisherTests.cs

示例6: Context

            protected override void Context()
            {
                _handler = MockRepository.GenerateMock<IEventHandler<EventData>>();

                IEventPublisher eventPublisher = new EventPublisher();

                eventPublisher.RegisterHandler(_handler);
                eventPublisher.UnregisterHandler(_handler);

                eventPublisher.Publish(new EventData("My Event Data"));
            }
开发者ID:panshuiqing,项目名称:appcontroller,代码行数:11,代码来源:EventAggregatorSpecs.cs

示例7: Context

			protected override void Context()
			{
				_handler = MockRepository.GenerateMock<IEventHandler<EventData>>();
				_handler.Stub(h => h.Handle(null)).IgnoreArguments().Callback(delegate(EventData data)
					{
						_eventData = data.SomeData;
						return true;
					});

				IEventPublisher eventPublisher = new EventPublisher();
				eventPublisher.RegisterHandler(_handler);
				eventPublisher.Publish(new EventData("My Event Data"));
			}
开发者ID:derickbailey,项目名称:appcontroller.cf,代码行数:13,代码来源:EventAggregatorSpecs.cs

示例8: Context

			protected override void Context()
			{
				_handler = SetupHandlerToThrowException();

				IEventPublisher eventPublisher = new EventPublisher();

				eventPublisher.OnHandlerError(ex =>
					{
						handlerExecuted = true;
						caughtException = ex;
					});
				
				eventPublisher.RegisterHandler(_handler);
				eventPublisher.Publish(new EventData());
			}
开发者ID:derickbailey,项目名称:appcontroller.cf,代码行数:15,代码来源:ExceptionHandlingSpecs.cs

示例9: ResourceModel_DesignValidationServicePublishingMemo_UpdatesErrors

        public void ResourceModel_DesignValidationServicePublishingMemo_UpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) =>
            {
                Assert.AreEqual(memo.Errors.Count, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

                foreach (var error in memo.Errors)
                {
                    var modelError = model.Errors.FirstOrDefault(me => me.ErrorType == error.ErrorType && me.Message == error.Message);
                    Assert.AreSame(error, modelError, "OnDesignValidationReceived did not set the error.");
                }
            };

            eventPublisher.Publish(pubMemo);
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:33,代码来源:ResourceModelTest.cs

示例10: ResourceModel_DesignValidationServicePublishingMemo_NoInstanceID_DoesNotUpdatesErrors

        public void ResourceModel_DesignValidationServicePublishingMemo_NoInstanceID_DoesNotUpdatesErrors()
        {
            //Setup();
            var instanceID = Guid.NewGuid();
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error." });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error." });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);

            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            model.OnDesignValidationReceived += (sender, memo) => Assert.AreEqual(0, model.Errors.Count, "OnDesignValidationReceived did not update the number of errors correctly.");

            eventPublisher.Publish(pubMemo);
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:24,代码来源:ResourceModelTest.cs

示例11: EventPublisherPublish_UnitTest_UnregisteredType_DoesNotFindSubject

        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_UnitTest_UnregisteredType_DoesNotFindSubject()
        // ReSharper restore InconsistentNaming
        {
            var memo = new Memo();

            var publisher = new EventPublisher();

            publisher.Publish(memo);
            Assert.IsTrue(true);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:11,代码来源:EventPublisherTests.cs

示例12: ResourceModel_Environment_DesignValidationService_WiredUp

        public void ResourceModel_Environment_DesignValidationService_WiredUp()
        {
            var eventPublisher = new EventPublisher();

            var environmentID = Guid.NewGuid();
            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.ID).Returns(environmentID);
            environment.Setup(e => e.Connection.ServerEvents).Returns(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environment.Object, new Mock<IEventAggregator>().Object);

            var errors = model.GetErrors(instanceID);
            Assert.AreEqual(0, errors.Count);

            var err = new ErrorInfo
            {
                InstanceID = instanceID,
            };

            var memo = new DesignValidationMemo
            {
                InstanceID = environmentID,
                Errors = new List<IErrorInfo>
                {
                    err
                }
            };

            //------------Execute Test---------------------------
            eventPublisher.Publish(memo);

            //------------Assert Results-------------------------
            errors = model.GetErrors(instanceID);
            Assert.AreEqual(1, errors.Count);
            Assert.AreSame(err, errors[0]);
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:37,代码来源:ResourceModelTest.cs

示例13: EventPublisher

        public void EnvironmentTreeViewModel_PermissionsChanged_MemoIDEqualsEnvironmentServerId_UserPermissionChangesNonLocalHost()
        {
            //------------Setup for test--------------------------


            var resourceID = Guid.NewGuid();
            //var connectionServerId = Guid.NewGuid();
            var memoServerID = Guid.NewGuid();

            var pubMemo = new PermissionsModifiedMemo { ServerID = memoServerID };

            pubMemo.ModifiedPermissions.Add(new WindowsGroupPermission { ResourceID = resourceID, Permissions = Permissions.Execute });
            pubMemo.ModifiedPermissions.Add(new WindowsGroupPermission { ResourceID = resourceID, Permissions = Permissions.DeployTo });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);
            connection.SetupGet(c => c.ServerID).Returns(memoServerID);

            var srepo = new Mock<IStudioResourceRepository>();
            var repo = new Mock<IResourceRepository>();
#pragma warning disable 168
            var environment = new EnvironmentModel(Guid.NewGuid(), connection.Object, repo.Object, srepo.Object) { Name = "localhost" };
            connection.Raise(environmentConnection => environmentConnection.NetworkStateChanged += null, new NetworkStateEventArgs(NetworkState.Offline, NetworkState.Online));
#pragma warning restore 168
            connection.Setup(a => a.DisplayName).Returns("bob");
            //------------Execute Test---------------------------
            eventPublisher.Publish(pubMemo);
            srepo.Verify(a => a.UpdateRootAndFoldersPermissions(It.IsAny<Permissions>(), It.IsAny<Guid>(), true), Times.Never());
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:30,代码来源:EnvironmentModelTest.cs

示例14: ResourceModel_Rollback_FixedErrorsRestored

        public void ResourceModel_Rollback_FixedErrorsRestored()
        {
            //Setup();
            var eventPublisher = new EventPublisher();
            var environmentModel = CreateMockEnvironment(eventPublisher);

            var instanceID = Guid.NewGuid();
            var model = new ResourceModel(environmentModel.Object)
            {
                ID = instanceID
            };

            var hitCount = 0;
            model.OnDesignValidationReceived += (sender, memo) =>
            {
                switch (hitCount++)
                {
                    case 0:
                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;

                    case 1:
                        Assert.AreEqual(1, model.Errors.Count);
                        Assert.AreEqual(1, model.FixedErrors.Count);

                        model.Rollback();

                        Assert.AreEqual(2, model.Errors.Count);
                        Assert.AreEqual(0, model.FixedErrors.Count);
                        break;
                }
            };

            // Publish 2 errors
            var pubMemo = new DesignValidationMemo { InstanceID = instanceID };
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, Message = "Critical error.", InstanceID = instanceID });
            pubMemo.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Warning, Message = "Warning error.", InstanceID = instanceID });
            eventPublisher.Publish(pubMemo);

            // Fix 1 error and publish
            pubMemo.Errors.RemoveAt(1);
            eventPublisher.Publish(pubMemo);
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:44,代码来源:ResourceModelTest.cs

示例15: ClientSecurityService_PermissionsModified_NewPermissionsReceived_ShouldReplaceCurrentPermissions

        public void ClientSecurityService_PermissionsModified_NewPermissionsReceived_ShouldReplaceCurrentPermissions()
        {
            //------------Setup for test--------------------------
            var connection = new Mock<IEnvironmentConnection>();
            IEventPublisher eventPublisher = new EventPublisher();
            connection.Setup(c => c.ServerEvents).Returns(eventPublisher);
            var clientSecurityService = new TestClientSecurityService(connection.Object);
            var currentPermissions = new List<WindowsGroupPermission>();
            Guid resourceID = Guid.NewGuid();

            var resourcePermission = new WindowsGroupPermission();
            resourcePermission.ResourceID = resourceID;
            resourcePermission.Permissions = Permissions.View & Permissions.Execute;

            var serverPermission = new WindowsGroupPermission();
            serverPermission.ResourceID = Guid.Empty;
            serverPermission.Permissions = Permissions.DeployFrom & Permissions.DeployTo;
            serverPermission.IsServer = true;

            currentPermissions.Add(serverPermission);
            currentPermissions.Add(resourcePermission);
            clientSecurityService.SetCurrentPermissions(currentPermissions);
            clientSecurityService.ReadAsync().Wait();

            var changedPermissions = new List<WindowsGroupPermission>();

            var changedResourcePermission = new WindowsGroupPermission();
            changedResourcePermission.ResourceID = resourceID;
            changedResourcePermission.Permissions = Permissions.Contribute;

            var changedServerPermission = new WindowsGroupPermission();
            changedServerPermission.ResourceID = Guid.Empty;
            changedServerPermission.Permissions = Permissions.Administrator;
            changedServerPermission.IsServer = true;

            changedPermissions.Add(changedServerPermission);
            changedPermissions.Add(changedResourcePermission);

            var permissionsModifiedMemo = new PermissionsModifiedMemo();
            permissionsModifiedMemo.ModifiedPermissions = changedPermissions;
            //------------Execute Test---------------------------
            connection.Raise(environmentConnection => environmentConnection.PermissionsModified += null, null,changedPermissions);
            eventPublisher.Publish(permissionsModifiedMemo);
            //------------Assert Results-------------------------
            var updateResourcePermission = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == resourceID);
            var updateServerPermission = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == Guid.Empty);
            Assert.IsNotNull(updateResourcePermission);
            Assert.IsNotNull(updateServerPermission);
            Assert.AreEqual(Permissions.Contribute, updateResourcePermission.Permissions);
            Assert.AreEqual(Permissions.Administrator, updateServerPermission.Permissions);
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:51,代码来源:ClientSecurityServiceTests.cs


注:本文中的EventPublisher.Publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。