public void MessageCoordinator_Publish_ShouldNotFireSubsequentSubscribersIfOneFails() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe((string message) => { throw new ApplicationException("Test exception"); }); coordinator.Subscribe((string message) => { Assert.Fail(); }); // Act try { coordinator.Publish("message"); } catch (ApplicationException ex) { Assert.AreEqual("Test exception", ex.Message); throw; } // Assert }
public void MessageCoordinator_Close_ShouldFireNeverReceivedCallbackInOrderOfSubscription() { // Arrange var coordinator = new MessageCoordinator(); var subscriberCount = 20; var firedCallbacks = new List<int>(); for (var i = 0; i < subscriberCount; i++) { var subscriberIndex = i; coordinator.Subscribe((string message) => { Assert.Fail("Callback should never have been called."); }, () => { firedCallbacks.Add(subscriberIndex); }); } // Act coordinator.Close(); // Assert var expectedFiringOrder = Enumerable.Range(0, subscriberCount).ToArray(); CollectionAssert.AreEquivalent(expectedFiringOrder, firedCallbacks); }
public void MessageCoordinator_Close_ShouldFireNeverReceivedCallbackInOrderOfSubscription() { // Arrange var coordinator = new MessageCoordinator(); var subscriberCount = 20; var firedCallbacks = new List <int>(); for (var i = 0; i < subscriberCount; i++) { var subscriberIndex = i; coordinator.Subscribe((string message) => { Assert.Fail("Callback should never have been called."); }, () => { firedCallbacks.Add(subscriberIndex); }); } // Act coordinator.Close(); // Assert var expectedFiringOrder = Enumerable.Range(0, subscriberCount).ToArray(); CollectionAssert.AreEquivalent(expectedFiringOrder, firedCallbacks); }
public void Setup() { mockedHandler = Substitute.For <IMessageHandler>(); messageCoordinator = new MessageCoordinator(new List <IMessageHandler> { mockedHandler }); }
public TestObjects(List <IMessageSender> messageSenders, MessageCoordinator coordinator, Message message, List <MessageRecipient> recipients) { MessageSenders = messageSenders; Coordinator = coordinator; Message = message; Recipients = recipients; }
public TestObjects(List<IMessageSender> messageSenders, MessageCoordinator coordinator, Message message, List<MessageRecipient> recipients) { MessageSenders = messageSenders; Coordinator = coordinator; Message = message; Recipients = recipients; }
public void MessageCoordinator_Subscribe_ShouldThrowArgumentNullExceptionIfMessageReceivedCallbackIsNull() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Subscribe((Action <object>)null); // Assert }
public void MessageCoordinator_Subscribe_ShouldAcceptNullForNeverReceivedCallback() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Subscribe((object message) => { }, null); // Assert }
public void MessageCoordinator_Publish_ShouldNotFailIfThereAreNoMatchingSubscribers() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Publish("message"); // Assert }
public void MessageCoordinator_Close_ShouldSupportBeingCalledMultipleTimes() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Close(); // Assert }
public void MessageCoordinator_Publish_ShouldThrowInvalidOperationExceptionIfCalledAfterClose() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Publish("message"); // Assert }
public void MessageCoordinator_Subscribe_ShouldThrowInvalidOperationExceptionIfCalledAfterClose() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Subscribe((string message) => { Assert.Fail(); }); // Assert }
public void MessageCoordinator_Publish_ShouldAcceptNewMessagesWithinALateSubscribeCallback() { // Arrange var coordinator = new MessageCoordinator(); // Act var intReceived = false; coordinator.Publish("message"); coordinator.Subscribe <int>(m => { intReceived = m == 123; }); coordinator.Subscribe <string>(m => coordinator.Publish(123)); // Assert Assert.IsTrue(intReceived); }
public void MessageCoordinator_Close_ShouldFireNotDeliveredForSubscribersOfInheritedTypes() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe<InheritedTestMessage>( (InheritedTestMessage message) => { Assert.Fail("The recieved callback should not be called"); }, () => { }); //Act coordinator.Publish(new TestMessage()); coordinator.Close(); // Assert }
public void MessageCoordinator_Close_ShouldFireNotDeliveredForSubscribersOfInheritedTypes() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe <InheritedTestMessage>( (InheritedTestMessage message) => { Assert.Fail("The recieved callback should not be called"); }, () => { }); //Act coordinator.Publish(new TestMessage()); coordinator.Close(); // Assert }
public void MessageCoordinator_Publish_ShouldAcceptNullMessage() { // Arrange var coordinator = new MessageCoordinator(); string receviedMessage = "something else"; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Act coordinator.Publish((string)null); // Assert Assert.IsNull(receviedMessage); }
public void MessageCoordinator_Publish_ShouldAcceptNullMessage() { // Arrange var coordinator = new MessageCoordinator(); string receviedMessage = "something else"; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Act coordinator.Publish((string)null); // Assert Assert.IsNull(receviedMessage); }
public void MessageCoordinator_Publish_ShouldNotFireSubscribersOfInheritedTypes() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe((InheritedTestMessage message) => { Assert.Fail("Callback should never have been called."); }); // Act var publishedMessage = new TestMessage(); coordinator.Publish(publishedMessage); // Assert }
public void MessageCoordinator_Publish_ShouldFireExistingSubscribers() { // Arrange var coordinator = new MessageCoordinator(); string receviedMessage = null; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Act var publishedMessage = "hello"; coordinator.Publish(publishedMessage); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Publish_ShouldFireSubscribersOfBaseTypes() { // Arrange var coordinator = new MessageCoordinator(); TestMessage receviedMessage = null; coordinator.Subscribe((TestMessage message) => { receviedMessage = message; }); // Act var publishedMessage = new InheritedTestMessage(); coordinator.Publish(publishedMessage); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Publish_ShouldFireExistingSubscribers() { // Arrange var coordinator = new MessageCoordinator(); string receviedMessage = null; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Act var publishedMessage = "hello"; coordinator.Publish(publishedMessage); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Subscribe_ShouldReceivePreviousMessages() { // Arrange var coordinator = new MessageCoordinator(); var publishedMessage = "hello"; coordinator.Publish(publishedMessage); // Act string receviedMessage = null; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Publish_ShouldNotFireSubsequentSubscribersIfOneFails() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe((string message) => throw new ApplicationException("Test exception")); coordinator.Subscribe((string message) => { Assert.Fail(); }); // Act var exception = Assert.Throws <ApplicationException>( () => coordinator.Publish("message")); Assert.AreEqual("Test exception", exception.Message); // Assert }
public void MessageCoordinator_Publish_ShouldFireSubscribersOfBaseTypes() { // Arrange var coordinator = new MessageCoordinator(); TestMessage receviedMessage = null; coordinator.Subscribe((TestMessage message) => { receviedMessage = message; }); // Act var publishedMessage = new InheritedTestMessage(); coordinator.Publish(publishedMessage); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Close_ShouldFireNeverReceivedCallback() { // Arrange var coordinator = new MessageCoordinator(); bool neverReceivedCallbackFired = false; coordinator.Subscribe( (int message) => { Assert.Fail("Callback should never have been called."); }, () => { neverReceivedCallbackFired = true; }); // Act coordinator.Publish("hello"); coordinator.Close(); // Assert Assert.IsTrue(neverReceivedCallbackFired); }
public void MessageCoordinator_Publish_ShouldFireMultipleSubscribersInOrderOfSubscription() { // Arrange var coordinator = new MessageCoordinator(); var subscriberCount = 20; var firedSubscribers = new List<int>(); for (var i = 0; i < subscriberCount; i++) { var subscriberIndex = i; coordinator.Subscribe((string message) => { firedSubscribers.Add(subscriberIndex); }); } // Act coordinator.Publish("message"); // Assert var expectedFiringOrder = Enumerable.Range(0, subscriberCount).ToArray(); CollectionAssert.AreEquivalent(expectedFiringOrder, firedSubscribers); }
public void MessageCoordinator_Subscribe_ShouldReceiveMultiplePreviousMessagesInOrderOfPublishing() { // Arrange var coordinator = new MessageCoordinator(); var messageCount = 20; var publishedMessages = Enumerable.Range(0, messageCount).ToList(); foreach (var message in publishedMessages) { coordinator.Publish(message); } // Act var receviedMessages = new List <int>(); coordinator.Subscribe((int message) => { receviedMessages.Add(message); }); // Assert CollectionAssert.AreEquivalent(publishedMessages, receviedMessages); }
public void MessageCoordinator_Close_ShouldFireNeverReceivedCallback() { // Arrange var coordinator = new MessageCoordinator(); bool neverReceivedCallbackFired = false; coordinator.Subscribe( (int message) => { Assert.Fail("Callback should never have been called."); }, () => { neverReceivedCallbackFired = true; }); // Act coordinator.Publish("hello"); coordinator.Close(); // Assert Assert.IsTrue(neverReceivedCallbackFired); }
public void MessageCoordinator_Close_ShouldNotFireNeverReceivedCallbackForMessagesThatHaveBeenReceived() { // Arrange var coordinator = new MessageCoordinator(); bool messageReceivedCallbackFired = false; coordinator.Subscribe( (string message) => { messageReceivedCallbackFired = true; }, () => { Assert.Fail("Callback should never have been called."); }); // Act coordinator.Publish("hello"); coordinator.Close(); // Assert Assert.IsTrue(messageReceivedCallbackFired); }
public void MessageCoordinator_Publish_ShouldFireMultipleSubscribersInOrderOfSubscription() { // Arrange var coordinator = new MessageCoordinator(); var subscriberCount = 20; var firedSubscribers = new List <int>(); for (var i = 0; i < subscriberCount; i++) { var subscriberIndex = i; coordinator.Subscribe((string message) => { firedSubscribers.Add(subscriberIndex); }); } // Act coordinator.Publish("message"); // Assert var expectedFiringOrder = Enumerable.Range(0, subscriberCount).ToArray(); CollectionAssert.AreEquivalent(expectedFiringOrder, firedSubscribers); }
public void MessageCoordinator_Publish_ShouldNotFailIfThereAreNoMatchingSubscribers() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Publish("message"); // Assert }
public void MessageCoordinator_Close_ShouldSupportBeingCalledMultipleTimes() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Close(); // Assert }
public void MessageCoordinator_Close_ShouldNotFireNeverReceivedCallbackForMessagesThatHaveBeenReceived() { // Arrange var coordinator = new MessageCoordinator(); bool messageReceivedCallbackFired = false; coordinator.Subscribe( (string message) => { messageReceivedCallbackFired = true; }, () => { Assert.Fail("Callback should never have been called."); }); // Act coordinator.Publish("hello"); coordinator.Close(); // Assert Assert.IsTrue(messageReceivedCallbackFired); }
public void MessageCoordinator_Subscribe_ShouldAcceptNullForNeverReceivedCallback() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Subscribe((object message) => { }, null); // Assert }
public static bool Prefix(AttackDirector.AttackSequence __instance, MessageCenterMessage message) { CustomAmmoCategoriesLog.Log.LogWrite("AttackDirector.AttackSequence.OnAttackSequenceResolveDamage"); try { AttackSequenceResolveDamageMessage resolveDamageMessage = (AttackSequenceResolveDamageMessage)message; WeaponHitInfo hitInfo = resolveDamageMessage.hitInfo; if (hitInfo.attackSequenceId != __instance.id) { return(true); } ; MessageCoordinator messageCoordinator = (MessageCoordinator)typeof(AttackDirector.AttackSequence).GetField("messageCoordinator", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); if (!messageCoordinator.CanProcessMessage(resolveDamageMessage)) { messageCoordinator.StoreMessage((MessageCenterMessage)resolveDamageMessage); } else { if (AttackDirector.AttackSequence.logger.IsLogEnabled) { AttackDirector.AttackSequence.logger.Log((object)string.Format("[OnAttackSequenceResolveDamage] ID {0}, Group {1}, Weapon {2}, AttackerId [{3}], TargetId [{4}]", (object)__instance.id, (object)hitInfo.attackGroupIndex, (object)hitInfo.attackWeaponIndex, (object)hitInfo.attackerId, (object)hitInfo.targetId)); } Weapon weapon = __instance.GetWeapon(resolveDamageMessage.hitInfo.attackGroupIndex, resolveDamageMessage.hitInfo.attackWeaponIndex); if (__instance.meleeAttackType == MeleeAttackType.DFA) { float damageAmount = __instance.attacker.StatCollection.GetValue <float>("DFASelfDamage"); __instance.attacker.TakeWeaponDamage(resolveDamageMessage.hitInfo, 64, weapon, damageAmount, 0, DamageType.DFASelf); __instance.attacker.TakeWeaponDamage(resolveDamageMessage.hitInfo, 128, weapon, damageAmount, 0, DamageType.DFASelf); if (AttackDirector.damageLogger.IsLogEnabled) { AttackDirector.damageLogger.Log((object)string.Format("@@@@@@@@ {0} takes {1} damage to its legs from the DFA attack!", (object)__instance.attacker.DisplayName, (object)damageAmount)); } } __instance.target.ResolveWeaponDamage(resolveDamageMessage.hitInfo); AbstractActor target = __instance.target as AbstractActor; int attackIndex = -1; int num1 = 0; int num2 = 65536; for (int index = 0; index < resolveDamageMessage.hitInfo.hitLocations.Length; ++index) { int hitLocation = resolveDamageMessage.hitInfo.hitLocations[index]; if (hitLocation != num1 && hitLocation != num2 && attackIndex == -1) { attackIndex = index; } } if (attackIndex > -1) { //typeof(AttackDirector.AttackSequence).GetProperty("attackCompletelyMissed", BindingFlags.NonPublic).SetValue(__instance, (object)false); PropertyInfo property = typeof(AttackDirector.AttackSequence).GetProperty("attackCompletelyMissed"); property.DeclaringType.GetProperty("attackCompletelyMissed"); property.GetSetMethod(true).Invoke(__instance, new object[1] { (object)false }); //__instance.attackCompletelyMissed = false; } if (attackIndex > -1 && !__instance.target.IsDead && target != null) { foreach (EffectData statusEffect in CustomAmmoCategories.getWeaponStatusEffects(weapon)) { if (statusEffect.targetingData.effectTriggerType == EffectTriggerType.OnHit) { string effectID = string.Format("OnHitEffect_{0}_{1}", (object)__instance.attacker.GUID, (object)resolveDamageMessage.hitInfo.attackSequenceId); __instance.Director.Combat.EffectManager.CreateEffect(statusEffect, effectID, __instance.stackItemUID, (ICombatant)__instance.attacker, __instance.target, hitInfo, attackIndex, false); if (__instance.target != null) { __instance.Director.Combat.MessageCenter.PublishMessage((MessageCenterMessage) new FloatieMessage(__instance.target.GUID, __instance.target.GUID, statusEffect.Description.Name, FloatieMessage.MessageNature.Debuff)); } } } if (target != null) { List <EffectData> effectsForTriggerType = target.GetComponentStatusEffectsForTriggerType(EffectTriggerType.OnDamaged); for (int index = 0; index < effectsForTriggerType.Count; ++index) { __instance.Director.Combat.EffectManager.CreateEffect(effectsForTriggerType[index], string.Format("OnDamagedEffect_{0}_{1}", (object)target.GUID, (object)resolveDamageMessage.hitInfo.attackSequenceId), __instance.stackItemUID, __instance.target, (ICombatant)__instance.attacker, hitInfo, attackIndex, false); } } } __instance.attacker.HandleDeath(__instance.attacker.GUID); __instance.attacker.HandleDeath(__instance.attacker.GUID); messageCoordinator.MessageComplete((MessageCenterMessage)resolveDamageMessage); } } catch (Exception e) { CustomAmmoCategoriesLog.Log.LogWrite("Exception " + e.ToString() + "\nFallback to default"); return(true); } return(false); }
public void MessageCoordinator_Subscribe_ShouldThrowArgumentNullExceptionIfMessageReceivedCallbackIsNull() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Subscribe((Action<object>)null); // Assert }
public void MessageCoordinator_Subscribe_ShouldThrowInvalidOperationExceptionIfCalledAfterClose() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Subscribe((string message) => { Assert.Fail(); }); // Assert }
public void MessageCoordinator_Subscribe_ShouldReceiveMultiplePreviousMessagesInOrderOfPublishing() { // Arrange var coordinator = new MessageCoordinator(); var messageCount = 20; var publishedMessages = Enumerable.Range(0, messageCount).ToList(); foreach (var message in publishedMessages) { coordinator.Publish(message); } // Act var receviedMessages = new List<int>(); coordinator.Subscribe((int message) => { receviedMessages.Add(message); }); // Assert CollectionAssert.AreEquivalent(publishedMessages, receviedMessages); }
public void MessageCoordinator_Subscribe_ShouldReceivePreviousMessages() { // Arrange var coordinator = new MessageCoordinator(); var publishedMessage = "hello"; coordinator.Publish(publishedMessage); // Act string receviedMessage = null; coordinator.Subscribe((string message) => { receviedMessage = message; }); // Assert Assert.AreEqual(publishedMessage, receviedMessage); }
public void MessageCoordinator_Publish_ShouldAcceptNewMessagesWithinALateSubscribeCallback() { // Arrange var coordinator = new MessageCoordinator(); // Act var intReceived = false; coordinator.Publish("message"); coordinator.Subscribe<int>(m => { intReceived = m == 123; }); coordinator.Subscribe<string>(m => coordinator.Publish(123)); // Assert Assert.IsTrue(intReceived); }
public void MessageCoordinator_Publish_ShouldNotFireSubsequentSubscribersIfOneFails() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe((string message) => { throw new ApplicationException("Test exception"); }); coordinator.Subscribe((string message) => { Assert.Fail(); }); // Act try { coordinator.Publish("message"); } catch (ApplicationException ex) { Assert.AreEqual("Test exception", ex.Message); throw; } // Assert }
public void MessageCoordinator_Publish_ShouldNotFireSubscribersOfInheritedTypes() { // Arrange var coordinator = new MessageCoordinator(); coordinator.Subscribe((InheritedTestMessage message) => { Assert.Fail("Callback should never have been called."); }); // Act var publishedMessage = new TestMessage(); coordinator.Publish(publishedMessage); // Assert }
public void MessageCoordinator_Publish_ShouldThrowInvalidOperationExceptionIfCalledAfterClose() { // Arrange var coordinator = new MessageCoordinator(); // Act coordinator.Close(); coordinator.Publish("message"); // Assert }
public void SetUp() { view = new Mock<IViewBeersToDrinkSoon>(); service = new Mock<IBeerRepository>(); messageCoordinator = new MessageCoordinator(); }
public void SetUp() { view = new Mock<IViewBeersToDrinkSoon>(); service = new Mock<IBeerRepository>(); user = new Mock<IUserProvider>(); messageCoordinator = new MessageCoordinator(); templateController = new Mock<ITemplateController>(); }