public void GetAllImages()
 {
     try
     {
         using (MockContext context = MockContext.Start("ImageListManagement"))
         {
             //GetImageLists();
             // wait(2);
             api = ContentModeratorAPI.GET_ALL_IMAGES;
             //imageListId = ((int)allImageLists[0].Id).ToString();
             HttpMockServer.Initialize("ImageListManagement", "GetAllImages");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetResponse(client, api, imageListId);
             results = Constants.GetResponse(client, api, "157299");
             var getAllImagesFromListId = results.GetAllImages;
             allImages = getAllImagesFromListId.Body;
             Assert.NotNull(getAllImagesFromListId);
             Assert.Equal(HttpStatusCode.OK, getAllImagesFromListId.Response.StatusCode);
             Assert.Equal("157299", getAllImagesFromListId.Body.ContentSource);
             //Assert.Equal(imageListId, getAllImagesFromListId.Body.ContentSource);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #2
0
        public void OCRRaw()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "OCRRaw");
                    //wait(2);
                    Stream imgStream = new FileStream(rawImageCurrentPath, FileMode.Open, FileAccess.Read);
                    api    = ContentModeratorAPI.OCR;
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());

                    results = Constants.GetImageResponseRaw(client, api, "", imgStream, MIMETypes.IMAGE_JPEG.GetDescription());
                    if (results.InnerException == null)
                    {
                        var ocr = results.OCR;
                        Assert.NotNull(ocr);
                        Assert.Equal(HttpStatusCode.OK, ocr.Response.StatusCode);
                        Assert.True(Helpers.Utilities.VerifyOCR(ocr.Body), TestBase.ErrorMessage);
                    }
                    else
                    {
                        var ex = results.InnerException;
                        Assert.NotNull(ex);
                        Assert.Equal(HttpStatusCode.BadRequest, ex.Response.StatusCode);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void FindFaces()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "FindFaces");
                    //GetImageLists();

                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    api     = ContentModeratorAPI.FIND_FACES;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);

                    var findfaces = results.FoundFaces;
                    Assert.NotNull(findfaces);
                    Assert.Equal(HttpStatusCode.OK, findfaces.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyFoundFaces(findfaces.Body), TestBase.ErrorMessage);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #4
0
        public void AddTerm()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    //if (allTermLists.Count == 1)
                    //{
                    //    CreateTermLists();
                    //}
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    api = ContentModeratorAPI.ADD_TERM;
                    HttpMockServer.Initialize("TextListManagement", "AddTerm");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetResponse(client, api, "67");

                    var addTermToListId = results.AddTerm;
                    Assert.NotNull(addTermToListId);
                    Assert.Equal(HttpStatusCode.Created, addTermToListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #5
0
        public void RefreshIndexTermList()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    api = ContentModeratorAPI.REFRESH_INDEX_TERM_LIST;
                    TermListIdToUpdate = ((int)allTermLists[1].Id).ToString();
                    HttpMockServer.Initialize("TextListManagement", "RefreshIndexTermList");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListIdToUpdate);
                    results = Constants.GetResponse(client, api, "67");
                    var refreshIndexTermList = results.RefreshIndexTermList;

                    Assert.NotNull(refreshIndexTermList);
                    Assert.Equal(HttpStatusCode.OK, refreshIndexTermList.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyRefreshIndex(refreshIndexTermList.Body));
                    Assert.Equal("RefreshIndex successfully completed.", refreshIndexTermList.Body.Status.Description);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #6
