PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Tests/Unit/BindingActionStrategyTests.cs

https://github.com/developingchris/ninject
C# | 66 lines | 56 code | 10 blank | 0 comment | 0 complexity | 0f1856a6ec6610cc1ab2d727261bd71f MD5 | raw file
  1. using System;
  2. using Moq;
  3. using Ninject.Activation;
  4. using Ninject.Activation.Strategies;
  5. using Ninject.Planning.Bindings;
  6. using Xunit;
  7. using Xunit.Should;
  8. namespace Ninject.Tests.Unit.BindingActionStrategyTests
  9. {
  10. public class BindingActionStrategyContext
  11. {
  12. protected readonly BindingActionStrategy strategy;
  13. protected readonly Mock<IContext> contextMock;
  14. protected readonly Mock<IBinding> bindingMock;
  15. public BindingActionStrategyContext()
  16. {
  17. contextMock = new Mock<IContext>();
  18. bindingMock = new Mock<IBinding>();
  19. strategy = new BindingActionStrategy();
  20. }
  21. }
  22. public class WhenActivateIsCalled : BindingActionStrategyContext
  23. {
  24. [Fact]
  25. public void StrategyInvokesActivationActionsDefinedInBinding()
  26. {
  27. bool action1WasCalled = false;
  28. bool action2WasCalled = false;
  29. Action<object> action1 = c => action1WasCalled = true;
  30. Action<object> action2 = c => action2WasCalled = true;
  31. var actions = new[] { action1, action2 };
  32. contextMock.SetupGet(x => x.Binding).Returns(bindingMock.Object);
  33. bindingMock.SetupGet(x => x.ActivationActions).Returns(actions);
  34. strategy.Activate(contextMock.Object, new InstanceReference());
  35. action1WasCalled.ShouldBeTrue();
  36. action2WasCalled.ShouldBeTrue();
  37. }
  38. }
  39. public class WhenDeactivateIsCalled : BindingActionStrategyContext
  40. {
  41. [Fact]
  42. public void StrategyInvokesDeactivationActionsDefinedInBinding()
  43. {
  44. bool action1WasCalled = false;
  45. bool action2WasCalled = false;
  46. Action<object> action1 = c => action1WasCalled = true;
  47. Action<object> action2 = c => action2WasCalled = true;
  48. var actions = new[] { action1, action2 };
  49. contextMock.SetupGet(x => x.Binding).Returns(bindingMock.Object);
  50. bindingMock.SetupGet(x => x.DeactivationActions).Returns(actions);
  51. strategy.Deactivate(contextMock.Object, new InstanceReference());
  52. action1WasCalled.ShouldBeTrue();
  53. action2WasCalled.ShouldBeTrue();
  54. }
  55. }
  56. }