public void OnInitialized_sets_component()
        {
            var component = A.Fake <IDisposable>();

            var behavior = new TestableBehavior
            {
                WhenOnInitialized = () => { }
            };

            ((IBehavior)behavior).Component = component;
            ((IBehavior)behavior).OnInitialized();

            behavior.GetComponent().Should().BeSameAs(component);
        }
        public void Instance_must_not_be_shared_between_components()
        {
            // arrange
            var component1 = A.Fake <IDisposable>();
            var component2 = A.Fake <IDisposable>();

            var behavior = new TestableBehavior();

            ((IBehavior)behavior).Component = component1;

            // act
            Action reuseBehavior = () => ((IBehavior)behavior).Component = component2;

            // assert
            reuseBehavior.Should().Throw <InvalidOperationException>().WithMessage("An behaviors instance must not be shared between components. If you injected the behavior, register it with transient lifetime.");
        }
        public void OnInitialized_forwards_call()
        {
            var component = A.Fake <IDisposable>();

            bool called = false;

            var behavior = new TestableBehavior
            {
                WhenOnInitialized = () => called = true
            };

            ((IBehavior)behavior).Component = component;
            ((IBehavior)behavior).OnInitialized();

            called.Should().BeTrue();
        }
        public void OnInitializedAsync_forwards_call()
        {
            var component = A.Fake <IDisposable>();

            bool called = false;

            var behavior = new TestableBehavior
            {
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
                WhenOnInitializedAsync = async() => called = true
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
            };

            ((IBehavior)behavior).OnInitializedAsync();

            called.Should().BeTrue();
        }