示例#1
0
        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);
            }
        }
示例#2
0
        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());
                });
            }
        }