Exemple #1
0
        public async Task SubjectActionKeyAndValue()
        {
            var p = new Person {
                Id = Guid.NewGuid(), Name = "Caleb"
            };

            var ed = EventData.CreateValueEvent(p, "Subject", "Action");
            var eh = await new EventHubs.AzureEventHubsEventConverter {
                UseMessagingPropertiesForMetadata = true
            }.ConvertToAsync(ed);

            Assert.IsNotNull(eh);
            Assert.AreEqual("Subject", eh.Properties[EventMetadata.SubjectAttributeName]);
            Assert.AreEqual("Action", eh.Properties[EventMetadata.ActionAttributeName]);
            Assert.IsFalse(eh.Properties.ContainsKey(EventMetadata.TenantIdAttributeName));
            Assert.AreEqual(p.Id, eh.Properties[EventMetadata.KeyPropertyName]);

            ed = (EventData <Person>)await new EventHubs.AzureEventHubsEventConverter {
                UseMessagingPropertiesForMetadata = true
            }.ConvertFromAsync(typeof(Person), eh);
            Assert.IsNotNull(eh);
            Assert.AreEqual("Subject", ed.Subject);
            Assert.AreEqual("Action", ed.Action);
            Assert.AreEqual(null, ed.TenantId);
            Assert.AreEqual(p.Id, ed.Key);
            Assert.IsNotNull(ed.Value);
            Assert.AreEqual(p.Id, ed.Value.Id);
            Assert.AreEqual(p.Name, ed.Value.Name);
        }
Exemple #2
0
        public void SubjectActionKeyAndValue()
        {
            var p = new Person {
                Id = Guid.NewGuid(), Name = "Caleb"
            };

            var ed = EventData.CreateValueEvent(p, "Subject", "Action");
            var eh = ed.ToEventHubsEventData();

            Assert.IsNotNull(eh);
            Assert.AreEqual("Subject", eh.Properties[EventDataMapper.SubjectPropertyName]);
            Assert.AreEqual("Action", eh.Properties[EventDataMapper.ActionPropertyName]);
            Assert.AreEqual(null, eh.Properties[EventDataMapper.TenantIdPropertyName]);
            Assert.AreEqual(p.Id, eh.Properties[EventDataMapper.KeyPropertyName]);

            ed = eh.ToBeefEventData <Person>();
            Assert.IsNotNull(eh);
            Assert.AreEqual("Subject", ed.Subject);
            Assert.AreEqual("Action", ed.Action);
            Assert.AreEqual(null, ed.TenantId);
            Assert.AreEqual(p.Id, ed.Key);
            Assert.IsNotNull(ed.Value);
            Assert.AreEqual(p.Id, ed.Value.Id);
            Assert.AreEqual(p.Name, ed.Value.Name);
        }
Exemple #3
0
 public async Task A140_PowerSourceChangeSubscriber_InvalidData_Value()
 {
     await EventSubscriberTester.Create <Startup>()
     .ExpectResult(SubscriberStatus.InvalidData)
     .RunAsync <PowerSourceChangeSubscriber>(EventData.CreateValueEvent(new PowerSourceChangeData {
         RobotId = 1.ToGuid(), PowerSource = "!"
     }, $"Demo.Robot.{1.ToGuid()}", "PowerSourceChange"));
 }
Exemple #4
0
 public async Task A130_PowerSourceChangeSubscriber_NotFound()
 {
     await EventSubscriberTester.Create <Startup>()
     .ExpectResult(SubscriberStatus.DataNotFound)
     .RunAsync <PowerSourceChangeSubscriber>(EventData.CreateValueEvent(new PowerSourceChangeData {
         RobotId = 404.ToGuid(), PowerSource = "N"
     }, $"Demo.Robot.{404.ToGuid()}", "PowerSourceChange"));
 }
Exemple #5
0
        public async Task A150_PowerSourceChangeSubscriber_ManagerFailure()
        {
            var rm = new Mock <IRobotManager>();

            rm.Setup(x => x.GetAsync(1.ToGuid())).Throws(new InvalidOperationException("Get method failed!"));

            await EventSubscriberTester.Create <Startup>()
            .ExpectUnhandledException <InvalidOperationException>("*")
            .AddScopedService(rm.Object)
            .RunAsync <PowerSourceChangeSubscriber>(EventData.CreateValueEvent(new PowerSourceChangeData {
                RobotId = 1.ToGuid(), PowerSource = "N"
            }, $"Demo.Robot.{1.ToGuid()}", "PowerSourceChange"));
        }
Exemple #6
0
        public void A110_PowerSourceChangeSubscriber_NoUpdated()
        {
            var r = AgentTester.Create <RobotAgent, Robot>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.Agent.GetAsync(1.ToGuid())).Value;

            EventSubscriberTester.Create <PowerSourceChangeSubscriber>()
            .ExpectResult(SubscriberStatus.Success)
            .ExpectNoEvents()
            .Run(EventData.CreateValueEvent(r.PowerSourceSid, $"Demo.Robot.{r.Id}", "PowerSourceChange", r.Id));

            AgentTester.Create <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => r)
            .Run(a => a.Agent.GetAsync(1.ToGuid()));
        }
Exemple #7
0
        public async Task A110_PowerSourceChangeSubscriber_NoUpdated()
        {
            var r = (await AgentTester.Test <RobotAgent, Robot>()
                     .ExpectStatusCode(HttpStatusCode.OK)
                     .RunAsync(a => a.GetAsync(1.ToGuid()))).Value;

            await EventSubscriberTester.Create <Startup>()
            .ExpectResult(SubscriberStatus.Success)
            .ExpectNoEvents()
            .RunAsync <PowerSourceChangeSubscriber>(EventData.CreateValueEvent(new PowerSourceChangeData {
                RobotId = r.Id, PowerSource = r.PowerSourceSid
            }, $"Demo.Robot.{r.Id}", "PowerSourceChange"));

            await AgentTester.Test <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectValue(_ => r)
            .RunAsync(a => a.GetAsync(1.ToGuid()));
        }
