예제 #1
0
        public void CloneEvent()
        {
            var random = new Random();

            foreach (var type in TypesProvider.GetAllEventTypes())
            {
                var midiEvent = type == typeof(UnknownMetaEvent)
                    ? new UnknownMetaEvent(1)
                    : (MidiEvent)Activator.CreateInstance(type);

                if (midiEvent is ChannelEvent channelEvent)
                {
                    channelEvent.Channel = (FourBitNumber)(random.Next(5) + 5);
                }

                if (midiEvent is BaseTextEvent baseTextEvent)
                {
                    baseTextEvent.Text = random.Next(1000).ToString();
                }

                midiEvent.DeltaTime = random.Next(1000) + 1;

                var midiEventClone = midiEvent.Clone();
                MidiAsserts.AreEventsEqual(midiEvent, midiEventClone, true, $"Clone of {type} is invalid.");
            }
        }
        public ServiceLocator(IContainerConfiguration containerConfiguration)
        {
            var assembliesProvider      = new AssembliesProvider(containerConfiguration);
            var compositionRootProvider = new CompositionRootProvider(assembliesProvider);
            var registry      = new Registry();
            var typesProvider = new TypesProvider();
            var objectInstantiatingGenerator            = new ObjectInstantiatingGenerator();
            var intantiationProvidingGeneratingStrategy = new InstantiationProvidingGeneratingStrategy(objectInstantiatingGenerator);
            var scopeKeeper = new ScopeKeeper();
            var perRequestProvidingGeneratingStrategy   = new PerRequestProvidingGeneratingStrategy(scopeKeeper, objectInstantiatingGenerator);
            var perContainerProvidingGeneratingStrategy = new PerContainerProvidingGeneratingStrategy(scopeKeeper, objectInstantiatingGenerator);
            var arrayInstantiatingGenerator             = new ArrayInstantiatingGenerator();
            var enumerableProvidingGeneratingStrategy   = new EnumerableProvidingGeneratingStrategy(arrayInstantiatingGenerator);
            var generatingStrategyProvider           = new GeneratingStrategyProvider(intantiationProvidingGeneratingStrategy, perRequestProvidingGeneratingStrategy, perContainerProvidingGeneratingStrategy, enumerableProvidingGeneratingStrategy);
            var objectGraphProvider                  = new ObjectGraphProvider(registry, generatingStrategyProvider);
            var instanceProvidingMethodBodyGenerator = new InstanceProvidingMethodBodyGenerator();
            var instanceProvidingMethodGenerator     = new InstanceProvidingMethodGenerator(objectGraphProvider, instanceProvidingMethodBodyGenerator);
            var registrationFactory                  = new RegistrationFactory(typesProvider, instanceProvidingMethodGenerator);
            var assemblyBoundedRegistrator           = new AssemblyBoundedRegistrator(registry, registrationFactory);
            var registratorProvider                  = new RegistratorProvider(assemblyBoundedRegistrator);
            var dependenciesCompositor               = new DependenciesCompositor(compositionRootProvider, registratorProvider);
            var registrySaturator   = new RegistrySaturator(registry, scopeKeeper);
            var registryInitializer = new RegistryInitializer(dependenciesCompositor, registrySaturator);

            _map.Add(typeof(IRegistryInitializer), registryInitializer);
            _map.Add(typeof(IScopeKeeper), scopeKeeper);
            var resolver = new Resolver(registry, scopeKeeper);

            _map.Add(typeof(IResolver), resolver);
        }
        public void GetAllDerivedTypes_Interface_NotNull(Type serviceType)
        {
            var typesProvider = new TypesProvider();
            var result        = typesProvider.GetAllDerivedTypesFrom(serviceType, serviceType.Assembly);

            Assert.NotNull(result);
        }
예제 #4
0
        public void AllEventTypesAreReadCorrectly(Func <Type, MidiEvent> createMidiEvent)
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(SystemCommonEvent).IsAssignableFrom(t) &&
                                !typeof(SystemRealTimeEvent).IsAssignableFrom(t) &&
                                t != typeof(EndOfTrackEvent) &&
                                t != typeof(UnknownMetaEvent))
                         .Select(createMidiEvent)
                         .ToArray();

            var midiFile = MidiFileTestUtilities.Read(
                new MidiFile(new TrackChunk(events)),
                null,
                new ReadingSettings {
                SilentNoteOnPolicy = SilentNoteOnPolicy.NoteOn
            },
                MidiFileFormat.SingleTrack);

            var readEvents = midiFile.GetEvents().ToArray();

            for (var i = 0; i < events.Length; i++)
            {
                var expectedEvent = events[i];
                var actualEvent   = readEvents[i];

                MidiAsserts.AreEventsEqual(expectedEvent, actualEvent, true, $"Event {i} is invalid.");
            }
        }
예제 #5
0
        private static void FetchInitializers()
        {
            initializers = new Dictionary <Type, List <IContextInitializer> >();

            foreach (Type type in TypesProvider.GetTypes())
            {
                AddInitializer(type);
            }
        }
        public void GetAllDerivedTypes_Interface_DerivedClass(Type serviceType, Type implType0, Type implType1, Type implType2)
        {
            var typesProvider = new TypesProvider();
            var result        = typesProvider.GetAllDerivedTypesFrom(serviceType, serviceType.Assembly).ToList();

            Assert.Contains(implType0, result);
            Assert.Contains(implType1, result);
            Assert.Contains(implType2, result);
        }
