public Issue8CrashDuringDecodingOfHttpMessage() { _messageReceivedEvent = new ManualResetEvent(false); var moduleManager = new ModuleManager(); var myM = new MyModule(_messageReceivedEvent); moduleManager.Add(myM); _server = new HttpServer(moduleManager); _server.Start(IPAddress.Any, 8088); }
public async Task When_Twin_Has_No_Value_Temperature_Threshold_Is_Default() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(25d, module.TemperatureThreshold); }
public async Task When_Twin_Is_Update_With_New_Threshold_Current_State_Is_Updated() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); await moduleClient.TriggerDesiredPropertyChange(new { TemperatureThreshold = 100.0 }); Assert.Equal(100.0, module.TemperatureThreshold); }
public async Task When_Twin_Has_Value_Temperature_Threshold_Is_Initialized() { var moduleClient = new ModuleClientForTest() .SetGetTwinResult(new { TemperatureThreshold = 45.0 }); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(45d, module.TemperatureThreshold); }
public static void DisableLogging_Should_Not_Have_Effect_When_Module_Is_Null() { // arrange MyModule module = null; // act module.DisableLogging(); // assert Assert.Null(module); }
public async Task When_Payload_Is_Invalid_Ignore() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(MessageResponse.Completed, await moduleClient.RouteMessage("input1", "{ 'MachineTemperature': '30")); var actualOutputMessages = moduleClient.GetSentEvents("output1"); Assert.Empty(actualOutputMessages); }
public async Task When_Payload_Has_Different_Contract_Ignore() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(MessageResponse.Completed, await moduleClient.RouteMessage("input1", new { wrongProperty = 30 })); var actualOutputMessages = moduleClient.GetSentEvents("output1"); Assert.Empty(actualOutputMessages); }
public static void DisableLogging_Should_Not_Have_Effect_When_Module_Context_Items_Is_Null() { // arrange MyModule module = new MyModule(); module.Context = new NancyContext(); // act module.DisableLogging(); // assert Assert.NotNull(module.Context.Items["DisableLogging"]); }
public async Task When_Temperature_Is_Lesser_Than_Default_Threshold_Ignore() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(MessageResponse.Completed, await moduleClient.RouteMessage("input1", new DevicePayload { Machine = new MachineTelemetry { Temperature = 20 } })); var actualOutputMessages = moduleClient.GetSentEvents("output1"); Assert.Empty(actualOutputMessages); }
public void IfNotRegistered_ConditionalInModuleIsDecoratedWhenModuleRegistered2nd() { var builder = new ContainerBuilder(); var module = new MyModule(build => { build.RegisterType <ServiceA>().As <IService>().IfNotRegistered(typeof(IService)); }); builder.RegisterDecorator <Decorator, IService>(); builder.RegisterModule(module); var container = builder.Build(); var result = container.Resolve <IService>(); Assert.IsType <Decorator>(result); }
public async Task When_Temperature_Is_Higher_Than_Default_Threshold_Forwards_To_IotHub() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); Assert.Equal(MessageResponse.Completed, await moduleClient.RouteMessage("input1", new DevicePayload { Machine = new MachineTelemetry { Temperature = 30 } })); var actualOutputMessages = moduleClient.GetSentEvents("output1"); Assert.Single(actualOutputMessages); Assert.True(actualOutputMessages.First().Properties.ContainsKey("alert"), "Ensure 'alert' property was created"); }
public void DisableLog_Should_Works() { // arrange string originIp = null; var protocolVersion = "1.1"; var requestMethod = "POST"; string requestBody = null; var requestUrl = "http://some.thing.xp/log-disabled?sometest=rrtt"; var requestHeaders = new Dictionary <string, IEnumerable <string> > { { "Content-Type", new string[] { "text/html" } }, { "Accept", new string[] { "text/html", "text/xml" } } }; var responseHeaders = new Dictionary <string, string> { { "Content-Type", "text/html" }, }; var responseStatusCode = HttpStatusCode.BadRequest; string Content = null; var context = NancyContextMock.Create( requestMethod, requestUrl, requestBody, requestHeaders, responseStatusCode, Content, responseHeaders, originIp, protocolVersion); var logger = new CommunicationLogger(); var module = new MyModule(); module.Context = context; module.DisableLogging(); // act logger.LogData(context); // assert Assert.DoesNotContain("log-disabled", this.TestOutputHelper.Output); }
public async Task When_Message_Is_Forwarded_Properties_Are_Copied() { var moduleClient = new ModuleClientForTest(); var module = new MyModule(moduleClient, this.logger); await module.InitializeAsync(); var message = new Message(UTF8Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new DevicePayload { Machine = new MachineTelemetry { Temperature = 30 } }))); message.Properties.Add("MyProperty", "MyValue"); Assert.Equal(MessageResponse.Completed, await moduleClient.RouteMessage("input1", message)); var actualOutputMessages = moduleClient.GetSentEvents("output1"); Assert.Single(actualOutputMessages); Assert.True(actualOutputMessages.First().Properties.ContainsKey("alert"), "Ensure 'alert' property was created"); Assert.True(actualOutputMessages.First().Properties.ContainsKey("MyProperty"), "Ensure 'MyProperty' property was copied"); Assert.Equal("MyValue", actualOutputMessages.First().Properties["MyProperty"]); }
protected void Page_Unload(object sender, EventArgs e) { MyModule.WriteLog(this.GetType() + "Page:UnLoad"); }
// pass other methods through. public static int OtherMethod(int x, int y) { return(MyModule.OtherMethod(x, y)); }
protected override void Render(HtmlTextWriter output) { MyModule.WriteLog(this.GetType() + "Page:Render"); base.Render(output); }
protected void Button1_Click(object sender, EventArgs e) { MyModule.WriteLog(this.GetType() + "Page:Event"); }
public override void Validate() { MyModule.WriteLog(this.GetType() + "Page:Validate"); }
protected void Page_init(object sender, EventArgs e) { MyModule.WriteLog(this.GetType() + "Page:Init"); }
public void ProcessRequest(HttpContext context) { MyModule.WriteLog("Handler:" + DateTime.Now.ToString("yyyy-MM-dd")); //context.Response.Write(" Handler:" + DateTime.Now.ToString("yyyy-MM-dd")); }