Esempio n. 1
0
        public void add_get()
        {
            var ids = new[] { Guid.NewGuid(), Guid.NewGuid() };

            _sut.Add(_src, ids);
            _sut.Get(_src).ShouldAllBeEquivalentTo(ids);
        }
Esempio n. 2
0
        public void reserver_ids()
        {
            var id = Guid.NewGuid();

            Guid[] ids = null;
            _store.Add(Arg.Any <ReservedIdsSource>(), Arg.Do <Guid[]>(d => ids = d));
            var rez = _sut.ReserveIdsFor(typeof(Handler), id, 2);

            _store.Received(1).Add(Arg.Any <ReservedIdsSource>(), rez);
            _store.Get(Arg.Any <ReservedIdsSource>()).Returns(ids);
            var rez2 = _sut.ReserveIdsFor(typeof(Handler), id, 2);

            _store.ReceivedWithAnyArgs(1).Add(Arg.Any <ReservedIdsSource>(), rez);
            rez.ShouldAllBeEquivalentTo(rez2);
        }
Esempio n. 3
0
        /// <exception cref="InvalidReservationCountException"></exception>
        public Guid[] ReserveIdsFor <T>(T handlerType, Guid msgId, int howMany)
        {
            this.LogDebug("Getting reserved ids for event {0} handled by {1}", msgId, handlerType.GetType().Name);
            var input = new ReservedIdsSource()
            {
                Count = howMany, HandlerType = typeof(T), MessageId = msgId
            };
            var guids = _reservedIds.Get(input);

            if (guids.IsNullOrEmpty())
            {
                this.LogDebug("No ids are reserved for event {0} handled by {1}. Generating {2} ids", msgId, handlerType.GetType().Name, howMany);
                guids = Enumerable.Range(1, howMany).Select(d => Guid.NewGuid()).ToArray();
                _reservedIds.Add(input, guids);
            }
            else
            {
                if (guids.Length != howMany)
                {
                    throw new InvalidReservationCountException(msgId, typeof(T), howMany, guids.Length);
                }
            }
            return(guids);
        }