public void CanRegisterAnApplyMethod() { var buildUp = BuildUp.Initialize(_ => { _.RegisterApply(_apply); }); }
private void ReplaceType <T>(BuildUp <T> buildMethod) { lock (_dictionaryLock) { _dictionary[typeof(T)] = new ServiceBuilder <T>(buildMethod); }; }
public void CanRegisterAnEventTransform() { var buildUp = BuildUp.Initialize(_ => { _.RegisterEventTransform(_transform); }); }
/// <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); }
public void CanRegisterAProjectionAndApplyMethodsAreFoundBySignature() { var buildUp = BuildUp.Initialize(_ => { _.RegisterProjection <SignatureProjection>(); }); var methods = buildUp.GetApplyMethods(); Assert.Equal(3, methods.Count()); }
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); }
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); }
/// <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); }
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); }
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--; } }
/// <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)); } }
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); }
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); }
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); }
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); }
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); }
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}"); }
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}"); }
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}"); }
public ServiceBuilder(BuildUp <T> buildMethod) { BuildUp = buildMethod; }
/// <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()); }
internal OverrideDisposer(BuildUp <T> oldBuildMethod, ServiceLocator locator) { _oldBuildMethod = oldBuildMethod; _locator = locator; }