TestValidationSettings.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using NUnit.Framework;
  2. using Assert = ModestTree.Assert;
  3. namespace Zenject.Tests
  4. {
  5. [TestFixture]
  6. public class TestValidationSettings
  7. {
  8. DiContainer Container
  9. {
  10. get; set;
  11. }
  12. [SetUp]
  13. public void Setup()
  14. {
  15. Container = new DiContainer(true);
  16. }
  17. // Doesn't work because the logged error is flagged as a test error
  18. //[Test]
  19. //public void TestValidationErrorLogOnly()
  20. //{
  21. //Container.Settings = new ZenjectSettings(ValidationErrorResponses.Log);
  22. //Container.Bind<Bar>().AsSingle().NonLazy();
  23. //Container.ResolveRoots();
  24. //}
  25. [Test]
  26. public void TestValidationErrorThrows()
  27. {
  28. Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
  29. Container.Bind<Bar>().AsSingle().NonLazy();
  30. Assert.Throws(() => Container.ResolveRoots());
  31. }
  32. [Test]
  33. public void TestOutsideObjectGraph1()
  34. {
  35. Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
  36. Container.Bind<Bar>().AsSingle();
  37. Container.ResolveRoots();
  38. }
  39. [Test]
  40. public void TestOutsideObjectGraph2()
  41. {
  42. Container.Settings = new ZenjectSettings(
  43. ValidationErrorResponses.Throw, RootResolveMethods.All);
  44. Container.Bind<Bar>().AsSingle();
  45. Assert.Throws(() => Container.ResolveRoots());
  46. }
  47. public class Bar
  48. {
  49. public Bar(Foo foo)
  50. {
  51. }
  52. }
  53. public class Foo
  54. {
  55. }
  56. }
  57. }