예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public async Task DistributeToListenersAsync(List <object> added, EfContextInfo contextInfo, List <Tuple <object, object> > modified, List <object> removed, bool isChildRepository = false)
        {
            if (!isChildRepository)
            {
                List <Type> otherTypes = added.Where(a => !(a is T)).Select(a => a.GetType()).ToList();
                otherTypes.AddRange(modified.Where(a => !(a.Item1 is T)).Select(a => a.Item1.GetType()));
                otherTypes.AddRange(removed.Where(a => !(a is T)).Select(a => a.GetType()));
                foreach (var otherType in otherTypes.Distinct())
                {
                    var repo = GetChildRepositoryFor(otherType);
                    await repo.DistributeToListenersAsync(added, contextInfo, modified, removed, true);
                }
            }


            /* from the same type */
            //added.Where(a=>(a) is T).Cast<T>().Select(async a => await Listen.CreatedAsync(a, contextInfo));
            foreach (var addedEntry in added.Where(a => (a) is T).Cast <T>())
            {
                await Listen.CreatedAsync(addedEntry, contextInfo);
            }
            //var t2 = modified.Where(a => a is Tuple<T,T>).Cast<Tuple<T,T>>().Select(async a =>await Listen.ModifiedAsync((a).Item1, (a).Item2, contextInfo));
            foreach (var modifiedEntry in modified.Where(a => a.Item1 is T && a.Item2 is T).Cast <Tuple <object, object> >())
            {
                await Listen.ModifiedAsync(modifiedEntry.Item1 as T, modifiedEntry.Item2 as T, contextInfo);
            }

            //var t3 = removed.Where(a => a is T).Cast<T>().Select(async a => await Listen.RemovedAsync((a), contextInfo));
            foreach (var removedEntry in removed.Where(a => a is T).Cast <T>())
            {
                await Listen.RemovedAsync(removedEntry, contextInfo);
            }
        }
예제 #4
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);
        }