0
        public void GetAllTerms()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    api = ContentModeratorAPI.GET_ALL_TERMS;
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    HttpMockServer.Initialize("TextListManagement", "GetAllTerms");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId);
                    results = Constants.GetResponse(client, api, "67");
                    var getAllTermsFromListId = results.GetAllTerms;


                    allTerms = getAllTermsFromListId.Body;
                    Assert.NotNull(getAllTermsFromListId);
                    Assert.NotNull(getAllTermsFromListId.Body.Data);
                    Assert.NotNull(getAllTermsFromListId.Body.Paging);
                    Assert.Equal(HttpStatusCode.OK, getAllTermsFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DeleteImage()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageListManagement"))
                {
                    //GetAllImages();
                    //wait(2);
                    //if (allImages.ContentIds.Count == 0)
                    //{
                    //    AddImage();
                    //    GetAllImages();
                    //}

                    api = ContentModeratorAPI.DELETE_IMAGE;
                    HttpMockServer.Initialize("ImageListManagement", "DeleteImage");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //string imageId = allImages.ContentIds[0].Value.ToString();

                    //results = Constants.GetResponse(client, api, imageListId, MIMETypes.JSON.GetDescription(), "eng", string.Empty, false, imageId);
                    results = Constants.GetResponse(client, api, "157299", MIMETypes.JSON.GetDescription(), "eng", string.Empty, false, "157332");
                    var deleteImageFromListId = results.DeleteImage;
                    Assert.NotNull(deleteImageFromListId);
                    Assert.Equal(HttpStatusCode.OK, deleteImageFromListId.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #8
0
 public void GetDetailsTermList()
 {
     try
     {
         using (MockContext context = MockContext.Start("TextListManagement"))
         {
             //GetTermLists();
             // wait(2);
             api = ContentModeratorAPI.GET_DETAILS_TERM_LIST;
             //TermListIdToUpdate = ((int)allTermLists[1].Id).ToString();
             HttpMockServer.Initialize("TextListManagement", "GetDetailsTermList");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetResponse(client, api, TermListIdToUpdate);
             results = Constants.GetResponse(client, api, "67");
             var getdetailsTermList = results.GetDetailsTermList;
             Assert.NotNull(getdetailsTermList);
             Assert.Equal(HttpStatusCode.OK, getdetailsTermList.Response.StatusCode);
             Assert.Equal("67", getdetailsTermList.Body.Id.ToString());
             //Assert.Equal(TermListIdToUpdate, getdetailsTermList.Body.Id.ToString());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #9
0
        public void OCR()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "OCR");
                    //GetImageLists();
                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    api     = ContentModeratorAPI.OCR;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);

                    var ocr = results.OCR;
                    Assert.NotNull(ocr);
                    Assert.Equal(HttpStatusCode.OK, ocr.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyOCR(ocr.Body), TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void UpdateImageList()
 {
     try
     {
         using (MockContext context = MockContext.Start("ImageListManagement"))
         {
             //GetImageLists();
             //wait(2);
             api = ContentModeratorAPI.UPDATE_IMAGE_LIST;
             //imageListIdToUpdate = ((int)allImageLists[1].Id).ToString();
             HttpMockServer.Initialize("ImageListManagement", "UpdateImageList");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetResponse(client, api, imageListIdToUpdate);
             results = Constants.GetResponse(client, api, "157184");
             var updateImageLists = results.UpdateImageList;
             Assert.NotNull(updateImageLists);
             Assert.Equal(HttpStatusCode.OK, updateImageLists.Response.StatusCode);
             Assert.Equal("157184", updateImageLists.Body.Id.ToString());
             //Assert.Equal(imageListIdToUpdate, updateImageLists.Body.Id.ToString());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #11
0
        public void DeleteAllTerms()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    api = ContentModeratorAPI.DELETE_ALL_TERM;
                    HttpMockServer.Initialize("TextListManagement", "DeleteAllTerms");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId);
                    results = Constants.GetResponse(client, api, "67");

                    var deleteAllTermFromListId = results.DeleteTerms;
                    Assert.NotNull(deleteAllTermFromListId);
                    Assert.Equal(HttpStatusCode.NoContent, deleteAllTermFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #12
0
        public void Match()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "Match");

                    api     = ContentModeratorAPI.MATCH;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);
                    if (results != null)
                    {
                        var match = results.MatchImage;
                        Assert.NotNull(match);
                        Assert.Equal(HttpStatusCode.OK, match.Response.StatusCode);
                        Assert.True(Helpers.Utilities.VerifyMatchResponse(match.Body), TestBase.ErrorMessage);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #13
0
        public void GetTermLists()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    api = ContentModeratorAPI.GET_ALL_TERM_LIST;
                    HttpMockServer.Initialize("TextListManagement", "GetTermLists");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetResponse(client, api, string.Empty);
                    Assert.NotNull(results.GetAllTermLists);
                    Assert.Equal(HttpStatusCode.OK, results.GetAllTermLists.Response.StatusCode);

                    allTermLists = results.GetAllTermLists.Body.ToList();
                    if (allTermLists.Count > 0)
                    {
                        Assert.True(allTermLists.TrueForAll(x => !string.IsNullOrEmpty(((int)x.Id).ToString()) && !string.IsNullOrEmpty(x.Name) && x.Metadata != null), "Failed to get the result");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #14
0
        public void DetectLanguage()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextModerator"))
                {
                    HttpMockServer.Initialize("TextModerator", "DetectLanguage");
                    wait(2);
                    TermListId = "";
                    byte[]       byteArray = Encoding.UTF8.GetBytes("Ciao buongiorno stronzo");
                    MemoryStream stream    = new MemoryStream(byteArray);
                    api     = ContentModeratorAPI.DETECT_LANGUAGE;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetTextResponse(client, api, TermListId, stream);

                    var detectLanguage = results.DetectLanguage;
                    Assert.NotNull(detectLanguage);
                    Assert.Equal(HttpStatusCode.OK, detectLanguage.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyDetectLanguage(detectLanguage.Body), TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void DeleteImageList()
 {
     try
     {
         using (MockContext context = MockContext.Start("ImageListManagement"))
         {
             //GetImageLists();
             //wait(2);
             api = ContentModeratorAPI.DELETE_IMAGE_LIST;
             //imageListIdToDelete = ((int)allImageLists[0].Id).ToString();
             HttpMockServer.Initialize("ImageListManagement", "DeleteImageList");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetResponse(client, api, imageListIdToDelete);
             results = Constants.GetResponse(client, api, "157298");
             var deleteImageLists = results.DeleteImageLists;
             Assert.NotNull(deleteImageLists);
             Assert.Equal(HttpStatusCode.OK, deleteImageLists.Response.StatusCode);
             Assert.Equal("", deleteImageLists.Body);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #16
0
        public void DeleteTerm()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetAllTerms();
                    //wait(2);
                    //if (allTerms.Data.Terms.Count == 0)
                    //{
                    //    AddTerm();
                    //    GetAllTerms();
                    //}

                    api = ContentModeratorAPI.DELETE_TERM;

                    HttpMockServer.Initialize("TextListManagement", "DeleteTerm");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId, MIMETypes.JSON.GetDescription(), "eng", "test");
                    results = Constants.GetResponse(client, api, "67", MIMETypes.JSON.GetDescription(), "eng", "test");


                    var deleteTermFromListId = results.DeleteTerm;
                    Assert.NotNull(deleteTermFromListId);
                    Assert.Equal(HttpStatusCode.NoContent, deleteTermFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #17
0
        public void Evaluate()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "Evaluate");
                    //GetImageLists();

                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    api     = ContentModeratorAPI.EVALUATE;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);

                    var evaluate = results.Evaluate;
                    Assert.NotNull(evaluate);
                    Assert.Equal(HttpStatusCode.OK, evaluate.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #18
0
        public void CreateTermLists()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //int counter = 0;
                    //GetTermLists();
                    //wait(2);


                    //counter = allTermLists.Count;
                    //if (counter == 5)
                    //{
                    //    DeleteTermList();
                    //    counter--;
                    //    wait(2);
                    //}
                    // Create TermLIsts
                    api = ContentModeratorAPI.CREATE_TERM_LIST;
                    //while (counter < 5)
                    {
                        HttpMockServer.Initialize("TextListManagement", "CreateTermLists");
                        client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                        results = Constants.GetResponse(client, api, string.Empty);

                        var createTermList = results.CreateTermList;
                        Assert.NotNull(createTermList);
                        Assert.Equal(HttpStatusCode.OK, createTermList.Response.StatusCode);

                        //counter++;
                        wait(2);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #19
0
 public void ScreenText()
 {
     try
     {
         using (MockContext context = MockContext.Start("TextModerator"))
         {
             HttpMockServer.Initialize("TextModerator", "ScreenText");
             byte[]       byteArray = Encoding.UTF8.GetBytes("crap 764-87-9887");
             MemoryStream stream    = new MemoryStream(byteArray);
             api     = ContentModeratorAPI.SCREEN_TEXT;
             client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             results = Constants.GetTextResponse(client, api, "", stream);
             var screenText = results.ScreenText;
             Assert.NotNull(screenText);
             Assert.Equal(HttpStatusCode.OK, screenText.Response.StatusCode);
             Assert.True(Helpers.Utilities.VerifyScreenText(screenText.Body), TestBase.ErrorMessage);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void AddImage()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageListManagement"))
                {
                    //GetImageLists();
                    //wait(2);
                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    Constants.AddImage = new BodyModel("URL", "https://moderatorsampleimages.blob.core.windows.net/samples/sample.jpg");
                    api = ContentModeratorAPI.ADD_IMAGE;
                    HttpMockServer.Initialize("ImageListManagement", "AddImage");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, imageListId);
                    results = Constants.GetResponse(client, api, "157299");
                    if (results.InnerException != null)
                    {
                        DeleteImage();
                        api = ContentModeratorAPI.ADD_IMAGE;
                        HttpMockServer.Initialize("ImageListManagement", "AddImage");
                        client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                        results = Constants.GetResponse(client, api, null);
                    }
                    var addImgeToListId = results.AddImage;

                    Assert.NotNull(addImgeToListId);
                    Assert.Equal(HttpStatusCode.OK, addImgeToListId.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyAddImageResponse(addImgeToListId.Body), "Add Image Response verification failed." + TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #21
0
 public void DeleteTermList()
 {
     try
     {
         using (MockContext context = MockContext.Start("TextListManagement"))
         {
             //GetTermLists();
             //wait(2);// should wait as the plan permits 1 trans/sec
             api = ContentModeratorAPI.DELETE_TERM_LIST;
             //TermListIdToDelete = ((int)allTermLists[0].Id).ToString();
             HttpMockServer.Initialize("TextListManagement", "DeleteTermList");
             client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             results = Constants.GetResponse(client, api, "66");
             var deleteTermLists = results.DeleteTermLists;
             Assert.NotNull(deleteTermLists);
             Assert.Equal(HttpStatusCode.OK, deleteTermLists.Response.StatusCode);
             Assert.Equal("", deleteTermLists.Body);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public static bool VerifyBadRequestResponse(BadRequestResponse br, ContentModeratorAPI api)
        {
            string error = "";

            try
            {
                switch (api)
                {
                case ContentModeratorAPI.CREATE_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.UPDATE_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.GET_ALL_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.GET_DETAILS_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.DELETE_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.REFRESH_INDEX_IMAGE_LIST:
                    break;

                case ContentModeratorAPI.CREATE_TERM_LIST:
                    break;

                case ContentModeratorAPI.UPDATE_TERM_LIST:
                    break;

                case ContentModeratorAPI.GET_ALL_TERM_LIST:
                    break;

                case ContentModeratorAPI.GET_DETAILS_TERM_LIST:
                    break;

                case ContentModeratorAPI.DELETE_TERM_LIST:
                    break;

                case ContentModeratorAPI.REFRESH_INDEX_TERM_LIST:
                    break;

                case ContentModeratorAPI.ADD_IMAGE:
                    break;

                case ContentModeratorAPI.DELETE_IMAGE:
                    break;

                case ContentModeratorAPI.DELETE_ALL_IMAGE:
                    break;

                case ContentModeratorAPI.GET_ALL_IMAGES:
                    break;

                case ContentModeratorAPI.ADD_TERM:
                    break;

                case ContentModeratorAPI.DELETE_TERM:
                    break;

                case ContentModeratorAPI.DELETE_ALL_TERM:
                    break;

                case ContentModeratorAPI.GET_ALL_TERMS:
                    break;

                case ContentModeratorAPI.EVALUATE:
                case ContentModeratorAPI.FIND_FACES:
                case ContentModeratorAPI.MATCH:
                case ContentModeratorAPI.OCR:

                    if (!br.Message.Equals(ImageErrorMessages.IMAGE_SIZE_ERROR.GetDescription(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        error += $"Error Message mismatch. Actual<{br.Message}> Expected<{ImageErrorMessages.IMAGE_SIZE_ERROR.GetDescription()}>";
                    }
                    if (!br.Errors[0].Title.Equals(ImageErrorMessages.IMAGE_SIZE_ERROR.GetDescription(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        error += $"Errors object Title mismatch. Actual<{br.Errors[0].Title}> Expected<{ImageErrorMessages.IMAGE_SIZE_ERROR.GetDescription()}>";
                    }
                    if (br.TrackingId == null)
                    {
                        error = $"Tracking id is null";
                    }
                    break;

                case ContentModeratorAPI.SCREEN_TEXT:
                    break;

                case ContentModeratorAPI.DETECT_LANGUAGE:
                    break;

                default:
                    break;
                }

                TestBase.ErrorMessage = error;
                return(string.IsNullOrEmpty(error));
            }
            catch (Exception)
            {
                TestBase.ErrorMessage += $"Unable to verify BadRequestResponse. Response {JsonConvert.SerializeObject(br)}";
                return(false);
            }
        }