public async void Function_Returns_Ok_Result_And_Adds_Message_To_Collector_When_Order_Is_Valid()
        {
            var order = new RecognitionOrder()
            {
                DestinationFolder = "testFolder",
                EmailAddress      = "*****@*****.**",
                PhoneNumber       = "+123456789",
                PhotosSource      = "testSource",
                RecognitionName   = "testName",
                PatternFaces      = new string[] { }
            };

            var queueCollector = new AsyncCollector <RecognitionOrder>();
            var mockValidator  = new Mock <IRecOrderValidator>();

            mockValidator.Setup(x => x.IsValid(It.IsAny <RecognitionOrder>())).Returns(true);

            var query = new Dictionary <String, StringValues>();
            var body  = JsonConvert.SerializeObject(order);

            var result = await RecognitionStart.Run(req : HttpRequestSetup(query, body), validator : mockValidator.Object, queueWithRecOrders : queueCollector, log : log);

            Assert.IsType <OkResult>(result);
            Assert.NotEmpty(queueCollector.Items);
            Assert.Equal(order.DestinationFolder, queueCollector.Items[0].DestinationFolder);
            Assert.Equal(order.EmailAddress, queueCollector.Items[0].EmailAddress);
            Assert.Equal(order.PhoneNumber, queueCollector.Items[0].PhoneNumber);
            Assert.Equal(order.PhotosSource, queueCollector.Items[0].PhotosSource);
            Assert.Equal(order.RecognitionName, queueCollector.Items[0].RecognitionName);
            Assert.Equal(order.PatternFaces, queueCollector.Items[0].PatternFaces);
        }
Пример #2
0
        public static async Task TrainPersonSequenceStart(
            [QueueTrigger("modeltraining", Connection = "StorageConnectionString")] RecognitionOrder order,
            [OrchestrationClient] DurableOrchestrationClient starter,
            TraceWriter log)
        {
            string instanceId = await starter.StartNewAsync("TrainPersonSequence", order);

            log.Info($"Started orchestration with ID = '{instanceId}'. Processing: {order.RecognitionName}.");
        }
Пример #3
0
        public static async Task ValidationSequenceStart(
            [QueueTrigger("recognitionqueue", Connection = "StorageConnectionString")] RecognitionOrder order,
            [OrchestrationClient] DurableOrchestrationClient starter,
            TraceWriter log)
        {
            string instanceId = await starter.StartNewAsync("ValidationSequence", order);

            log.Info($"Started orchestration with ID = '{instanceId}'. For recognition: {order.RecognitionName}.");
        }
Пример #4
0
        public void IsValid_Should_Return_True_When_Order_Is_Valid()
        {
            var validator = new RecOrderValidator();
            var order     = new RecognitionOrder()
            {
                DestinationFolder = "testFolder",
                EmailAddress      = "*****@*****.**",
                PhoneNumber       = "+48123456789",
                SourcePath        = "testSource",
                RecognitionName   = "testName",
                PatternFaces      = new string[] { "testFace" }
            };

            Assert.True(validator.IsValid(order));
        }
Пример #5
0
        public async void RecognitionStart_Returns_Bad_Request_When_Order_Not_Valid()
        {
            var order          = new RecognitionOrder();
            var queueCollector = new AsyncCollector <RecognitionOrder>();
            var mockValidator  = new Mock <IRecOrderValidator>();

            mockValidator.Setup(x => x.IsValid(It.IsAny <RecognitionOrder>())).Returns(false);

            var body    = JsonConvert.SerializeObject(order);
            var request = HttpRequestSetup(body, HttpMethod.Post, "https://localhost");
            var result  = await RecognitionStart.Run(req : request, validator : mockValidator.Object, queueWithRecOrders : queueCollector, log : log);

            var resultObject = result;

            Assert.Equal(HttpStatusCode.BadRequest, resultObject.StatusCode);
        }
