Exemplo n.º 1
0
    public static void Main(string[] args)
    {
        var test = new SampleClass();

        test.MyTransactionDelegate += () => { Console.WriteLine("Success"); };
        test.DoSomething();
    }
        public void CanRetrieveType()
        {
            Container.Add <SampleClass>();

            SampleClass sample = Container.Get <SampleClass>();

            Assert.NotNull(sample);
            Assert.Equal(1, sample.DoSomething());

            Container.Clear();
        }
        public void CanAddSingleInstance()
        {
            SampleClass sampleClass = new SampleClass();

            Container.Add(sampleClass);

            SampleClass retrievedSampleClass = Container.Get <SampleClass>();

            Assert.NotNull(retrievedSampleClass);
            Assert.Equal(1, retrievedSampleClass.DoSomething());

            Container.Clear();
        }
        public void Test_WeakEventListener_Events()
        {
            bool isOnEventTriggered = false;
            bool isOnDetachTriggered = false;

            SampleClass sample = new SampleClass();

            WeakEventListener<SampleClass, object, EventArgs> weak = new WeakEventListener<SampleClass, object, EventArgs>(sample);
            weak.OnEventAction = (instance, source, eventArgs) => { isOnEventTriggered = true; };
            weak.OnDetachAction = (listener) => { isOnDetachTriggered = true; };

            sample.Raisevent += weak.OnEvent;

            sample.DoSomething();
            Assert.IsTrue(isOnEventTriggered);

            weak.Detach();
            Assert.IsTrue(isOnDetachTriggered);
        }