public void GetDataMethodSadPath1()
        {
            CloudEvent cloudEvent = null !;

            Action act = () => cloudEvent.GetData <TestClient>();

            act.Should().ThrowExactly <ArgumentNullException>().WithMessage("*cloudEvent*");
        }
        public void GetDataMethodSadPath2()
        {
            var cloudEvent    = new CloudEvent();
            var serialization = (DataSerialization)(-123);

            Action act = () => cloudEvent.GetData <TestClient>(serialization);

            act.Should().ThrowExactly <ArgumentOutOfRangeException>().WithMessage("*serialization*");
        }
        public void GetDataMethodSadPath5()
        {
            var cloudEvent = new CloudEvent();

            _dataObjects.Add(cloudEvent, new NotAClient());

            Action act = () => cloudEvent.GetData <TestClient>();

            act.Should().ThrowExactly <InvalidCastException>();
        }
        public void GetDataMethodSadPath4()
        {
            var cloudEvent = new CloudEvent();

            cloudEvent.Unlock()._data = "Not valid JSON";

            Action act = () => cloudEvent.GetData <TestClient>(DataSerialization.Xml);

            act.Should().Throw <InvalidOperationException>();
        }
        public void GetDataMethodSadPath3()
        {
            var cloudEvent = new CloudEvent();

            cloudEvent.Unlock()._data = "Not valid JSON";

            Action act = () => cloudEvent.GetData <TestClient>();

            act.Should().Throw <JsonException>();
        }
        public void GetDataMethodHappyPath3()
        {
            var cloudEvent = new CloudEvent();
            var client     = new TestClient {
                FirstName = "First", LastName = "Last"
            };

            _dataObjects.Add(cloudEvent, client);

            cloudEvent.GetData <TestClient>().Should().BeSameAs(client);
        }
Esempio n. 7
0
        public async Task SerializesExpectedProperties_BaseType()
        {
            var mockTransport = new MockTransport(new MockResponse(200));
            var options       = new EventGridPublisherClientOptions
            {
                Transport = mockTransport
            };
            EventGridPublisherClient client =
                new EventGridPublisherClient(
                    new Uri("http://localHost"),
                    new AzureKeyCredential("fakeKey"),
                    options);
            var cloudEvent = new CloudEvent(
                "record",
                "Microsoft.MockPublisher.TestEvent",
                new DerivedTestPayload
            {
                Name            = "name",
                Age             = 10,
                DerivedProperty = 5
            },
                "TestPayload",
                typeof(TestPayload));

            // since the data has not yet been serialized (CloudEvent not constructed from Parse method), GetData returns the passed in instance.
            Assert.AreEqual(5, cloudEvent.GetData <DerivedTestPayload>().DerivedProperty);

            // GetData returns as BinaryData so it will always serialize first even if cloudEvent was not constructed by calling Parse.
            Assert.IsNull(cloudEvent.GetData().ToObjectFromJson <DerivedTestPayload>().DerivedProperty);

            List <CloudEvent> eventsList = new List <CloudEvent>()
            {
                cloudEvent
            };

            await client.SendEventsAsync(eventsList);

            cloudEvent = DeserializeRequest(mockTransport.SingleRequest).First();
            Assert.IsNull(cloudEvent.GetData <DerivedTestPayload>().DerivedProperty);
            Assert.IsNull(cloudEvent.GetData().ToObjectFromJson <DerivedTestPayload>().DerivedProperty);
        }
        public void GetDataMethodHappyPath2()
        {
            var cloudEvent = new CloudEvent();
            var clientData = XmlSerialize(new TestClient {
                FirstName = "First", LastName = "Last"
            });

            cloudEvent.Unlock()._data = clientData;

            var client = cloudEvent.GetData <TestClient>(DataSerialization.Xml);

            client.FirstName.Should().Be("First");
            client.LastName.Should().Be("Last");
        }
        public void GetDataMethodHappyPath1()
        {
            var cloudEvent = new CloudEvent();
            var clientData = JsonConvert.SerializeObject(new TestClient {
                FirstName = "First", LastName = "Last"
            });

            cloudEvent.Unlock()._data = clientData;

            var client = cloudEvent.GetData <TestClient>();

            client.FirstName.Should().Be("First");
            client.LastName.Should().Be("Last");
        }
Esempio n. 10
0
        public async Task SerializesExpectedProperties_DerivedType()
        {
            var mockTransport = new MockTransport(new MockResponse(200));
            var options       = new EventGridPublisherClientOptions
            {
                Transport = mockTransport
            };
            EventGridPublisherClient client =
                new EventGridPublisherClient(
                    new Uri("http://localHost"),
                    new AzureKeyCredential("fakeKey"),
                    options);
            var cloudEvent = new CloudEvent(
                "record",
                "Microsoft.MockPublisher.TestEvent",
                new DerivedTestPayload
            {
                Name            = "name",
                Age             = 10,
                DerivedProperty = 5
            },
                "TestPayload");

            Assert.AreEqual(5, cloudEvent.GetData <DerivedTestPayload>().DerivedProperty);
            Assert.AreEqual(5, cloudEvent.GetData().ToObjectFromJson <DerivedTestPayload>().DerivedProperty);

            List <CloudEvent> eventsList = new List <CloudEvent>()
            {
                cloudEvent
            };

            await client.SendEventsAsync(eventsList);

            cloudEvent = DeserializeRequest(mockTransport.SingleRequest).First();
            Assert.AreEqual(5, cloudEvent.GetData <DerivedTestPayload>().DerivedProperty);
            Assert.AreEqual(5, cloudEvent.GetData().ToObjectFromJson <DerivedTestPayload>().DerivedProperty);
        }