Пример #6
0
        public void IsValid_Should_Return_False_When_Pattern_Faces_Array_Is_Empty()
        {
            var validator = new RecOrderValidator();

            var order = new RecognitionOrder()
            {
                DestinationFolder = "testFolder",
                EmailAddress      = "*****@*****.**",
                PhoneNumber       = "+123456789",
                PhotosSource      = "testSource",
                RecognitionName   = "testName",
                PatternFaces      = new string[] {}
            };

            Assert.False(validator.IsValid(order));
        }
        public async void Function_Returns_Bad_Request_When_Order_Not_Valid()
        {
            var order          = new RecognitionOrder();
            var queueCollector = new AsyncCollector <RecognitionOrder>();
            var mockValidator  = new Mock <IRecOrderValidator>();

            mockValidator.Setup(x => x.IsValid(It.IsAny <RecognitionOrder>())).Returns(false);

            var query = new Dictionary <String, StringValues>();
            var body  = JsonConvert.SerializeObject(order);

            var result = await RecognitionStart.Run(req : HttpRequestSetup(query, body), validator : mockValidator.Object, queueWithRecOrders : queueCollector, log : log);

            var resultObject = (BadRequestObjectResult)result;

            Assert.Equal("Provided data is invalid", resultObject.Value);
        }
Пример #8
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req,
                                                           [Queue("recognitionqueue", Connection = "ImageStorageAccount")] IAsyncCollector <RecognitionOrder> queueWithRecOrders,
                                                           TraceWriter log)
        {
            string requestBody = await req.Content.ReadAsStringAsync();

            RecognitionOrder recognitionOrder = JsonConvert.DeserializeObject <RecognitionOrder>(requestBody);

            if (!IsValid(recognitionOrder))
            {
                return(req.CreateErrorResponse(HttpStatusCode.BadRequest, "Provided data is invalid"));
            }
            await queueWithRecOrders.AddAsync(recognitionOrder);

            await queueWithRecOrders.FlushAsync();

            return(req.CreateResponse(HttpStatusCode.OK));
        }
Пример #9
0
        public async void RecognitionStart_Adds_Message_To_Collector_When_Order_Is_Valid()
        {
            var order = new RecognitionOrder()
            {
                DestinationFolder = "testFolder",
                EmailAddress      = "*****@*****.**",
                PhoneNumber       = "+48123456789",
                SourcePath        = "testSource",
                RecognitionName   = "testName",
                PatternFaces      = new string[] { }
            };
            var queueCollector = new AsyncCollector <RecognitionOrder>();
            var mockValidator  = new Mock <IRecOrderValidator>();

            mockValidator.Setup(x => x.IsValid(It.IsAny <RecognitionOrder>())).Returns(true);

            var body    = JsonConvert.SerializeObject(order);
            var request = HttpRequestSetup(body, HttpMethod.Post, "https://localhost");
            await RecognitionStart.Run(req : request, validator : mockValidator.Object, queueWithRecOrders : queueCollector, log : log);

            Assert.NotEmpty(queueCollector.Items);
            Assert.Equal(order.EmailAddress, queueCollector.Items[0].EmailAddress);
        }
Пример #10
0
 private static bool IsValid(RecognitionOrder recognitionOrder)
 {
     if (string.IsNullOrWhiteSpace(recognitionOrder.DestinationFolder))
     {
         return(false);
     }
     if (string.IsNullOrWhiteSpace(recognitionOrder.SourcePath))
     {
         return(false);
     }
     if (!recognitionOrder.PatternFaces.Any())
     {
         return(false);
     }
     if (string.IsNullOrWhiteSpace(recognitionOrder.EmailAddress) || !EmailAddressAttribute.IsValid(recognitionOrder.EmailAddress))
     {
         return(false);
     }
     if (!PhoneRegex.Match(recognitionOrder.PhoneNumber).Success)
     {
         return(false);
     }
     return(true);
 }
Пример #11
0
        public static async Task Run([ActivityTrigger] RecognitionOrder recognitionOrder, [Queue("modeltraining", Connection = "StorageConnectionString")] IAsyncCollector <RecognitionOrder> queue)
        {
            await queue.AddAsync(recognitionOrder);

            await queue.FlushAsync();
        }