Esempio n. 1
0
 public void CanRegisterAnApplyMethod()
 {
     var buildUp = BuildUp.Initialize(_ =>
     {
         _.RegisterApply(_apply);
     });
 }
Esempio n. 2
0
 private void ReplaceType <T>(BuildUp <T> buildMethod)
 {
     lock (_dictionaryLock)
     {
         _dictionary[typeof(T)] = new ServiceBuilder <T>(buildMethod);
     };
 }
Esempio n. 3
0
 public void CanRegisterAnEventTransform()
 {
     var buildUp = BuildUp.Initialize(_ =>
     {
         _.RegisterEventTransform(_transform);
     });
 }
Esempio n. 4
0
        /// <summary>
        /// Temporarily registers a new instance of type <typeparamref name="T"/> with the locator that will be returned
        /// for all calls to <see cref="GetService"/> for this type
        /// </summary>
        /// <typeparam name="T">The type implemented by the instance</typeparam>
        /// <param name="newBuildMethod">The method used to construct an instance of T</param>
        public IDisposable OverrideType <T>(BuildUp <T> newBuildMethod)
        {
            BuildUp <T>          oldBuildMethod = GetBuildDelegate <T>();
            OverrideDisposer <T> disposer       = new OverrideDisposer <T>(oldBuildMethod, this);

            ReplaceType <T>(newBuildMethod);
            return(disposer);
        }
Esempio n. 5
0
        public void CanRegisterAProjectionAndApplyMethodsAreFoundBySignature()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterProjection <SignatureProjection>();
            });
            var methods = buildUp.GetApplyMethods();

            Assert.Equal(3, methods.Count());
        }
Esempio n. 6
0
        public void ApplyCanBeSetAsPatchViaRegistration()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_patchApply).Patch();
            });
            var methods = buildUp.GetApplyMethods();
            var method  = methods.FirstOrDefault(t => t.EventType == typeof(PatchEvent) && t.IsPatchable);

            Assert.NotNull(method);
        }
Esempio n. 7
0
        public void CanUseAttributesToSpecifyPatchEvents()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_alsoPatchApply);
            });
            var methods = buildUp.GetApplyMethods();
            var method  = methods.FirstOrDefault(t => t.EventType == typeof(AlsoPatchEvent) && t.IsPatchable);

            Assert.NotNull(method);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a build up delegate for use with a <see cref="ServiceLocator"/>.
        /// </summary>
        /// <typeparam name="TFrom">The service type (superclass)</typeparam>
        /// <typeparam name="TTo">The concrete implementation (subclass)</typeparam>
        /// <returns>A build up delegate</returns>
        private static BuildUp <TFrom> CreateLazyBuildUp <TFrom, TTo>() where TTo : TFrom, new()
        {
            LazyInit <TTo> init = new LazyInit <TTo>();

            BuildUp <TFrom> del = delegate
            {
                return((TFrom)init.Instance);
            };

            return(del);
        }
Esempio n. 9
0
        public void ApplyCanBeSetAsADeleteViaRegistration()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_deleteApply).Delete();
            });
            var methods = buildUp.GetApplyMethods();
            var method  = methods.FirstOrDefault(t => t.EventType == typeof(DeleteEvent) && t.IsDelete);

            Assert.NotNull(method);
        }
Esempio n. 10
0
 private void Button03_Tapped(object sender, TappedRoutedEventArgs e)
 {
     if (count == 0)
     {
         BuildUp.IsLooping = true;
         BuildUp.Play();
         count++;
     }
     else if (count == 1)
     {
         BuildUp.IsLooping = false;
         BuildUp.Pause();
         count--;
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Registers a type mapping in the locator where the <paramref name="buildMethod"/> delegate will be called when
        /// <see cref="GetService"/> is called for type <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The service type</typeparam>
        /// <param name="buildMethod">The delegate called to build instances of type <typeparamref name="T"/></param>
        /// <exception cref="InvalidOperationException">Throw when this service type has already been registered with the container</exception>
        public void RegisterType <T>(BuildUp <T> buildMethod)
        {
            Type type = typeof(T);

            lock (_dictionaryLock)
            {
                if (_dictionary.ContainsKey(type))
                {
                    throw new InvalidOperationException(string.Format(
                                                            Resources.TypeAlreadyRegistered,
                                                            typeof(T)));
                }
                _dictionary.Add(type, new ServiceBuilder <T>(buildMethod));
            }
        }
Esempio n. 12
0
        public async Task HandlesMultipleEventsOK()
        {
            // SETUP
            var es       = new InMemoryEventStream();
            var eStorage = new InMemoryEventStorage();
            var sStorage = new InMemorySnapShotStorage();
            var buildup  = BuildUp.Initialize(t =>
            {
                t.SetEventStream(es);
                t.SetEventProvider(eStorage);
                t.SetEventStorage(eStorage);
                t.SetSnapshotProvider(sStorage);
                t.SetSnapshotStorage(sStorage);
            });
            var @event = new BuildUpEvent <RandomEvent>
            {
                StreamId = Guid.NewGuid(),
                Data     = new RandomEvent {
                    I = 5
                },
                EventDate = DateTime.UtcNow,
                Version   = 1
            };
            var eventTwo = new BuildUpEvent <RandomEvent>
            {
                StreamId = @event.StreamId,
                Data     = new RandomEvent {
                    I = 72
                },
                EventDate = DateTime.UtcNow,
                Version   = 2
            };

            //ACT
            es.PublishEvent(@event);
            es.PublishEvent(eventTwo);
            es.EndStream();
            Thread.Sleep(25);
            //ASSERT
            var projections = await sStorage.GetSnapshots(@event.StreamId);

            var buildUpSnapshots = projections as IBuildUpSnapshot[] ?? projections.ToArray();

            Assert.Single(buildUpSnapshots);
            var projection = (RandomProjection)buildUpSnapshots.First().Snapshot;

            Assert.Equal(72, projection.I);
        }
Esempio n. 13
0
        public void CanApplyAnEventWithNoTransform()
        {
            var existing = new ExampleProjection();
            var @event   = new ExampleEvent
            {
                Id          = Guid.NewGuid(),
                AppendValue = "AppendingValue"
            };
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_apply);
            });
            var projectedValue = buildUp.Project(existing, @event);

            Assert.Equal(projectedValue.Id, @event.Id);
            Assert.Equal(projectedValue.SomeValue, @event.AppendValue);
        }