예제 #7
0
        public void CheckEventsReceiving_AllEventTypes_ExceptSysEx()
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(MetaEvent).IsAssignableFrom(t) && !typeof(SysExEvent).IsAssignableFrom(t))
                         .Select(t => (MidiEvent)Activator.CreateInstance(t))
                         .ToArray();

            CollectionAssert.IsNotEmpty(events, "Events collection is empty.");
            SendReceiveUtilities.CheckEventsReceiving(events.Select(e => new EventToSend(e, TimeSpan.Zero)).ToArray());
        }
예제 #8
0
 public void AllEventTypesAreCorrect()
 {
     foreach (var type in TypesProvider.GetAllEventTypes())
     {
         var instance = type == typeof(UnknownMetaEvent)
             ? new UnknownMetaEvent(0)
             : (MidiEvent)Activator.CreateInstance(type);
         var eventType = instance.EventType;
         Assert.IsTrue(
             type.Name.StartsWith(eventType.ToString()),
             $"Type '{eventType}' is invalid for events of type '{type.Name}'.");
     }
 }
예제 #9
0
        public void AllEventTypesHaveParameterlessConstructor()
        {
            foreach (var type in TypesProvider.GetAllEventTypes())
            {
                if (type == typeof(UnknownMetaEvent))
                {
                    continue;
                }

                Assert.IsNotNull(
                    type.GetConstructor(Type.EmptyTypes),
                    $"Type '{type.Name}' has no parameterless constructor.");
            }
        }
예제 #10
0
        public void EventPlayed_AllEventsTypes()
        {
            var delay        = 10;
            var eventsToSend = TypesProvider
                               .GetAllEventTypes()
                               .Select(type => type == typeof(UnknownMetaEvent)
                    ? new UnknownMetaEvent(0)
                    : (MidiEvent)Activator.CreateInstance(type))
                               .Select(midiEvent => new EventToSend(midiEvent, TimeSpan.FromMilliseconds(delay)))
                               .ToArray();

            CheckEventPlayedEvent(
                eventsToSend: eventsToSend,
                expectedPlayedEvents: eventsToSend.Select((e, i) => new ReceivedEvent(e.Event, TimeSpan.FromMilliseconds(delay * (i + 1)))).ToArray());
        }
예제 #11
0
        public void AllEventTypesAreReadCorrectly()
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(SystemCommonEvent).IsAssignableFrom(t) &&
                                !typeof(SystemRealTimeEvent).IsAssignableFrom(t) &&
                                t != typeof(EndOfTrackEvent) &&
                                t != typeof(UnknownMetaEvent))
                         .Select(t =>
            {
                var instance = (MidiEvent)Activator.CreateInstance(t);

                if (instance is SysExEvent sysExEvent)
                {
                    sysExEvent.Data = new byte[] { 1, 2, 3 }
                }
                ;

                if (instance is SequencerSpecificEvent sequencerSpecificEvent)
                {
                    sequencerSpecificEvent.Data = new byte[] { 1, 2, 3 }
                }
                ;

                if (instance is NoteOnEvent noteOnEvent)
                {
                    noteOnEvent.Velocity = (SevenBitNumber)100;
                }

                if (instance is BaseTextEvent baseTextEvent)
                {
                    baseTextEvent.Text = Guid.NewGuid().ToString();
                }

                return(instance);
            })
                         .ToArray();

            var midiFile   = MidiFileTestUtilities.Read(new MidiFile(new TrackChunk(events)), null, null, MidiFileFormat.SingleTrack);
            var readEvents = midiFile.GetEvents().ToArray();

            for (var i = 0; i < events.Length; i++)
            {
                var expectedEvent = events[i];
                var actualEvent   = readEvents[i];

                MidiAsserts.AreEventsEqual(expectedEvent, actualEvent, true, $"Event {i} is invalid.");
            }
        }
예제 #12
0
        internal TransientModule GetModule(ScriptContext /*!*/ context, DTypeDesc caller, string /*!*/ code, SourceCodeDescriptor descriptor)
        {
            Debug.Assert(context != null && code != null);

            Key   key = new Key(code, descriptor);
            Value value;

            rwLock.EnterUpgradeableReadLock();

            try
            {
                if (cache.TryGetValue(key, out value))
                {
                    if (TypesProvider.LoadAndMatch(value.TypeDependencies, context, caller))
                    {
#if !SILVERLIGHT
                        Performance.Increment(Performance.DynamicCacheHits);
#endif
                        return(value.Module);
                    }
                    else
                    {
                        // invalidate the cache entry, because type dependencies were changed:
                        rwLock.EnterWriteLock();

                        try
                        {
                            cache.Remove(key);
                        }
                        finally
                        {
                            rwLock.ExitWriteLock();
                        }
                    }
                }
            }
            finally
            {
                rwLock.ExitUpgradeableReadLock();
            }

            return(null);
        }