public async Task HandleIsOnlyCalledOnce() { var dateTimeOffset = 1; var domainEventWrapper = new SubscribedDomainEventWrapper { OverallVersion = dateTimeOffset, DomainEvent = new TestEv2(Guid.NewGuid()) }; var handleAsync = new Handler1(); var handleAsync2 = new Handler2(); var eventDelegateHandler1 = new AsyncEventHandler <Handler1, TestEv2>( new VersionRepositoryMongoDb(EventMongoDb), new EventFeedMock(dateTimeOffset, domainEventWrapper), handleAsync); var eventDelegateHandler2 = new AsyncEventHandler <Handler1, TestEv2>( new VersionRepositoryMongoDb(EventMongoDb), new EventFeedMock(dateTimeOffset, domainEventWrapper), handleAsync2); await eventDelegateHandler1.UpdateAsync(); await eventDelegateHandler2.UpdateAsync(); Assert.AreEqual(1, handleAsync.TimesCalled); Assert.AreEqual(1, handleAsync2.TimesCalled); }
public void EventUtility_RaiseAsync_2() { Task task = Handler1.RaiseAsync(this); Assert.IsNotNull(task); task.Wait(); }
public async Task AddRebus_ConfigureRebusOnce_StartsAndConfiguresBus() { // Arrange var services = new ServiceCollection(); var testHandler = new Handler1(2); // Act services .AddSingleton <IHandleMessages <Message1> >(testHandler) .AddRebus(config => config .Logging(l => l.None()) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(false), "Messages")) .Routing(r => r.TypeBased().MapAssemblyOf <Message1>("Messages"))); var provider = services .BuildServiceProvider() .UseRebus(); var rebus = provider.GetRequiredService <IBus>(); await rebus.Send(new Message1()); await rebus.Send(new Message1()); // Assert await Task.WhenAny(testHandler.CountReached, Task.Delay(3000)); (provider.GetRequiredService <IHandleMessages <Message1> >() as Handler1) .HandleCount.Should().Be(2); }
// Use this for initialization void Start() { IHandler handle2 = new Handler2(); IHandler handle1 = new Handler1(handle2); handle1.HandleRequest(20); }
public void Init() { var kernel = new StandardKernel(new SampleDatastoreModule()); // Rebind kernel.Rebind <ISampleContext>().ToConstant(new MockSampleContext()); kernel.Rebind <ILogger>().ToConstant(_logger.Object); // 生成一些数据 var data = new List <Animal> { new Animal { AnimalKey = 1, BirthDate = _date, Sex = Sex.Female, Species = Species.Cattle }, new Animal { AnimalKey = 2, BirthDate = _date.AddYears(1), Sex = Sex.Male, Species = Species.Deer }, new Animal { AnimalKey = 3 } }; data.ForEach(x => kernel.Get <ISampleContext>().Animals.Attach(x)); // new一个新的Handler做测试之用 _handler1 = kernel.Get <Handler1>(); }
public void test() { Handler1 a = new Handler1(); // System.Web.HttpContext b = new System.Web.HttpContext(new System.Web.HttpRequest("", "www.google.com", ""), new System.Web.HttpResponse(new System.IO.StringWriter())); a.ProcessRequest(System.Web.HttpContext.Current); }
public void EventUtility_RaiseAsync_1() { EventArgs args = new EventArgs(); Task task = Handler1.RaiseAsync(this, args); Assert.IsNotNull(task); task.Wait(); }
static void Main(string[] args) { Handler1 Handler1 = new Handler1(); Handler2 Handler2 = new Handler2(); _Counter.Reached += Handler1.Message; _Counter.Reached += Handler2.Message; _Counter.Count(); }
static void Main(string[] args) { Counter counter = new Counter(); Handler1 handler1 = new Handler1(); Handler2 handler2 = new Handler2(); counter.OnValueReached += handler1.Message; counter.OnValueReached += handler2.Message; counter.Count(30); }
static void Main() { MyStopWatch stopwatch = new MyStopWatch(); Handler1 handler1 = new Handler1(); Handler2 handler2 = new Handler2(); Handler3 handler3 = new Handler3(); stopwatch.Event += handler1.OnTimer; stopwatch.Event += handler2.OnTimer; stopwatch.Event += handler3.OnTimer; stopwatch.Start(new TimeSpan(0, 0, 5)); }
static void UseEvent() { ClassCounter Counter = new ClassCounter(); Handler1 Handler1 = new Handler1(); Handler2 Handler2 = new Handler2(); Counter.onCount += Handler1.Message; Counter.onCount += Handler2.Message; //Запустили счетчик Counter.Counter(); }
public void Should_resolve_instance_of_Handler1_and_return_it() { // Arrange var expectedHandler = new Handler1(); var convention = new DefaultPolicyViolationHandlerIsOfTypeConvention <Handler1>(); convention.PolicyViolationHandlerProvider = t => expectedHandler; var exception = TestDataFactory.CreateExceptionFor(new IgnorePolicy()); // Act var handler = convention.GetHandlerFor(exception); // Assert Assert.That(handler, Is.EqualTo(expectedHandler)); }
private void GetHandlerAsUsual() { Console.WriteLine("GetHandlerAsUsual"); // 将数据存入Fake数据库 var set = new Mock <DbSet <Animal> >().SetupData(_data); // Mock一个Context var context = new Mock <ISampleContext>(); context.Setup(c => c.Animals).Returns(set.Object); // 第一种方法: new一个新的Handler做测试之用 _animalRepository = new AnimalRepository(context.Object); _handler1 = new Handler1(_animalRepository, _logger.Object); }
public void AddRebus_ConfigureRebusManyTimes_Throws() { // Arrange var services = new ServiceCollection(); var testHandler = new Handler1(2); // Act new Action(() => { services .AddSingleton <IHandleMessages <Message1>, Handler1>() .AddRebus(config => config .Logging(l => l.None()) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(false), "Messages"))) .AddRebus(config => config .Routing(r => r.TypeBased().MapAssemblyOf <Message1>("Messages"))); }).ShouldThrow <InvalidOperationException>(); }
public void Should_resolve_instances_from_container() { // Arrange var expectedHandler = new Handler1(); FakeIoC.GetAllInstancesProvider = () => new List <object> { expectedHandler }; SecurityConfigurator.Configure(configuration => configuration.ResolveServicesUsing(FakeIoC.GetAllInstances)); var convention = new DefaultPolicyViolationHandlerIsOfTypeConvention <Handler1>(); var exception = TestDataFactory.CreateExceptionFor(new IgnorePolicy()); // Act var handler = convention.GetHandlerFor(exception); // Assert Assert.That(handler, Is.EqualTo(expectedHandler)); }
private void GetHandlerByNinject() { var kernel = new StandardKernel(new SampleDatastoreModule()); // 将数据存入Fake数据库 var set = new Mock <DbSet <Animal> >().SetupData(_data); // Mock一个Context var context = new Mock <ISampleContext>(); context.Setup(c => c.Animals).Returns(set.Object); // Rebind kernel.Rebind <ISampleContext>().ToConstant(context.Object); kernel.Rebind <ILogger>().ToConstant(_logger.Object); // 第二种方法: 使用Ninject去获得_handler1, 应该更好 _handler1 = kernel.Get <Handler1>(); }
static void Main(string[] args) { WriteArguments(args); Handler1 handler1 = new Handler1(); Handler2 handler2 = new Handler2(); Handler3 handler3 = new Handler3(); MyServiceNormal myServiceNormal = new MyServiceNormal(handler1, handler2, handler3); myServiceNormal.DoSomething(); WriteSeparator(); HandlerMediator handlerMediator = new HandlerMediator(handler1, handler2, handler3); MyServiceWithMediator myServiceWithMediator = new MyServiceWithMediator(handlerMediator); myServiceWithMediator.DoSomething(); }
/// <summary> /// 异步调用 /// </summary> public void DoAsynAction() { Handler1 handler1 = new Handler1(AsynDemo1); handler1.BeginInvoke(null, null); Handler2 handler2 = new Handler2(AsynDemo2); handler2.BeginInvoke("string", null, null); Handler3 handler3 = new Handler3(AsynDemo3); //handler3.BeginInvoke(null, null); IAsyncResult result3 = handler3.BeginInvoke(null, null); Handler4 handler4 = new Handler4(AsynDemo4); //handler4.BeginInvoke("string", null, null); IAsyncResult result4 = handler4.BeginInvoke("string", null, null); Handler5 handler5 = new Handler5(AsynDemo5); //handler5.BeginInvoke("", 0, null, null); IAsyncResult result5 = handler5.BeginInvoke("string", 0, null, null); }
public async Task AddRebus_ConfigureRebusOnce_StartsAndConfiguresBus() { var handledMessages = new ConcurrentQueue <string>(); // Arrange var services = new ServiceCollection(); var testHandler = new Handler1(2); // Act services .AddSingleton(handledMessages) //.AddSingleton<IHandleMessages<Message1>>(testHandler) .AddTransient <IHandleMessages <TextMessage>, TextMessageHandler>() .AddRebus(config => config .Logging(l => l.None()) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "Messages")) .Routing(r => r.TypeBased().MapAssemblyOf <Message1>("Messages"))); var provider = services .BuildServiceProvider() .UseRebus(); var rebus = provider.GetRequiredService <IBus>(); await rebus.Send(new TextMessage("HEJ")); await rebus.Send(new TextMessage("MED")); await rebus.Send(new TextMessage("DIG")); // Assert await handledMessages.WaitUntil(q => q.Count >= 3); await Task.Delay(TimeSpan.FromSeconds(0.1)); Assert.That(handledMessages, Is.EqualTo(new[] { "HEJ", "MED", "DIG" })); }
public RequestHandler1 <T>?Handle(Handler1 handler) { _executor = (request, param1, mediaTypeMapper1, errorHandler1, logger1) => RequestExecutor.ExecuteRequest(() => handler.Invoke(param1), errorHandler1, logger1); return(this); }
/// <summary> /// Create an event with one argeter. /// </summary> /// <typearg name="TArg1"></typearg> /// <arg name="handler"></arg> /// <arg name="arg1"></arg> /// <returns></returns> public static EventBase CreateEvent <TArg1>(int eventId, Handler1 <TArg1> handler, TArg1 arg1) { return(new Event1 <TArg1>(eventId, handler, arg1)); }
public void EventUtility_Raise_3() { Handler1.Raise(this); }
public void EventUtility_Raise_1() { EventArgs args = new EventArgs(); Handler1.Raise(this, args); }
public void hand() { Handler1?.Invoke(this, EventArgs.Empty); }
public HandlerMediator(Handler1 handler1, Handler2 handler2, Handler3 handler3) { _handler1 = handler1; _handler2 = handler2; _handler3 = handler3; }
/// <summary> /// Initializes a new instance of the Event1 class. /// </summary> /// <arg name="handler"></arg> /// <arg name="arg1"></arg> public Event1(int evenId, Handler1 <TArg1> handler, TArg1 arg1) : base(evenId) { this.handler = handler; this.arg1 = arg1; }
public MyServiceNormal(Handler1 handler1, Handler2 handler2, Handler3 handler3) { _handler1 = handler1; _handler2 = handler2; _handler3 = handler3; }