public async Task TestCustomPropertyWithHandler() { CustomHandler testHandler = new CustomHandler(); // Add the random guid to the property Guid randomGuid = Guid.NewGuid(); string propertyKey = "Test"; testHandler.UpdateRequestMessage = x => x.Properties[propertyKey] = randomGuid; CosmosClient customClient = TestCommon.CreateCosmosClient( (cosmosClientBuilder) => cosmosClientBuilder.AddCustomHandlers(testHandler)); ToDoActivity testItem = CreateRandomToDoActivity(); using (CosmosResponseMessage response = await customClient.GetContainer(this.database.Id, this.Container.Id).CreateItemStreamAsync( partitionKey: new Cosmos.PartitionKey(testItem.status), streamPayload: this.jsonSerializer.ToStream(testItem))) { Assert.IsNotNull(response); Assert.IsNotNull(response.RequestMessage); Assert.IsNotNull(response.RequestMessage.Properties); Assert.AreEqual(randomGuid, response.RequestMessage.Properties[propertyKey]); } }
public void Should_Provide_All_Callbacks() { var handler = new CustomHandler(); var bars = handler.ResolveAll <Bar>(); Assert.AreEqual(2, bars.Length); }
public void Should_Resolve_Self_Implicitly() { var handler = new CustomHandler(); var result = handler.Resolve <CustomHandler>(); Assert.AreSame(handler, result); }
public void Should_Resolve_Self_Implicitly_Decorated() { var handler = new CustomHandler(); var result = handler.Broadcast().Resolve <CustomHandler>(); Assert.AreSame(handler, result); }
public void Should_Provide_Callbacks_By_String_Key() { var handler = new CustomHandler(); var bar = handler.Resolve("Bar") as Bar; Assert.IsNotNull(bar); }
public void Should_Indicate_Not_Provided() { var handler = new CustomHandler(); var bee = handler.Resolve <Bee>(); Assert.IsNull(bee); }
public void Should_Provide_Callbacks_Mapped() { var handler = new CustomHandler(); var baz = handler.Resolve <Baz <int, string> >(); Assert.IsInstanceOfType(baz, typeof(Baz <int, string>)); Assert.AreEqual(0, baz.Stuff); }
public void Should_Handle_Callbacks_Implicitly() { var foo = new Foo(); var handler = new CustomHandler(); Assert.IsTrue(handler.Handle(foo)); Assert.AreEqual(1, foo.Handled); }
public void Should_Provide_Callbacks_Explicitly() { var handler = new CustomHandler(); var baz = handler.Resolve <Baz>(); Assert.IsInstanceOfType(baz, typeof(SuperBaz)); Assert.IsFalse(baz.HasComposer); }
internal static async Task RunAsync(HttpClient httpClient, CancellationToken cancellationToken) { var handler = new CustomHandler(); using var bootstrap = new LambdaBootstrap(httpClient, handler.InvokeAsync); await bootstrap.RunAsync(cancellationToken); }
public async Task Should_Cancel_Async_Resolution() { var handler = new CustomHandler(); var promise = handler.Aspect((_, c) => false).ResolveAsync <Bar>(); Assert.IsInstanceOfType(promise, typeof(Promise <Bar>)); await promise; }
public void Should_Handle_Callbacks_Genericly() { var baz = new Baz <int>(22); var handler = new CustomHandler(); Assert.IsTrue(handler.Handle(baz)); Assert.AreEqual(0, baz.Stuff); Assert.IsFalse(handler.Handle(new Baz <char>('M'))); }
public void Should_Handle_Callbacks_Contravariantly() { var foo = new SuperFoo(); var handler = new CustomHandler(); Assert.IsTrue(handler.Handle(foo)); Assert.IsTrue(foo.HasComposer); Assert.AreEqual(2, foo.Handled); }
public void Should_Provide_Callbacks_Implicitly() { var handler = new CustomHandler(); var bar = handler.Resolve <Bar>(); Assert.IsNotNull(bar); Assert.IsFalse(bar.HasComposer); Assert.AreEqual(1, bar.Handled); }
public void Should_Provide_Callbacks_Implicitly_With_Composer() { var handler = new CustomHandler(); var boo = handler.Resolve <Boo>(); Assert.IsNotNull(boo); Assert.AreEqual(boo.GetType(), typeof(Boo)); Assert.IsTrue(boo.HasComposer); }
public void Should_Provide_Callbacks_Covariantly() { var handler = new CustomHandler(); var bar = handler.Resolve <SuperBar>(); Assert.IsInstanceOfType(bar, typeof(SuperBar)); Assert.IsTrue(bar.HasComposer); Assert.AreEqual(1, bar.Handled); }
public void Should_Provide_Callbacks_Greedily() { var handler = new CustomHandler() + new CustomHandler(); var bars = handler.ResolveAll <Bar>(); Assert.AreEqual(4, bars.Length); bars = handler.ResolveAll <SuperBar>(); Assert.AreEqual(2, bars.Length); }
public async Task Should_Async_Filter_Async_Resolution() { var handler = new CustomHandler(); var bar = await handler.Aspect((_, c) => Promise.True) .ResolveAsync <Bar>(); Assert.IsNotNull(bar); Assert.IsFalse(bar.HasComposer); Assert.AreEqual(1, bar.Handled); }
public void Should_Handle_Callbacks_Genericly_Mapped() { var baz = new Baz <int, float>(22, 15.5f); var handler = new CustomHandler(); Assert.IsTrue(handler.Handle(baz)); Assert.AreEqual(0, baz.Stuff); Assert.AreEqual(0, baz.OtherStuff); Assert.IsFalse(handler.Handle(new Baz <char, float>('M', 2))); }
public void Should_Broadcast_Callbacks() { var foo = new Foo(); var group = new CustomHandler() + new CustomHandler() + new CustomHandler(); Assert.IsTrue(group.Broadcast().Handle(foo)); Assert.AreEqual(3, foo.Handled); }
public void Should_Resolve_All() { var custom = new CustomHandler(); var special = new SpecialHandler(); var handler = custom + special; var objects = handler.ResolveAll <object>(); CollectionAssert.Contains(objects, custom); CollectionAssert.Contains(objects, special); Assert.AreEqual(11, objects.Length); }
public void Should_Handle_Callbacks_Explicitly() { var bar = new Bar(); var handler = new CustomHandler(); Assert.IsTrue(handler.Handle(bar)); Assert.IsTrue(bar.HasComposer); Assert.AreEqual(1, bar.Handled); Assert.IsFalse(handler.Handle(bar)); Assert.AreEqual(2, bar.Handled); }
public async Task SerializeSpans() { var handler = new CustomHandler(); var factory = new HttpClientRequestFactory(handler); var request = factory.Create(new Uri("http://localhost/")); await request.PostAsync(ArraySegment <byte> .Empty); var message = handler.Message; Assert.IsAssignableFrom <ByteArrayContent>(message.Content); }
public async Task SerializeSpans() { var handler = new CustomHandler(); var factory = new HttpClientRequestFactory(handler); var request = factory.Create(new Uri("http://localhost/")); await request.PostAsync(new Span[0][], new FormatterResolverWrapper(SpanFormatterResolver.Instance)); var message = handler.Message; Assert.IsAssignableFrom <TracesMessagePackContent>(message.Content); }
public void ShouldBeAbleToProviderOnceOffExceptionHandler() { // Arrange var handler = new CustomHandler(); var cmd = new ShouldTimeout(handler); // Act Expect(() => CommandExecutor.Execute(cmd)) .Not.To.Throw(); // Assert Expect(handler.CaughtException) .Not.To.Be.Null(); Expect(handler.HandledOperation) .To.Equal(Operation.Insert); }
public async void InnerHandler_NotAssigned() { var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://contoso.com"); var handler = new CustomHandler(); var invoker = new HttpMessageInvoker(handler); try { await invoker.SendAsync(httpRequestMessage, new CancellationToken()); Assert.Fail(); } catch (InvalidOperationException) { } }
private void ChainOfResponsibility() { Image image = new Image("tatil-fotografim", "JPG"); JPEGHandler jpegHandler = new JPEGHandler(); JPGHandler jpgHandler = new JPGHandler(); CustomHandler customHandler = new CustomHandler(); // Zincirlerin birbirleri ile bağlantısının yapıldığı yerdir. // JPEG bu işlemi gerçekleştiremezse JPG'e aktarır o da Custom'a aktarır. jpegHandler.SetNextHandler(jpgHandler); jpgHandler.SetNextHandler(customHandler); jpegHandler.HandleRequest(image); }
protected void s(j A_0) { global::u.c("handleGetRegisterHandlers"); try { List <string> registered = CustomHandler.GetRegistered(); A_0.b = registered; } catch (Exception ex) { global::u.a(ex.Message + " " + ex.StackTrace); A_0.f = ResponseStatus.UN_KNOW_ERROR; A_0.b = ex.Message + " " + ex.StackTrace; } global::o.a(A_0); }
public async Task ReadManyExceptionsTest(HttpStatusCode statusCode) { RequestHandler[] requestHandlers = new RequestHandler[1]; requestHandlers[0] = new CustomHandler(statusCode); CosmosClientBuilder builder = TestCommon.GetDefaultConfiguration(); builder.AddCustomHandlers(requestHandlers); CosmosClient client = builder.Build(); Database database = await client.CreateDatabaseAsync(Guid.NewGuid().ToString()); Container container = await database.CreateContainerAsync(Guid.NewGuid().ToString(), "/pk"); for (int i = 0; i < 5; i++) { await container.CreateItemAsync( ToDoActivity.CreateRandomToDoActivity("pk" + i, i.ToString())); } List <(string, PartitionKey)> itemList = new List <(string, PartitionKey)>(); for (int i = 0; i < 5; i++) { itemList.Add(("IncorrectId" + i, new PartitionKey("pk" + i))); // wrong ids } using (ResponseMessage responseMessage = await container.ReadManyItemsStreamAsync(itemList)) { Assert.AreEqual(responseMessage.StatusCode, statusCode); } try { await container.ReadManyItemsAsync <ToDoActivity>(itemList); Assert.Fail("Typed API should throw"); } catch (CosmosException ex) { Assert.AreEqual(ex.StatusCode, statusCode); } await database.DeleteAsync(); client.Dispose(); }
public async Task SetHeaders() { var handler = new CustomHandler(); var factory = new HttpClientRequestFactory(handler); var request = factory.Create(new Uri("http://localhost/")); request.AddHeader("Hello", "World"); await request.PostAsync(ArraySegment <byte> .Empty); var message = handler.Message; Assert.NotNull(message); Assert.Equal(".NET", message.Headers.GetValues(AgentHttpHeaderNames.Language).First()); Assert.Equal(TracerConstants.AssemblyVersion, message.Headers.GetValues(AgentHttpHeaderNames.TracerVersion).First()); Assert.Equal("false", message.Headers.GetValues(CommonHttpHeaderNames.TracingEnabled).First()); Assert.Equal("World", message.Headers.GetValues("Hello").First()); }
/// <summary> /// Creates an object that invokes code of your choice if an error occurs. The given custom handler will /// only be invoked in the case of an error, and it will prevent the default error message from being /// added to the validator's error collection. Even if the handler does not add an error to the validator, /// valdiator.HasErrors will return true because an error has still occurred. /// </summary> public ValidationErrorHandler( CustomHandler customHandler ) { this.customHandler = customHandler; }
public void Extensibility_DeserializeWithInvalidRegisteredExtensionHandlers() { XliffDocument document; XliffDataList expectedChildren; List<IExtensionAttribute> expectedAttributes; Dictionary<string, IExtensionHandler> handlers; IExtensible extensible; XliffData data1; XliffData data2; XliffData data3; handlers = new Dictionary<string, IExtensionHandler>(); handlers["bogus"] = new CustomHandler("bogus", "bogus"); document = TestUtilities.Deserialize(TestData.DocumentWithExtensions, true, handlers); Console.WriteLine("Verifying document extensions."); extensible = (IExtensible)document; Assert.IsNotNull(extensible.Extensions, "Extensions should not be null"); Assert.AreEqual(1, extensible.Extensions.Count, "Extensions count is incorrect."); Console.WriteLine(" Verifying Extensions[0]."); Assert.AreEqual(ExtensibilityTests.DefaultExtensionName, extensible.Extensions[0].Name, "Extension name is incorrect."); expectedAttributes = new List<IExtensionAttribute>(); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 1")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 2")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace2, "attribute1", "attribute 3")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace2, "attribute2", "attribute 4")); this.VerifyAttributes(expectedAttributes, extensible.Extensions[0]); this.VerifyExtensionChildren(" ", null, extensible.Extensions[0]); Console.WriteLine("Verifying file extensions."); extensible = (IExtensible)document.Files[0]; Assert.IsNotNull(extensible.Extensions, "Extensions should not be null"); Assert.AreEqual(1, extensible.Extensions.Count, "Extensions count is incorrect."); Console.WriteLine(" Verifying Extensions[0]."); Assert.AreEqual(ExtensibilityTests.DefaultExtensionName, extensible.Extensions[0].Name, "Extension name is incorrect."); expectedAttributes = new List<IExtensionAttribute>(); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 5")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 6")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace2, "attribute1", "attribute 7")); expectedAttributes.Add(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace2, "attribute2", "attribute 8")); this.VerifyAttributes(expectedAttributes, extensible.Extensions[0]); expectedChildren = new XliffDataList(); // Child 0. data1 = expectedChildren.AddChild(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1", typeof(GenericElement)); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute1", "attribute 9"); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute2", "attribute 10"); data2 = data1.Children.AddChild(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element2", typeof(GenericElement)); data2.AddAttribute(ExtensibilityTests.Namespace1, "attribute3", "attribute 11"); data3 = data2.Children.AddChild(NamespaceValues.Core, "source", typeof(Source)); data3.AddAttribute(NamespacePrefixes.Xml, null, "lang", "de-de", true); data3.AddAttribute(NamespacePrefixes.Xml, null, "space", Preservation.Preserve, true); // Child 1. data1 = expectedChildren.AddChild(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1", typeof(GenericElement)); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute1", "attribute 12"); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute2", "attribute 13"); data2 = data1.Children.AddChild(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element2", typeof(GenericElement)); data2.AddAttribute(ExtensibilityTests.Namespace1, "attribute3", "attribute 14"); data2.Text = "text 1"; // Child 2. data1 = expectedChildren.AddChild(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1", typeof(GenericElement)); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute1", "attribute 15"); data1.AddAttribute(ExtensibilityTests.Namespace1, "attribute2", "attribute 16"); data1.AddAttribute(ExtensibilityTests.Namespace2, "attribute1", "attribute 17"); data2 = data1.Children.AddChild(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1", typeof(GenericElement)); data2.AddAttribute(ExtensibilityTests.Namespace1, "attribute2", "attribute 18"); data2.Text = "text 3"; // Child 3. data1 = expectedChildren.AddChild(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1", typeof(GenericElement)); data1.AddAttribute(ExtensibilityTests.Namespace2, "attribute1", "attribute 19"); data1.AddAttribute(ExtensibilityTests.Namespace2, "attribute2", "attribute 20"); data2 = data1.Children.AddChild(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element2", typeof(GenericElement)); data2.AddAttribute(ExtensibilityTests.Namespace2, "attribute3", "attribute 21"); data3 = data2.Children.AddChild(NamespaceValues.Core, "target", typeof(Target)); data3.AddAttribute(null, "order", null, false); data3.AddAttribute(NamespacePrefixes.Xml, null, "lang", null, false); data3.AddAttribute(NamespacePrefixes.Xml, null, "space", Preservation.Default, false); // Child 4. data1 = expectedChildren.AddChild(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1", typeof(GenericElement)); data1.AddAttribute(ExtensibilityTests.Namespace2, "attribute1", "attribute 22"); data1.AddAttribute(ExtensibilityTests.Namespace2, "attribute2", "attribute 23"); data2 = data1.Children.AddChild(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element2", typeof(GenericElement)); data2.AddAttribute(ExtensibilityTests.Namespace2, "attribute3", "attribute 24"); data2.Text = "text 2"; this.VerifyExtensionChildren(" ", expectedChildren, extensible.Extensions[0]); Console.WriteLine("Verifying unit extensions."); extensible = (IExtensible)document.Files[0].Containers[0]; Assert.IsFalse(extensible.HasExtensions, "HasExtensions is incorrect."); }