Beispiel #1
0
        public async Task MultipleModifiedListeners()
        {
            MockListener.Reset();
            MockListener2.Reset();
            ObjectListener.Reset();

            await Listen.ModifiedAsync(ent, ent2, ctx);

            Assert.IsFalse(MockListener.WasOnCreatedCalled);
            Assert.IsFalse(MockListener.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(MockListener.WasOnModifiedCalled);
            Assert.IsFalse(MockListener.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener.WasOnDeletedCalled);
            Assert.IsFalse(MockListener.WasOnDeletionFailedCalled);

            Assert.IsFalse(MockListener2.WasOnCreatedCalled);
            Assert.IsFalse(MockListener2.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(MockListener2.WasOnModifiedCalled);
            Assert.IsFalse(MockListener2.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletionFailedCalled);

            Assert.IsFalse(ObjectListener.WasOnCreatedCalled);
            Assert.IsFalse(ObjectListener.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(ObjectListener.WasOnModifiedCalled);
            Assert.IsFalse(ObjectListener.WasOnModificationFailedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletionFailedCalled);

            Assert.IsTrue(MockListener.EntitesWereNotTheSameOnCalling.HasValue && MockListener.EntitesWereNotTheSameOnCalling.Value);
            Assert.IsTrue(MockListener2.EntitesWereNotTheSameOnCalling.HasValue && MockListener2.EntitesWereNotTheSameOnCalling.Value);
            Assert.IsTrue(ObjectListener.EntitesWereNotTheSameOnCalling.HasValue && ObjectListener.EntitesWereNotTheSameOnCalling.Value);
        }
Beispiel #2
0
        public async Task MultipleModifiedListeners_TestInheritance()
        {
            MockListener.Reset();
            MockListener2.Reset();
            ObjectListener.Reset();

            await Listen.ModifiedAsync(new object(), new { sajt = true }, ctx);

            Assert.IsFalse(MockListener.WasOnCreatedCalled);
            Assert.IsFalse(MockListener.WasOnCreationValidationFailedCalled);
            Assert.IsFalse(MockListener.WasOnModifiedCalled);
            Assert.IsFalse(MockListener.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener.WasOnDeletedCalled);
            Assert.IsFalse(MockListener.WasOnDeletionFailedCalled);

            Assert.IsFalse(MockListener2.WasOnCreatedCalled);
            Assert.IsFalse(MockListener2.WasOnCreationValidationFailedCalled);
            Assert.IsFalse(MockListener2.WasOnModifiedCalled);
            Assert.IsFalse(MockListener2.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletionFailedCalled);

            Assert.IsFalse(ObjectListener.WasOnCreatedCalled);
            Assert.IsFalse(ObjectListener.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(ObjectListener.WasOnModifiedCalled);
            Assert.IsFalse(ObjectListener.WasOnModificationFailedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletionFailedCalled);

            Assert.IsNull(MockListener.EntitesWereNotTheSameOnCalling);
            Assert.IsNull(MockListener2.EntitesWereNotTheSameOnCalling);
            Assert.IsTrue(ObjectListener.EntitesWereNotTheSameOnCalling.HasValue && ObjectListener.EntitesWereNotTheSameOnCalling.Value);
        }
 public void NotifyObserver(string name, Parameters param)
 {
     if (objListener.ContainsKey(name))
     {
         ObjectListener listener = objListener[name];
         listener.NotifyObservers(param);
     }
 }
 public void RemoveObserverAction(string name, System.Action <Parameters> action)
 {
     if (objListener.ContainsKey(name))
     {
         ObjectListener listener = objListener[name];
         listener.RemoveObserver(action);
     }
 }
 public void RemoveObserver(string name)
 {
     if (objListener.ContainsKey(name))
     {
         ObjectListener listener = objListener[name];
         listener.RemoveAllObservers();
         objListener.Remove(name);
     }
 }
 /// <summary>
 /// Adds an observer with parameters
 /// </summary>
 /// <param name="name">Name Identifer</param>
 /// <param name="action">Function</param>
 /// <param name="prepend">Add at the beginning</param>
 public void AddObserver(string name, System.Action<Parameters> action, bool prepend = false)
 {
     ObjectListener listener = null;
     if (objListener.ContainsKey(name)) {
         listener = objListener[name];
         listener.AddObserver(action, prepend);
     }
     else {
         listener = new ObjectListener();
         listener.AddObserver(action, prepend);
         objListener.Add(name, listener);
     }
 }
    /// <summary>
    /// Adds an observer with parameters
    /// </summary>
    /// <param name="name">Name Identifer</param>
    /// <param name="action">Function</param>
    /// <param name="prepend">Add at the beginning</param>
    public void AddObserver(string name, System.Action <Parameters> action, bool prepend = false)
    {
        ObjectListener listener = null;

        if (objListener.ContainsKey(name))
        {
            listener = objListener[name];
            listener.AddObserver(action, prepend);
        }
        else
        {
            listener = new ObjectListener();
            listener.AddObserver(action, prepend);
            objListener.Add(name, listener);
        }
    }
Beispiel #8
0
        public async Task LoadTest()
        {
            MockListener.Reset();
            MockListener2.Reset();
            ObjectListener.Reset();

            var start = DateTime.Now;

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 500000; i++)
            {
                tasks.Add(Listen.ModifiedAsync(ent, ent, ctx));
            }

            Task.WaitAll(tasks.ToArray());

            var time = DateTime.Now.Subtract(start).TotalMilliseconds;

            Assert.IsTrue(time < 1500, "time < 1500");

            Assert.IsFalse(MockListener.WasOnCreatedCalled);
            Assert.IsFalse(MockListener.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(MockListener.WasOnModifiedCalled);
            Assert.IsFalse(MockListener.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener.WasOnDeletedCalled);
            Assert.IsFalse(MockListener.WasOnDeletionFailedCalled);

            Assert.IsFalse(MockListener2.WasOnCreatedCalled);
            Assert.IsFalse(MockListener2.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(MockListener2.WasOnModifiedCalled);
            Assert.IsFalse(MockListener2.WasOnModificationFailedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletedCalled);
            Assert.IsFalse(MockListener2.WasOnDeletionFailedCalled);


            Assert.IsFalse(ObjectListener.WasOnCreatedCalled);
            Assert.IsFalse(ObjectListener.WasOnCreationValidationFailedCalled);
            Assert.IsTrue(ObjectListener.WasOnModifiedCalled);
            Assert.IsFalse(ObjectListener.WasOnModificationFailedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletedCalled);
            Assert.IsFalse(ObjectListener.WasOnDeletionFailedCalled);
        }