Exemplo n.º 1
0
        public void EventGridSchemaAdapterConvertNullThrowsExceptionTest()
        {
            // Arrange
            Mock <IEventGridIdentifySchemaService> mockEventGridIdentifySchemaService = new Mock <IEventGridIdentifySchemaService>();

            mockEventGridIdentifySchemaService.Setup(s => s.Identify(It.IsAny <string>())).Returns(Core.EventGridSchemaType.CloudEvent);
            IAdapter <string, List <EventGridEventModel> > adapter = new EventGridSchemaAdapter(mockEventGridIdentifySchemaService.Object);

            // Act
            var exception = Record.Exception(() => adapter.Convert(null));

            // Assert
            Assert.NotNull(exception);
        }
Exemplo n.º 2
0
        public void EventGridSchemaAdapterConvertCloudEventTest()
        {
            // Arrange
            string json = Data.GetMockCloudEventJson();
            Mock <IEventGridIdentifySchemaService> mockEventGridIdentifySchemaService = new Mock <IEventGridIdentifySchemaService>();

            mockEventGridIdentifySchemaService.Setup(s => s.Identify(json)).Returns(Core.EventGridSchemaType.CloudEvent);
            IAdapter <string, List <EventGridEventModel> > adapter = new EventGridSchemaAdapter(mockEventGridIdentifySchemaService.Object);
            var mockModel = JsonConvert.DeserializeObject <CloudEvent>(json);

            // Act
            var model = adapter.Convert(json).FirstOrDefault();

            // Assert
            Assert.True(model.Id == mockModel.Id && model.Subject == mockModel.Subject &&
                        model.EventType == mockModel.Type && model.EventTime == mockModel.Time);

            var data = JsonConvert.SerializeObject(mockModel, Formatting.Indented);

            Assert.Equal(data, model.Data);
        }