public void TestSync( ) { const string channelName = "myChannel"; using (var domain1 = new TestAppDomain( )) { Func <MessageEventArgs <TestMessage>, bool> predicate = m => m.Message.Action == "myMessage"; var instance1 = domain1.InjectType <SubscriberRefObject <TestMessage> >(channelName, RunAsDefaultTenant.DefaultTenantName, predicate); using (IDistributedMemoryManager manager = new RedisManager( )) { manager.Connect( ); const int count = 1000; using (IChannel <TestMessage> channel = manager.GetChannel <TestMessage>(channelName)) { RunSync(channel, count); instance1.MessageReceived.WaitOne(DefaultTimeout); Assert.Greater(instance1.ReceivedMessages.Count, 0); } } } }
public void UserAccountCacheTest( ) { const string username = "******"; const string password = "******"; UserAccount account = null; try { UserAccount existingAccount = Entity.GetByName <UserAccount>(username, true).FirstOrDefault( ); if (existingAccount != null) { existingAccount.Delete( ); } account = new UserAccount { Name = username, Password = password, AccountStatus_Enum = UserAccountStatusEnum_Enumeration.Active }; account.Save( ); Assert.AreEqual(0, GetUserAccountCacheCount( )); Assert.AreEqual(0, GetUserAccountCacheTenantCount(RunAsDefaultTenant.DefaultTenantName)); UserAccountCache.GetRequestContext(username, password, RunAsDefaultTenant.DefaultTenantName); Assert.AreEqual(1, GetUserAccountCacheCount( )); Assert.AreEqual(1, GetUserAccountCacheTenantCount(RunAsDefaultTenant.DefaultTenantName)); using (var domain = new TestAppDomain( )) { Func <MessageEventArgs <TestMessage>, bool> predicate = m => m.Message.Action == "EDC" && m.Message.Items.Contains(username); var instance = domain.InjectType <SubscriberRefObject <TestMessage> >(UserAccountCache.CacheName, RunAsDefaultTenant.DefaultTenantName, predicate); UserAccountCache.Invalidate(username, RunAsDefaultTenant.DefaultTenantName); bool waitOne = instance.MessageReceived.WaitOne(DefaultTimeout); Assert.IsTrue(waitOne, "No message received in " + DefaultTimeout + "ms."); Assert.GreaterOrEqual(instance.ReceivedMessages.Count, 1); MessageEventArgs <TestMessage> message = instance.ReceivedMessages.FirstOrDefault(predicate); Assert.IsNotNull(message, "Received message is invalid"); } } finally { if (account != null) { account.Delete( ); } } }
public void TestEntityFieldCacheRemove( ) { using (var domain = new TestAppDomain( )) { Func <MessageEventArgs <EntityFieldCacheMessage>, bool> predicate = m => m.Message.RemoveKeys.Any(rk => rk.Id == new EntityRef("core:resource").Id); var instance = domain.InjectType <SubscriberRefObject <EntityFieldCacheMessage>, EntityFieldCacheMessage>(EntityFieldCache.CacheName, RunAsDefaultTenant.DefaultTenantName, predicate); var entityRef = new EntityRef("core:resource"); var fieldRef = new EntityRef("core:name"); ///// // Get an entity in the primary domain. ///// Entity.Get(entityRef, fieldRef); ///// // Clear the cache from the primary domain. ///// EntityFieldCache.Instance.Remove(entityRef.Id); bool waitOne = instance.MessageReceived.WaitOne(DefaultTimeout); Assert.IsTrue(waitOne, "No message received in " + DefaultTimeout + "ms."); Assert.GreaterOrEqual(instance.ReceivedMessages.Count, 1, "Received message count is invalid."); MessageEventArgs <EntityFieldCacheMessage> message = instance.ReceivedMessages.FirstOrDefault(predicate); Assert.IsNotNull(message, "Received message is invalid"); } }
public void TestSubscriber( ) { const string channelName = "myChannel"; using (var domain1 = new TestAppDomain( )) { Func <MessageEventArgs <TestMessage>, bool> predicate = m => m.Message.Action == "myMessage"; var instance1 = domain1.InjectType <SubscriberRefObject <TestMessage> >(channelName, RunAsDefaultTenant.DefaultTenantName, predicate); using (var domain2 = new TestAppDomain( )) { var instance2 = domain2.InjectType <SubscriberRefObject <TestMessage> >(channelName, RunAsDefaultTenant.DefaultTenantName, predicate); using (IDistributedMemoryManager manager = new RedisManager( )) { manager.Connect( ); using (IChannel <TestMessage> channel = manager.GetChannel <TestMessage>(channelName)) { var message = new TestMessage( ); message.Action = "myMessage"; channel.Publish(message); bool waitOne1 = instance1.MessageReceived.WaitOne(DefaultTimeout); bool waitOne2 = instance2.MessageReceived.WaitOne(DefaultTimeout); Assert.IsTrue(waitOne1, "No message received in " + DefaultTimeout + "ms for app domain 1."); Assert.IsTrue(waitOne2, "No message received in " + DefaultTimeout + "ms for app domain 2."); instance2.Unsubscribe( ); channel.Publish(message); waitOne1 = instance1.MessageReceived.WaitOne(DefaultTimeout); waitOne2 = instance2.MessageReceived.WaitOne(0); Assert.IsTrue(waitOne1, "No message received in " + DefaultTimeout + "ms for app domain 1."); Assert.IsFalse(waitOne2, "Message received in app domain 1 when it should not have been."); instance1.Unsubscribe( ); var channelMessage = new TestMessage( ); channel.Publish(channelMessage); waitOne1 = instance1.MessageReceived.WaitOne(0); waitOne2 = instance2.MessageReceived.WaitOne(0); Assert.IsFalse(waitOne1, "Message received in app domain 1 when it should not have been."); Assert.IsFalse(waitOne2, "Message received in app domain 2 when it should not have been."); } } } } }
public void TestBulkPublisher( ) { const string channelName = "myChannel"; using (var domain = new TestAppDomain( )) { Func <MessageEventArgs <TestMessage>, bool> predicate = m => m.Message.Action == PublisherActions.Remove && m.Message.Items.Count == 2 && m.Message.Items.Contains("a,:") && m.Message.Items.Contains("b,:"); var instance = domain.InjectType <SubscriberRefObject <TestMessage> >(channelName, RunAsDefaultTenant.DefaultTenantName, predicate); using (IDistributedMemoryManager manager = new RedisManager( )) { manager.Connect( ); using (DeferredChannelMessageContext context = new DeferredChannelMessageContext()) { using (IChannel <TestMessage> channel1 = manager.GetChannel <TestMessage>(channelName)) { var message1 = new TestMessage { Action = PublisherActions.Remove }; message1.Items.Add("a,:"); channel1.Publish(message1, PublishOptions.None, false, (e, n) => e.Items.AddRange(n.Items)); using (IChannel <TestMessage> channel2 = manager.GetChannel <TestMessage>(channelName)) { var message2 = new TestMessage { Action = PublisherActions.Remove }; message2.Items.Add("b,:"); channel2.Publish(message2, PublishOptions.None, false, (e, n) => e.Items.AddRange(n.Items)); } } } bool waitOne = instance.MessageReceived.WaitOne(DefaultTimeout); Assert.IsTrue(waitOne, "No message received in " + DefaultTimeout + "ms."); Assert.GreaterOrEqual(instance.ReceivedMessages.Count, 1, "Received message count is invalid."); MessageEventArgs <TestMessage> args = instance.ReceivedMessages.FirstOrDefault(predicate); Assert.IsNotNull(args, "Received message is invalid."); } } }
public void TestEntityCacheClear( ) { using (var domain = new TestAppDomain( )) { Func <MessageEventArgs <EntityCacheMessage>, bool> predicate = m => m.Message.Clear; var instance = domain.InjectType <SubscriberRefObject <EntityCacheMessage>, EntityCacheMessage>(EntityCache.CacheName, RunAsDefaultTenant.DefaultTenantName, predicate); ///// // Clear the cache from the primary domain. ///// EntityCache.Instance.Clear( ); bool waitOne = instance.MessageReceived.WaitOne(DefaultTimeout); Assert.IsTrue(waitOne, "No message received in " + DefaultTimeout + "ms."); Assert.GreaterOrEqual(instance.ReceivedMessages.Count, 1, "Received message count is invalid."); MessageEventArgs <EntityCacheMessage> message = instance.ReceivedMessages.FirstOrDefault(predicate); Assert.IsNotNull(message, "Received message is invalid"); } }