public void SetApiTest_UnsupportedFormat() { var testFile = TestFiles.Json; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Creator", Category = "Person" } } }, Type = "String" } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message); }
public async Task GivenAnAggregateWithChangesWhenAggregateSavedIsRaisedThenTheChangesArePropagatedToTheBusAsync() { const int ExpectedTotalChanges = 2; var context = new SerializableMessage(); var aggregate = new SerializableEventCentricAggregateRoot(context); var request = new SetRequest(context, Guid.NewGuid()); var bus = new Mock <IBus>(); var cloner = new TestableCloner(); var repository = new UnversionedMemoryRepository <SerializableEventCentricAggregateRoot>(cloner); var propagator = new DomainEventPropagator <SerializableEventCentricAggregateRoot>(bus.Object, repository); IEnumerable <DomainEvent> changes = Enumerable.Empty <DomainEvent>(); _ = bus .Setup(b => b.PublishAsync( It.IsAny <IEnumerable <DomainEvent> >(), It.IsAny <CancellationToken?>())) .Callback <IEnumerable <DomainEvent>, CancellationToken?>((events, _) => changes = events); aggregate.Set(request); await repository.SaveAsync(aggregate); _ = Assert.Single(changes.OfType <SerializableCreatedDomainEvent>()); _ = Assert.Single(changes.OfType <SerializableSetDomainEvent>()); Assert.Equal(ExpectedTotalChanges, changes.Count()); }
private async Task <(bool, string)> RequestInternalAsync(Uri uri, HttpMethod httpMethod, byte[] data, string contentType) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.CookieContainer = Cookies; req.UserAgent = UserAgent; req.AllowAutoRedirect = AllowAutoRedirect; req.Referer = Referer; req.Method = httpMethod.Method; req.ContentType = contentType; SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req)); if (data != null && data.Any() && (httpMethod != HttpMethod.Get) && (httpMethod != HttpMethod.Head)) { req.ContentLength = data.Length; using (Stream stream = await req.GetRequestStreamAsync().ConfigureAwait(false)) { await stream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); } } HttpWebResponse res = (HttpWebResponse)(await req.GetResponseAsync().ConfigureAwait(false)); GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res)); Stream responseStream = res.GetResponseStream(); using (StreamReader sr = new StreamReader(responseStream, Encoding)) { string response = await sr.ReadToEndAsync().ConfigureAwait(false); return(IsSuccessStatusCode((int)res.StatusCode), response); } }
public override Task <SetResponse> Set(SetRequest request, ServerCallContext context) { _dict[request.Key] = request.Value; return(Task.FromResult(new SetResponse { Success = true })); }
public void SetApiTest_FileNotFound() { var testFile = TestFiles.NotExist; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", Type = "Boolean", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Creator", Category = "Person" } } }, } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message); }
public async Task <SetRequest> RequestSetAsync(int requesterID, int challengedID, string message) { if (!await dbContext.LeagueUsers.AnyAsync(lu => lu.ID == requesterID)) { throw new NotFoundException(typeof(LeagueUser), requesterID); } if (!await dbContext.LeagueUsers.AnyAsync(lu => lu.ID == challengedID)) { throw new NotFoundException(typeof(LeagueUser), challengedID); } var requester = await dbContext.LeagueUsers .Include(lu => lu.League).AsNoTracking() .FirstOrDefaultAsync(lu => lu.ID == requesterID); var setRequest = new SetRequest { LeagueID = requester.LeagueID, RequesterID = requesterID, ChallengedID = challengedID, DateCreated = DateTime.Now, Message = message, }; dbContext.Add(setRequest); await dbContext.SaveChangesAsync(); return(setRequest); }
public void SetApiTest_ValueFormatException() { var testFile = TestFiles.Jpg; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", Type = "Boolean", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Printed", Category = "Time" } } }, } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual(ex.Message, "Request parameters missing or have incorrect format"); }
public void SetApiTest_PropertyValue() { var testFile = TestFiles.Docx; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "Microsoft Office Word Application", Type = "String", SearchCriteria = new SearchCriteria { ValueOptions = new ValueOptions { Value = "Microsoft Office Word", Type = "String" } }, } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.IsNotEmpty(result.Path); Assert.IsNotEmpty(result.Url); Assert.Greater(result.SetCount, 0); }
public void SetApiTest_WrongTypeForTag() { var testFile = TestFiles.Pptx; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "true", Type = "Boolean", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Creator", Category = "Person" } } }, } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual($"There are no changes in metadata.", ex.Message); }
public void SetApiTest_PropertyName() { var testFile = TestFiles.Docx; var now = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss"); var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = now, Type = "DateTime", SearchCriteria = new SearchCriteria { NameOptions = new NameOptions { Value = "Date" } }, } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.IsNotEmpty(result.Path); Assert.IsNotEmpty(result.Url); Assert.Greater(result.SetCount, 0); }
public void SetApiTest() { var testFile = TestFiles.Docx; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Creator", Category = "Person" } } }, Type = "String" } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.Greater(result.SetCount, 0); }
public void SetApiTest_PossibleTagName() { var testFile = TestFiles.Xlsx; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "New Creator", Type = "String", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { PossibleName = "creator" } }, } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.IsNotEmpty(result.Path); Assert.IsNotEmpty(result.Url); Assert.Greater(result.SetCount, 0); }
public void SetApiTest_DocumentProtectedException() { var testFile = TestFiles.PasswordProtected; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Creator", Category = "Person" } } }, Type = "String" } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual($"The specified file '{testFile.FullName}' is protected.", ex.Message); }
public void SetApiTest_NoChanges() { var testFile = TestFiles.Psd; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "NewAuthor", Type = "String", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Owner", Category = "Legal" } } }, } } }; var request = new SetRequest(options); var ex = Assert.Throws <ApiException>(() => { MetadataApi.Set(request); }); Assert.AreEqual($"There are no changes in metadata.", ex.Message); }
public void SetApiTest_Integer() { var testFile = TestFiles.Docx; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = "14", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "SoftwareVersion", Category = "Tool" } } }, Type = "integer" } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.Greater(result.SetCount, 0); }
public void SetRequestTest() { Status status = Status.UnknownCommand; var request = new SetRequest { Key = @"Hello", Message = System.Text.UTF8Encoding.Default.GetBytes(@"World"), RequestId = 0, Expire = TimeSpan.FromHours(1), CallBack = (s) => status = s, CallBackPolicy = CallBackPolicy.AllOK }; Assert.AreEqual(Opcode.Set, request.RequestOpcode); var queryBuffer = request.GetQueryBuffer(); CollectionAssert.AreEqual(SET_QUERY, queryBuffer, "The set query buffer is different from the expected one"); var header = new MemcacheResponseHeader { Opcode = Opcode.Set, Status = Status.NoError }; Assert.DoesNotThrow(() => request.HandleResponse(header, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.NoError, status); }
private string RequestInternal(Uri uri, string method, byte[] data, string contentType) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.CookieContainer = Cookies; req.UserAgent = UserAgent; req.AllowAutoRedirect = AllowAutoRedirect; req.Referer = Referer; req.Method = method; req.ContentType = contentType; SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req)); if ((data != null) && data.Any() && (method != WebRequestMethods.Http.Get) && (method != WebRequestMethods.Http.Head)) { req.ContentLength = data.Length; using (Stream stream = req.GetRequestStream()) { stream.Write(data, 0, data.Length); } } HttpWebResponse res = (HttpWebResponse)req.GetResponse(); GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res)); using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding)) { return(sr.ReadToEnd()); } }
public void RedundantSetRequestTest() { Status status = Status.UnknownCommand; var request = new SetRequest(CallBackPolicy.AllOK) { Key = "Hello".Select(c => (byte)c).ToArray(), Message = System.Text.Encoding.UTF8.GetBytes(@"World"), RequestId = 0, Expire = TimeSpan.FromHours(1), CallBack = (s) => status = s, Replicas = 1, }; var headerOK = new MemcacheResponseHeader { Opcode = Opcode.Set, Status = Status.NoError }; Assert.AreEqual(Opcode.Set, request.RequestOpcode); var queryBuffer = request.GetQueryBuffer(); CollectionAssert.AreEqual(SET_QUERY, queryBuffer, "The set query buffer is different from the expected one"); Assert.DoesNotThrow(() => request.HandleResponse(headerOK, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.UnknownCommand, status, "Callback should not be called on the first OK response"); Assert.DoesNotThrow(() => request.HandleResponse(headerOK, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.NoError, status, "Callback should be called with status OK"); }
public void SetApiTest_DateTime() { var testFile = TestFiles.Xlsx; var now = DateTime.Now; var options = new SetOptions { FileInfo = testFile.ToFileInfo(), Properties = new List <SetProperty> { new SetProperty { NewValue = now.ToString("MM-dd-yyyy hh:mm:ss"), Type = "DateTime", SearchCriteria = new SearchCriteria { TagOptions = new TagOptions { ExactTag = new Tag { Name = "Created", Category = "Time" } } }, } } }; var request = new SetRequest(options); var result = MetadataApi.Set(request); Assert.IsNotNull(result); Assert.Greater(result.SetCount, 0); }
/// <summary> /// Set existing metadata fields with new values. /// </summary> /// <param name="request">Request. <see cref="SetRequest" /></param> /// <returns><see cref="SetResult"/></returns> public SetResult Set(SetRequest request) { // verify the required parameter 'options' is set if (request.options == null) { throw new ApiException(400, "Missing required parameter 'options' when calling Set"); } // create path and map variables var resourcePath = this.configuration.GetServerUrl() + "/metadata/set"; resourcePath = Regex .Replace(resourcePath, "\\*", string.Empty) .Replace("&", "&") .Replace("/?", "?"); var postBody = SerializationHelper.Serialize(request.options); // http body (model) parameter var response = this.apiInvoker.InvokeApi( resourcePath, "POST", postBody, null, null); if (response != null) { return((SetResult)SerializationHelper.Deserialize(response, typeof(SetResult))); } return(null); }
protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(request)); return(request); }
protected override void PerformCoordinatedOperation( SerializableEventCentricAggregateRoot aggregate, TCommand message) { var request = new SetRequest(message, identity); aggregate.Set(request); }
public static SetRequest SetRequest(this IEnumerable <string> keys) { var request = new SetRequest(); request.Pairs.AddRange(keys.Select(key => new KeyValuePair() { Key = key })); return(request); }
/// <summary> /// Initializes a new instance of the SessionObject class /// </summary> /// <param name="Message">The SetRequest Message to initialize fields from</param> public SessionObject(SetRequest Message) { inuse = 0; isExporting = 0; data = Message.Data; lockCookie = Message.LockCookie ?? 0; lockDate = DateTime.MinValue; updateDate = DateTime.UtcNow; timeout = Message.Timeout ?? DEFAULT_SESSION_TIMEOUT; sbyte.TryParse(Message.ExtraFlags, out extraFlags); locked = false; }
public void RedundantSetRequestFailTest() { Status status = Status.UnknownCommand; var request = new SetRequest { Key = @"Hello", Message = System.Text.UTF8Encoding.Default.GetBytes(@"World"), RequestId = 0, Expire = TimeSpan.FromHours(1), CallBack = (s) => status = s, CallBackPolicy = CallBackPolicy.AllOK, Replicas = 1, }; var headerOK = new MemcacheResponseHeader { Opcode = Opcode.Set, Status = Status.NoError }; var headerFail = new MemcacheResponseHeader { Opcode = Opcode.Set, Status = Status.OutOfMemory }; var queryBuffer = request.GetQueryBuffer(); CollectionAssert.AreEqual(SET_QUERY, queryBuffer, "The set query buffer is different from the expected one"); // 1. First reponse is OK, second is failing Assert.DoesNotThrow(() => request.HandleResponse(headerOK, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.UnknownCommand, status, "Callback should not be called on the first OK response"); Assert.DoesNotThrow(() => request.Fail()); Assert.AreEqual(Status.InternalError, status, "The status sent by a fail should be InternalError"); // 2. First response is failing, second one is OK status = Status.UnknownCommand; request = new SetRequest { Key = @"Hello", Message = System.Text.UTF8Encoding.Default.GetBytes(@"World"), RequestId = 0, Expire = TimeSpan.FromHours(1), CallBack = (s) => status = s, CallBackPolicy = CallBackPolicy.AllOK, Replicas = 1, }; Assert.DoesNotThrow(() => request.HandleResponse(headerFail, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.OutOfMemory, status, "Callback should be called on the first failed response"); status = Status.UnknownCommand; Assert.DoesNotThrow(() => request.HandleResponse(headerOK, null, SET_EXTRA, SET_MESSAGE)); Assert.AreEqual(Status.UnknownCommand, status, "Callback should not be called on the responses following a fail"); }
public void SetRequestSerialization() { MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); Byte[] packet = { 0x80, 0x01, 0x00, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x0e, 0x10, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64 }; writer.Write(packet); stream.Seek(0, SeekOrigin.Begin); using (BinaryReader reader = new BinaryReader(stream)) { SetRequest request = (SetRequest)ProtocolPacket.ReadRequest(reader); Assert.AreEqual(request.Header.Magic, 0x80); Assert.AreEqual(request.Header.OpCode, CommandOpCode.Set); Assert.AreEqual(request.Header.KeyLength, 5); Assert.AreEqual(request.Header.ExtrasLength, 8); Assert.AreEqual(request.Header.DataType, 0); Assert.AreEqual(request.Header.Status, ResponseStatus.NoError); Assert.AreEqual(request.Header.TotalBodyLength, (uint)0x12); Assert.AreEqual(request.Header.Opaque, (uint)0); Assert.AreEqual(request.Header.CAS, (ulong)0); Assert.AreEqual(request.Header.Extras.Flags, (uint)0xdeadbeef); Assert.AreEqual(request.Key, "Hello"); Assert.AreEqual(request.Value, "World"); MemoryStream stream2 = new MemoryStream(); BinaryWriter writer2 = new BinaryWriter(stream2); request.Write(writer2); writer.Close(); byte[] packet2 = stream2.ToArray(); CollectionAssert.AreEqual(packet, packet2); } }
public static SetRequest SetRequest <T>(this IEnumerable <Models.KeyValuePair <T> > keys) { var request = new SetRequest(); request.Pairs.AddRange(keys.Select(key => new KeyValuePair() { Key = key.Key, Value = ByteString.CopyFrom(MessagePackSerializer.Serialize(key.Value).AsSpan()), Ttl = key.Ttl })); return(request); }
private static SetRequest SetPRequest(string key) { var rq = new SetRequest(); var pair = new Common.KeyValuePair { Key = key, Value = ByteString.Empty }; rq.Pairs.Add(pair); return(rq); }
public void GivenAValueThenTheValueIsPropagated() { var expected = Guid.NewGuid(); var context = new SerializableMessage(); var request = new SetRequest(context, expected); var aggregate = new SerializableEventCentricAggregateRoot(context); Assert.NotEqual(expected, aggregate.Value); aggregate.Set(request); Assert.Equal(expected, aggregate.Value); }
public void GivenAValueWhenTheAggregateIsNewThenTheVersionRemainsUnchanged() { var value = Guid.NewGuid(); var context = new SerializableMessage(); var request = new SetRequest(context, value); var aggregate = new SerializableEventCentricAggregateRoot(context); SignedVersion version = aggregate.Version; Assert.True(version.IsNew); aggregate.Set(request); Assert.Equal(version, aggregate.Version); }
public void onSetRequest(SetRequest interval, object o) { }