Esempio n. 14
0
        void CanSpecifyWhatEventTypeCreatesAProjectionOnAStream()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterProjection <SignatureProjection>().CreatedBy <CreateEvent>();
            });
            var @event = new CreateEvent
            {
                Id = 72
            };
            var snapshots        = buildUp.GetSnapshots(@event);
            var buildUpSnapshots = snapshots as IBuildUpSnapshot[] ?? snapshots.ToArray();

            Assert.Single(buildUpSnapshots);
            var snapshot = buildUpSnapshots.First();

            Assert.Equal(72, ((SignatureProjection)snapshot.Snapshot).Id);
        }
Esempio n. 15
0
        void CanSpecifyWhatEventTypeCreatesAProjectionFromAttribute()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterProjection <SignatureProjection>();
            });

            var @event = new IsCreateSignatureProjectionEvent
            {
                Id = 5
            };
            var projections      = buildUp.GetSnapshots(@event);
            var buildUpSnapshots = projections as IBuildUpSnapshot[] ?? projections.ToArray();

            Assert.Single(buildUpSnapshots);
            var proj = buildUpSnapshots.First();

            Assert.Equal(5, ((SignatureProjection)proj.Snapshot).Id);
        }
Esempio n. 16
0
        public void CanApplyMultipleMethodsToProjection()
        {
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterProjection <SignatureProjection>();
            });
            var projection = new SignatureProjection();
            var create     = new CreateEvent
            {
                Id = 1
            };
            var modify = new ModifyEvent
            {
                Id = 3
            };

            projection = buildUp.Project(projection, create, modify);
            Assert.Equal(3, projection.Id);
        }
Esempio n. 17
0
        public void CanApplyMultipleEvents()
        {
            var existing = new ExampleProjection();
            var @event   = new ExampleEvent
            {
                Id          = Guid.NewGuid(),
                AppendValue = "AppendingValue"
            };
            var secondEvent = new ExampleEvent
            {
                Id          = @event.Id,
                AppendValue = "MoreValuesToAdd"
            };
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_apply);
            });
            var projectedValue = buildUp.Project(existing, @event, secondEvent);

            Assert.Equal(projectedValue.Id, @event.Id);
            Assert.Equal(projectedValue.SomeValue, $"{@event.AppendValue}{secondEvent.AppendValue}");
        }
Esempio n. 18
0
        public void AutomaticallyPerformsTransformIfPresent()
        {
            var existing = new ExampleProjection();
            var @event   = new ExampleEvent
            {
                Id          = Guid.NewGuid(),
                AppendValue = "AppendingValue"
            };
            var secondEvent = new ObsoleteEvent()
            {
                Id       = @event.Id,
                NewValue = "MoreValuesToAdd"
            };
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_apply);
                _.RegisterEventTransform(_transform);
            });
            var projectedValue = buildUp.Project(existing, @event, secondEvent);

            Assert.Equal(projectedValue.Id, @event.Id);
            Assert.Equal(projectedValue.SomeValue, $"{@event.AppendValue}{secondEvent.NewValue}");
        }
Esempio n. 19
0
        public void ChainsTransformsToFindAWayToApply()
        {
            var existing = new ExampleProjection();
            var @event   = new ExampleEvent
            {
                Id          = Guid.NewGuid(),
                AppendValue = "AppendingValue"
            };
            var secondEvent = new ChainedEvent()
            {
                Id       = @event.Id,
                OldValue = "MoreValuesToAdd"
            };
            var buildUp = BuildUp.Initialize(_ =>
            {
                _.RegisterApply(_apply);
                _.RegisterEventTransform(_transform);
                _.RegisterEventTransform(_chainedTransform);
            });
            var projectedValue = buildUp.Project(existing, @event, secondEvent);

            Assert.Equal(projectedValue.Id, @event.Id);
            Assert.Equal(projectedValue.SomeValue, $"{@event.AppendValue}{secondEvent.OldValue}");
        }
Esempio n. 20
0
 public ServiceBuilder(BuildUp <T> buildMethod)
 {
     BuildUp = buildMethod;
 }
Esempio n. 21
0
        /// <summary>
        /// Returns an instance of type <typeparamref name="T"/> as per the mapping registered with the locator
        /// </summary>
        /// <typeparam name="T">The type of service requested</typeparam>
        /// <returns>An instance of that service</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the service type does not exist in this service provider</exception>
        public T GetService <T>()
        {
            BuildUp <T> del = GetBuildDelegate <T>();

            return(del());
        }
Esempio n. 22
0
 internal OverrideDisposer(BuildUp <T> oldBuildMethod, ServiceLocator locator)
 {
     _oldBuildMethod = oldBuildMethod;
     _locator        = locator;
 }