public void MalformedContentTypeThrows()
 {
     Assert.Throws <FormatException>(
         () => new EventData(Uuid.NewUuid(), "-", Array.Empty <byte>(), contentType: "application"));
 }
예제 #2
0
 protected static EventData CreateLinkToEvent(string originalStreamName, StreamRevision originalRevision)
 => new EventData(Uuid.NewUuid(), SystemEventTypes.LinkTo,
                  Helper.UTF8NoBom.GetBytes($"{originalRevision.ToInt64()}@{originalStreamName}"));
예제 #3
0
 protected static EventData CreateTestEvent(int index, string type)
 => new EventData(Uuid.NewUuid(), type, Encoding.UTF8.GetBytes($@"{{""x"":{index}}}"));
예제 #4
0
        public void Equality()
        {
            var sut = Uuid.NewUuid();

            Assert.Equal(Uuid.FromGuid(sut.ToGuid()), sut);
        }
            private async ValueTask <IWriteResult> AppendInternal(BatchAppendReq.Types.Options options,
                                                                  IEnumerable <EventData> events, CancellationToken cancellationToken)
            {
                var batchSize        = 0;
                var correlationId    = Uuid.NewUuid();
                var correlationIdDto = correlationId.ToDto();

                var complete = _pendingRequests.GetOrAdd(correlationId, new TaskCompletionSource <IWriteResult>());

                foreach (var appendRequest in GetRequests())
                {
                    await _channel.Writer.WriteAsync(appendRequest, cancellationToken).ConfigureAwait(false);
                }

                return(await complete.Task.ConfigureAwait(false));

                IEnumerable <BatchAppendReq> GetRequests()
                {
                    bool first            = true;
                    var  proposedMessages = new List <BatchAppendReq.Types.ProposedMessage>();

                    foreach (var @event in events)
                    {
                        var proposedMessage = new BatchAppendReq.Types.ProposedMessage {
                            Data           = ByteString.CopyFrom(@event.Data.Span),
                            CustomMetadata = ByteString.CopyFrom(@event.Metadata.Span),
                            Id             = @event.EventId.ToDto(),
                            Metadata       =
                            {
                                { Constants.Metadata.Type,        @event.Type        },
                                { Constants.Metadata.ContentType, @event.ContentType }
                            }
                        };

                        proposedMessages.Add(proposedMessage);

                        if ((batchSize += proposedMessage.CalculateSize()) <
                            _settings.OperationOptions.BatchAppendSize)
                        {
                            continue;
                        }

                        yield return(new BatchAppendReq {
                            ProposedMessages = { proposedMessages },
                            CorrelationId = correlationIdDto,
                            Options = first ? options : null
                        });

                        first = false;
                        proposedMessages.Clear();
                        batchSize = 0;
                    }

                    yield return(new BatchAppendReq {
                        ProposedMessages = { proposedMessages },
                        IsFinal = true,
                        CorrelationId = correlationIdDto,
                        Options = first ? options : null
                    });
                }
            }
예제 #6
0
        public void ToFormattedStringProducesExpectedResult()
        {
            var sut = Uuid.NewUuid();

            Assert.Equal(sut.ToGuid().ToString("n"), sut.ToString("n"));
        }
예제 #7
0
        public void ArgumentNullException()
        {
            var ex = Assert.Throws <ArgumentNullException>(() => Uuid.Parse(null));

            Assert.Equal("value", ex.ParamName);
        }
예제 #8
0
        public void InequalityOperator()
        {
            var sut = Uuid.NewUuid();

            Assert.True(Uuid.NewUuid() != sut);
        }
예제 #9
0
        public void EqualityOperator()
        {
            var sut = Uuid.NewUuid();

            Assert.True(Uuid.FromGuid(sut.ToGuid()) == sut);
        }
예제 #10
0
        public void Inequality()
        {
            var sut = Uuid.NewUuid();

            Assert.NotEqual(Uuid.NewUuid(), sut);
        }