public async Task WhenCreatingSchedule_ItGetsCreated_AndCanBe_ReloadedFromTheEventOnlyRepository() { Func <Type, object> factory = (t) => { if (t == typeof(IRepository <Schedule, Guid, Guid>)) { return(_eventOnlyRepository); } throw new Exception("Invalid type requested"); }; using (var session = new MasterSession(new MasterSession.ServiceFactory(factory))) { var scheduleName = "test schedule"; var schedule = new Schedule(scheduleName); session.Attach(schedule); await session.SaveAsync(); session.DetachAll(); var reloadedSchedule = await session.GetByIdAsync <Schedule>(schedule.Id); reloadedSchedule.Id.ShouldBe(schedule.Id); reloadedSchedule.ScheduleName.ShouldBe(scheduleName); reloadedSchedule.StreamState.ShouldBe(StreamState.HasStream); reloadedSchedule.CurrentVersion.ShouldBe(0); reloadedSchedule.LastCommittedVersion.ShouldBe(0); var events = _eventPublisher.Events[reloadedSchedule.Id]; events.Count.ShouldBe(1); events.First().EventCommittedTimestamp.ShouldBe(_clock.Value); } }
public async Task WhenCreatingSchedule_MasterSessionThrowException_IfInvalidIdTypeIsPassed() { Func <Type, object> factory = (t) => { if (t == typeof(IRepository <Schedule, Guid, Guid>)) { return(_repository); } throw new Exception("Invalid type requested"); }; using (var session = new MasterSession(new MasterSession.ServiceFactory(factory))) { var scheduleName = "test schedule"; var schedule = new Schedule(scheduleName); session.Attach(schedule); await session.SaveAsync(); session.DetachAll(); await Should.ThrowAsync <ArgumentException>(async() => { await session.GetByIdAsync <Schedule>(schedule.Id.ToString()); }); } }
public void WhenCreatingSchedule_MasterSessionThrowException_IfInvalidAggregateTypeIsPassed() { Func <Type, object> factory = (t) => throw new Exception("Invalid type requested"); using (var session = new MasterSession(new MasterSession.ServiceFactory(factory))) { Should.Throw <ArgumentException>(() => { session.Attach(new MockObject()); }); } }
public void WhenCreatingSchedule_MasterSessionThrowException_IfNoRepositoryIsFound() { Func <Type, object> factory = (t) => null; using (var session = new MasterSession(new MasterSession.ServiceFactory(factory))) { var scheduleName = "test schedule"; var schedule = new Schedule(scheduleName); Should.Throw <ArgumentException>(() => { session.Attach(schedule); }); } }