Ejemplo n.º 1
0
        public void ReturnSensorNotAvailableIfSensorStopped()
        {
            var queryRequester     = CreateTestProbe();
            var temperatureSensor1 = CreateTestProbe();

            var floorQuery = Sys.ActorOf(FloorQuery.Props(
                                             actorRefToSensorId: new Dictionary <IActorRef, string>
            {
                [temperatureSensor1.Ref] = "s1",
            },
                                             requestId: 12,
                                             requester: queryRequester.Ref,
                                             timeout: TimeSpan.FromSeconds(3)
                                             ), "floor-query");

            temperatureSensor1.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                m.RequestId.Should().Be(FloorQuery.TemperatureRequestCorrelactionId);
                sender.Should().Be(floorQuery);
            });

            temperatureSensor1.Tell(PoisonPill.Instance);


            queryRequester.ExpectMsg <RespondFloorTemperatures>((m) =>
            {
                m.RequestId.Should().Be(12);
                m.TemperatureReadings.Count.Should().Be(1);

                m.TemperatureReadings["s1"].Should().BeAssignableTo <SensorNotAvailable>();
            });
        }
Ejemplo n.º 2
0
        public void ReturnTemperatures()
        {
            var queryRequester     = CreateTestProbe();
            var temperatureSensor1 = CreateTestProbe();
            var temperatureSensor2 = CreateTestProbe();
            var temperatureSensor3 = CreateTestProbe();

            var floorQuery = Sys.ActorOf(FloorQuery.Props(
                                             actorRefToSensorId: new Dictionary <IActorRef, string>
            {
                [temperatureSensor1.Ref] = "s1",
                [temperatureSensor2.Ref] = "s2",
                [temperatureSensor3.Ref] = "s3"
            },
                                             requestId: 12,
                                             requester: queryRequester.Ref,
                                             timeout: TimeSpan.FromSeconds(3)
                                             ), "floor-query");

            temperatureSensor1.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                m.RequestId.Should().Be(FloorQuery.TemperatureRequestCorrelactionId);
                sender.Should().Be(floorQuery);
            });
            temperatureSensor2.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                m.RequestId.Should().Be(FloorQuery.TemperatureRequestCorrelactionId);
                sender.Should().Be(floorQuery);
            });
            temperatureSensor3.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                m.RequestId.Should().Be(FloorQuery.TemperatureRequestCorrelactionId);
                sender.Should().Be(floorQuery);
            });

            floorQuery.Tell(new RespondTemperature(
                                FloorQuery.TemperatureRequestCorrelactionId, 23.5m), temperatureSensor1.Ref);
            floorQuery.Tell(new RespondTemperature(
                                FloorQuery.TemperatureRequestCorrelactionId, 13.2m), temperatureSensor2.Ref);
            floorQuery.Tell(new RespondTemperature(
                                FloorQuery.TemperatureRequestCorrelactionId, null), temperatureSensor3.Ref);

            queryRequester.ExpectMsg <RespondFloorTemperatures>((m) =>
            {
                m.RequestId.Should().Be(12);
                m.TemperatureReadings.Count.Should().Be(3);

                m.TemperatureReadings["s1"].Should().BeAssignableTo <TemperatureAvailable>();
                m.TemperatureReadings["s1"].As <TemperatureAvailable>().Temperature.Should().Be(23.5m);

                m.TemperatureReadings["s2"].Should().BeAssignableTo <TemperatureAvailable>();
                m.TemperatureReadings["s2"].As <TemperatureAvailable>().Temperature.Should().Be(13.2m);

                m.TemperatureReadings["s3"].Should().BeAssignableTo <NoTemperatureAvailable>();
            });
        }
Ejemplo n.º 3
0
        public void ReturnTemperatures()
        {
            var queryRequester = CreateTestProbe();

            var temperatureSensor1 = CreateTestProbe();
            var temperatureSensor2 = CreateTestProbe();

            var floorQuery = Sys.ActorOf(FloorQuery.Props(actorToSensorId: new Dictionary <IActorRef, string>
            {
                [temperatureSensor1.Ref] = "sensor1",
                [temperatureSensor2.Ref] = "sensor2"
            },
                                                          requestId: 1,
                                                          requester: queryRequester.Ref,
                                                          timeout: TimeSpan.FromSeconds(3)
                                                          ));

            temperatureSensor1.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                Assert.Equal(FloorQuery.TemperatureRequestCorrelationId, m.RequestId);
                Assert.Equal(floorQuery, sender);
            });

            temperatureSensor2.ExpectMsg <RequestTemperature>((m, sender) =>
            {
                Assert.Equal(FloorQuery.TemperatureRequestCorrelationId, m.RequestId);
                Assert.Equal(floorQuery, sender);
            });

            floorQuery.Tell(new RespondTemperature(FloorQuery.TemperatureRequestCorrelationId, 23.9), temperatureSensor1.Ref);
            floorQuery.Tell(new RespondTemperature(FloorQuery.TemperatureRequestCorrelationId, 32.4), temperatureSensor2.Ref);

            var response = queryRequester.ExpectMsg <RespondAllTemperatures>();

            Assert.Equal(1, response.RequestId);
            Assert.Equal(2, response.TemperatureReadings.Count);

            var temperatureReading1 =
                Assert.IsAssignableFrom <TemperatureAvailable>(response.TemperatureReadings["sensor1"]);

            Assert.Equal(23.9, temperatureReading1.Temperature);

            var temperatureReading2 =
                Assert.IsAssignableFrom <TemperatureAvailable>(response.TemperatureReadings["sensor1"]);

            Assert.Equal(32.4, temperatureReading2.Temperature);
        }