Exemple #8
0
        public void A120_PowerSourceChangeSubscriber_Updated()
        {
            var r = AgentTester.Test <RobotAgent, Robot>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetAsync(1.ToGuid())).Value;

            r.PowerSourceSid = "N";

            _subscriberTester.Test <PowerSourceChangeSubscriber>()
            .ExpectResult(SubscriberStatus.Success)
            .ExpectEvent($"Demo.Robot.{r.Id}", "Update")
            .Run(EventData.CreateValueEvent(r.PowerSourceSid, $"Demo.Robot.{r.Id}", "PowerSourceChange", r.Id));

            AgentTester.Test <RobotAgent, Robot>()
            .ExpectStatusCode(HttpStatusCode.OK)
            .ExpectChangeLogUpdated("*")
            .ExpectETag(r.ETag)
            .ExpectValue(_ => r)
            .Run(a => a.GetAsync(1.ToGuid()));
        }
Exemple #9
0
        static async Task Main()
        {
            var cs  = Environment.GetEnvironmentVariable("Beef_EventHubConnectionString");
            var ehc = new AzureEventHubs.EventHubProducerClient(cs);
            var ehp = new EventHubProducer(ehc);

            cs = Environment.GetEnvironmentVariable("Beef_ServiceBusConnectionString");
            var sbsc = new AzureServiceBus.ServiceBusClient(cs);
            var sbs  = new ServiceBusSender(sbsc, "Default");

            Console.WriteLine("Options are:");
            Console.WriteLine(" x - Stop.");
            Console.WriteLine();
            Console.WriteLine("EventHubs...");
            Console.WriteLine(" 1 - Non-subscribed Event.");
            Console.WriteLine(" 2 - Null Identifier.");
            Console.WriteLine(" 3 - Not Found Exception.");
            Console.WriteLine(" 4 - Unhandled Exception.");
            Console.WriteLine(" 5 - Invalid Data.");
            Console.WriteLine(" 6 - Success.");
            Console.WriteLine();
            Console.WriteLine("ServiceBus...");
            Console.WriteLine(" 11 - Non-subscribed Event.");
            Console.WriteLine(" 12 - Null Identifier.");
            Console.WriteLine(" 13 - Not Found Exception.");
            Console.WriteLine(" 14 - Unhandled Exception.");
            Console.WriteLine(" 15 - Invalid Data.");
            Console.WriteLine(" 16 - Success.");
            Console.WriteLine();

            while (true)
            {
                Console.Write("Enter option: ");
                switch (Console.ReadLine())
                {
                case "x":
                    return;

                case "1":
                    ehp.Publish("Something.Random", "Blah");
                    await ehp.SendAsync();

                    break;

                case "2":
                    ehp.Publish("Demo.Robot.Null", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "3":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = Guid.NewGuid(), PowerSource = "N"
                    }, "Demo.Robot.???", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "4":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.88", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "5":
                    ehp.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "!"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    await ehp.SendAsync();

                    break;

                case "6":
                    var ed = EventData.CreateValueEvent(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    ed.Key          = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    ed.PartitionKey = PartitionKeyGenerator.Generate(Guid.NewGuid());
                    ehp.Publish(ed);
                    await ehp.SendAsync();

                    break;

                case "11":
                    sbs.Publish("Something.Random", "Blah");
                    await sbs.SendAsync();

                    break;

                case "12":
                    sbs.Publish("Demo.Robot.Null", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "13":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = Guid.NewGuid(), PowerSource = "N"
                    }, "Demo.Robot.???", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "14":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.88", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "15":
                    sbs.PublishValue(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "!"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    await sbs.SendAsync();

                    break;

                case "16":
                    ed = EventData.CreateValueEvent(new PowerSourceChangeData {
                        RobotId = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), PowerSource = "N"
                    }, "Demo.Robot.2", "PowerSourceChange");
                    ed.Key          = new Guid(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    ed.PartitionKey = PartitionKeyGenerator.Generate(Guid.NewGuid());
                    sbs.Publish(ed);
                    await sbs.SendAsync();

                    break;
                }

                ehp.Reset();
                sbs.Reset();
            }
        }
Exemple #10
0
 public void A150_PowerSourceChangeSubscriber_InvalidData_Value()
 {
     EventSubscriberTester.Create <PowerSourceChangeSubscriber>()
     .ExpectResult(SubscriberStatus.InvalidData)
     .Run(EventData.CreateValueEvent("!", $"Demo.Robot.{1.ToGuid()}", "PowerSourceChange", 1.ToGuid()));
 }
Exemple #11
0
 public void A140_PowerSourceChangeSubscriber_InvalidData_Key()
 {
     EventSubscriberTester.Create <PowerSourceChangeSubscriber>()
     .ExpectResult(SubscriberStatus.InvalidData)
     .Run(EventData.CreateValueEvent("N", $"Demo.Robot.Xyz", "PowerSourceChange", "Xyz"));
 }
Exemple #12
0
 public void A130_PowerSourceChangeSubscriber_NotFound()
 {
     EventSubscriberTester.Create <PowerSourceChangeSubscriber>()
     .ExpectResult(SubscriberStatus.DataNotFound)
     .Run(EventData.CreateValueEvent("N", $"Demo.Robot.{404.ToGuid()}", "PowerSourceChange", 404.ToGuid()));
 }