public async Task Discover_InvokedTwiceAndCleared_TriggersNewDeviceTwice() { //Arange int newDeviceCallbackInvokations = 0; // Act using (var client = new OicClient()) { var service = new OicResourceDiscoverClient(client); client.AddTransport(_mockTransport.Object); service.NewDevice += (s, e) => { newDeviceCallbackInvokations++; }; await service.DiscoverAsync(); await Task.Delay(100); await service.DiscoverAsync(true); await Task.Delay(100); } // Assert Assert.That(newDeviceCallbackInvokations, Is.EqualTo(2), $"{typeof(OicResourceDiscoverClient)}.{nameof(OicResourceDiscoverClient.NewDevice)} was not invoked twice"); }
static void Main(string[] args) { using (_client = new OicClient()) { // Add a CoapTransport with a system assigned UDP Endpoint _client.AddTransport(new OicCoapTransport(new CoapUdpEndPoint())); // Create a discover client var discoverClient = new OicResourceDiscoverClient(_client); discoverClient.NewDevice += OnNewDevice; // Broadcast a discover request (GET /oic/res) discoverClient.DiscoverAsync().Wait(); Console.WriteLine("Press <Enter> to exit"); Console.ReadLine(); } }
public async Task TestDiscoverDevice() { //Arange bool newDeviceCallbackInvoked = false; OicDevice actualDevice = null; // Act using (var client = new OicClient()) { var service = new OicResourceDiscoverClient(client); client.AddTransport(_mockTransport.Object); service.NewDevice += (s, e) => { newDeviceCallbackInvoked = true; actualDevice = e.Device; }; await service.DiscoverAsync(); await Task.Delay(100); } // Assert Assert.IsTrue(newDeviceCallbackInvoked, $"{typeof(OicResourceDiscoverClient)}.{nameof(OicResourceDiscoverClient.NewDevice)} was not invoked"); var expectedDevice = new OicDevice() { DeviceId = Guid.Parse("0685B960-736F-46F7-BEC0-9E6CBD61ADC1"), Resources = { new CoreResources.OicDeviceResource { RelativeUri = "/oid/d", ResourceTypes ={ "oic.d.light", "oic.wk.d" }, Interfaces = OicResourceInterface.ReadOnly | OicResourceInterface.Baseline, }, new CoreResources.OicPlatformResource { RelativeUri = "/oid/p", ResourceTypes ={ "oic.wk.p" }, Interfaces = OicResourceInterface.ReadOnly | OicResourceInterface.Baseline, }, new ResourceTypes.SwitchBinary { RelativeUri = "/switch", ResourceTypes ={ "oic.r.switch.binary" }, Interfaces = OicResourceInterface.Actuator | OicResourceInterface.Baseline, }, new ResourceTypes.LightBrightness { RelativeUri = "/brightness", ResourceTypes ={ "oic.r.light.brightness" }, Interfaces = OicResourceInterface.Actuator | OicResourceInterface.Baseline, } } }; Assert.AreEqual(expectedDevice.DeviceId, actualDevice.DeviceId); Assert.AreEqual(expectedDevice.Resources, actualDevice.Resources); }