public void ShouldGetExpectedMessageWhenBroadcastTopicGivenMutilConsume() { var consume = new DataConsumer(); var consume2 = new DataConsumer(); var consume3 = new DataConsumer(); using (var host = new KnifeHost(new string[0], (build, sc) => { sc.AddSingleton <IEventConsumer>(consume); sc.AddSingleton <IEventConsumer>(consume2); sc.AddSingleton <IEventConsumer>(consume3); })) { var appLiftTime = host.GetService <IHostApplicationLifetime>(); var producer = host.GetService <IEventProducer>(); Task.WaitAll( Task.Run(host.Run), // wait 800ms for the consumes ready. Task.Delay(800).ContinueWith(_ => BroadcastTopicData(producer, 100)), Task.Delay(2000).ContinueWith(_ => appLiftTime.StopApplication()) ); } Assert.AreEqual(100, consume.Received.Count); Assert.AreEqual(100, consume2.Received.Count); Assert.AreEqual(100, consume3.Received.Count); }
public void ShouldGetExpectedMessageWhenEnqueueGivenMutilConsume() { var consume1 = new DataConsumer(); var consume2 = new DataConsumer(); var consume3 = new DataConsumer(); using (var host = new KnifeHost(new string[0], (build, sc) => { sc.AddSingleton <IEventConsumer>(consume1); sc.AddSingleton <IEventConsumer>(consume2); sc.AddSingleton <IEventConsumer>(consume3); })) { var appLiftTime = host.GetService <IHostApplicationLifetime>(); var producer = host.GetService <IEventProducer>(); EnqueueData(producer, 100); Task.WaitAll( Task.Run(host.Run), // wait 1500 ms to consume message Task.Delay(1500).ContinueWith(_ => appLiftTime.StopApplication()) ); } var consumeCount = consume1.Received.Count + consume2.Received.Count + consume3.Received.Count; Assert.AreEqual(100, consumeCount); var allReceived = consume1.Received.Concat(consume2.Received).Concat(consume3.Received); var countByKey = allReceived.Select(p => p.IntProp).Distinct().Count(); Assert.AreEqual(100, countByKey); }
public void ShouldGetZeroMessageWhenBroadcastTopicBeforeConsume() { var consume = new DataConsumer(); using (var host = new KnifeHost(new string[0], (build, sc) => { sc.AddSingleton <IEventConsumer>(consume); })) { var appLiftTime = host.GetService <IHostApplicationLifetime>(); var producer = host.GetService <IEventProducer>(); BroadcastTopicData(producer, 100); Task.WaitAll( Task.Run(host.Run), Task.Delay(2000).ContinueWith(_ => appLiftTime.StopApplication()) ); } Assert.AreEqual(0, consume.Received.Count); }
public void ShouldGetInstanceIfNoFilters() { using (var host = new KnifeHost( new Dictionary <string, object> { })) { var instance = host.GetService <MyService1>(); Assert.IsNotNull(instance); } }
public void ShouldNotGetInstanceWhenFilterTypeByWildcard() { using (var host = new KnifeHost( new Dictionary <string, object> { ["Knife:Ignores:Types:0"] = "*.MyService?" })) { var instance = host.GetService <MyService1>(); Assert.IsNull(instance); } }
public void ShouldNotGetInstanceWhenFilterTypeByName() { using (var host = new KnifeHost( new Dictionary <string, object> { ["Knife:Ignores:Types:0"] = typeof(MyService1).FullName })) { var instance = host.GetService <MyService1>(); Assert.IsNull(instance); } }
public void ShouldNotGetInstanceWhenFilterAssemblyByName() { using (var host = new KnifeHost( new Dictionary <string, object> { ["Knife:Ignores:Assemblies:0"] = this.GetType().Assembly.GetName().Name })) { var instance = host.GetService <MyService1>(); Assert.IsNull(instance); } }
public void ShouldNotGetInstanceWhenFilterAssemblyByWildcard() { using (var host = new KnifeHost( new Dictionary <string, object> { ["Knife:Ignores:Assemblies:0"] = "*" })) { var instance = host.GetService <MyService1>(); instance.Should().NotBeNull(); } }
public void ShouldNotBeNullWhenHasDefineMySqlDbContextClassAndWithInjectType() { var args = new Dictionary <string, object> { ["ConnectionStrings:TestContext2"] = "Server=localhost;Database=SequenceContext; User=root;Password=;" }; using (var host = new KnifeHost(args)) { Assert.IsNotNull(host.GetService <TestDbContext2>()); } }