Exemple #1
0
        public async Task Post_Returns200_ForValidDeliveryService()
        {
            var deliveryCallerMock = new Mock <IDeliveryServiceCaller>();

            deliveryCallerMock.Setup(r => r.ScheduleDeliveryAsync(It.IsAny <Delivery>(), It.IsAny <string>()))
            .ReturnsAsync(new DeliverySchedule {
                Id = "deliveryid"
            }).Verifiable();

            var eventOp = new EventGridEvent();

            eventOp.EventType = "GetDrone";
            eventOp.Data      = new Delivery();
            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    new Mock <IDroneSchedulerServiceCaller>().Object,
                                                    deliveryCallerMock.Object,
                                                    new Mock <IEventRepository>().Object,
                                                    new Mock <ILogger <ChoreographyController> >().Object);

            EventGridEvent[] events = new EventGridEvent[1];

            events[0] = eventOp;
            var result = await target.Post(events) as OkObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(200, result.StatusCode);
            deliveryCallerMock.Verify();
        }
Exemple #2
0
        public async Task Post_Returns400_WhenDroneServiceFailsToSendEvent()
        {
            var loggerMock             = new Mock <ILogger <ChoreographyController> >();
            var droneServiceCallerMock = new Mock <IDroneSchedulerServiceCaller>();

            droneServiceCallerMock.Setup(r => r.GetDroneIdAsync(It.IsAny <Delivery>()))
            .ReturnsAsync("droneId").Verifiable();
            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(e => e.SendEventAsync(It.IsAny <List <EventGridEvent> >()))
            .ThrowsAsync(new EventException()).Verifiable();

            var eventOp = new EventGridEvent();

            eventOp.EventType = "CreatePackage";
            eventOp.Data      = new Delivery();
            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    droneServiceCallerMock.Object,
                                                    new Mock <IDeliveryServiceCaller>().Object,
                                                    eventRepositoryMock.Object,
                                                    loggerMock.Object);

            EventGridEvent[] events = new EventGridEvent[1];
            events[0] = eventOp;
            var result = await target.Post(events) as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            droneServiceCallerMock.Verify();
            eventRepositoryMock.Verify();
            loggerMock.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once);
        }
Exemple #3
0
        public async Task Post_Returns200_ForValidDroneService()
        {
            var droneServiceCallerMock = new Mock <IDroneSchedulerServiceCaller>();

            droneServiceCallerMock.Setup(r => r.GetDroneIdAsync(It.IsAny <Delivery>()))
            .ReturnsAsync("droneId").Verifiable();
            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(e => e.SendEventAsync(It.IsAny <List <EventGridEvent> >()))
            .Returns(Task.CompletedTask).Verifiable();

            var eventOp = new EventGridEvent();

            eventOp.EventType = "CreatePackage";
            eventOp.Data      = new Delivery();
            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    droneServiceCallerMock.Object,
                                                    new Mock <IDeliveryServiceCaller>().Object,
                                                    eventRepositoryMock.Object,
                                                    new Mock <ILogger <ChoreographyController> >().Object);

            EventGridEvent[] events = new EventGridEvent[1];
            events[0] = eventOp;
            var result = await target.Post(events) as OkObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(200, result.StatusCode);
            droneServiceCallerMock.Verify();
            eventRepositoryMock.Verify();
        }
Exemple #4
0
        public async Task Post_Returns400_ForNoEvent_AndIslogged()
        {
            var loggerMock = new Mock <ILogger <ChoreographyController> >();

            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    new Mock <IDroneSchedulerServiceCaller>().Object,
                                                    new Mock <IDeliveryServiceCaller>().Object,
                                                    new Mock <IEventRepository>().Object,
                                                    loggerMock.Object);

            var result = await target.Post(null) as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            loggerMock.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once);
        }
Exemple #5
0
        public async Task Post_Returns200_ForSubscriptionValidationData()
        {
            var eventOp = new EventGridEvent();

            eventOp.EventType = EventTypes.EventGridSubscriptionValidationEvent;
            eventOp.Data      = eventValidationData;
            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    new Mock <IDroneSchedulerServiceCaller>().Object,
                                                    new Mock <IDeliveryServiceCaller>().Object,
                                                    new Mock <IEventRepository>().Object,
                                                    new Mock <ILogger <ChoreographyController> >().Object);

            EventGridEvent[] events = new EventGridEvent[1];

            events[0] = eventOp;

            var result = await target.Post(events) as OkObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(200, result.StatusCode);
        }
Exemple #6
0
        public async Task Post_Returns400_ForNullDelivery()
        {
            var loggerMock = new Mock <ILogger <ChoreographyController> >();
            var eventOp    = new EventGridEvent();

            eventOp.EventType = "GetDrone";
            eventOp.Data      = null;
            var target = new ChoreographyController(new Mock <IPackageServiceCaller>().Object,
                                                    new Mock <IDroneSchedulerServiceCaller>().Object,
                                                    new Mock <IDeliveryServiceCaller>().Object,
                                                    new Mock <IEventRepository>().Object,
                                                    loggerMock.Object);

            EventGridEvent[] events = new EventGridEvent[1];
            events[0] = eventOp;
            var result = await target.Post(events) as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            loggerMock.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once);
        }