public void TestConstruction()
        {
            NoAuthAuthenticator authenticator = new NoAuthAuthenticator();

            Assert.IsNotNull(authenticator);
            Assert.IsTrue(authenticator.AuthenticationType == Authenticator.AuthTypeNoAuth);
        }
Esempio n. 2
0
        /// <summary>
        /// Instantiates an Authenticator that reflects the properties contains in the specified Map.
        /// </summary>
        /// <param name="props">A Map containing configuration properties</param>
        /// <returns>An Authenticator instance</returns>
        private static Authenticator CreateAuthenticator(Dictionary <string, string> props)
        {
            Authenticator authenticator = null;

            // If auth type was not specified, we'll use "iam" as the default.
            props.TryGetValue(Authenticator.PropNameAuthType, out string authType);
            if (string.IsNullOrEmpty(authType))
            {
                authType = Authenticator.AuthTypeIam;
            }

            if (authType.Equals(Authenticator.AuthTypeNoAuth, StringComparison.InvariantCultureIgnoreCase))
            {
                authenticator = new NoAuthAuthenticator(props);
            }
            else if (authType.Equals(Authenticator.AuthTypeBasic, StringComparison.InvariantCultureIgnoreCase))
            {
                authenticator = new BasicAuthenticator(props);
            }
            else if (authType.Equals(Authenticator.AuthTypeIam, StringComparison.InvariantCultureIgnoreCase))
            {
                authenticator = new IamAuthenticator(props);
            }
            else if (authType.Equals(Authenticator.AuthTypeCp4d, StringComparison.InvariantCultureIgnoreCase))
            {
                authenticator = new CloudPakForDataAuthenticator(props);
            }
            else if (authType.Equals(Authenticator.AuthTypeBearer, StringComparison.InvariantCultureIgnoreCase))
            {
                authenticator = new BearerTokenAuthenticator(props);
            }

            return(authenticator);
        }
Esempio n. 3
0
        public void Analysis()
        {
            IClient  client  = CreateClient();
            IRequest request = Substitute.For <IRequest>();

            client.GetAsync(Arg.Any <string>())
            .Returns(request);

            #region response
            var analyzeResponse = new AnalyzeResponse()
            {
                Images = new List <Image>()
                {
                    new Image()
                    {
                        Source = new ImageSource()
                        {
                            Type            = "type",
                            Filename        = "filename",
                            ArchiveFilename = "archiveFilename",
                            SourceUrl       = "sourceUrl",
                            ResolvedUrl     = "resolvedUrl"
                        },
                        Dimensions = new ImageDimensions()
                        {
                            Width  = 100,
                            Height = 200
                        },
                        Objects = new DetectedObjects()
                        {
                            Collections = new List <CollectionObjects>()
                            {
                                new CollectionObjects()
                                {
                                    CollectionId = "collectionId",
                                    Objects      = new List <ObjectDetail>()
                                    {
                                        new ObjectDetail()
                                        {
                                            _Object  = "object",
                                            Location = new ObjectDetailLocation()
                                            {
                                                Top    = 0,
                                                Left   = 1,
                                                Width  = 2,
                                                Height = 3
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var response = new DetailedResponse <AnalyzeResponse>();
            response.Result = analyzeResponse;
            #endregion

            request.WithArgument(Arg.Any <string>(), Arg.Any <string>())
            .Returns(request);
            request.WithBodyContent(new MultipartFormDataContent())
            .Returns(request);
            request.As <AnalyzeResponse>()
            .Returns(Task.FromResult(response));

            NoAuthAuthenticator      authenticator = new NoAuthAuthenticator();
            VisualRecognitionService service       = new VisualRecognitionService(client);
            service.Version = "versionDate";
            service.Analyze(
                collectionIds: new List <string> {
                "colletionIds"
            },
                features: new List <string> {
                "features"
            });

            Assert.IsTrue(response.Result.Images[0].Source.Type == "type");
            Assert.IsTrue(response.Result.Images[0].Source.Filename == "filename");
            Assert.IsTrue(response.Result.Images[0].Source.ArchiveFilename == "archiveFilename");
            Assert.IsTrue(response.Result.Images[0].Source.SourceUrl == "sourceUrl");
            Assert.IsTrue(response.Result.Images[0].Source.ResolvedUrl == "resolvedUrl");
            Assert.IsTrue(response.Result.Images[0].Dimensions.Width == 100);
            Assert.IsTrue(response.Result.Images[0].Dimensions.Height == 200);
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].CollectionId == "collectionId");
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].Objects[0]._Object == "object");
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].Objects[0].Location.Top == 0);
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].Objects[0].Location.Left == 1);
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].Objects[0].Location.Width == 2);
            Assert.IsTrue(response.Result.Images[0].Objects.Collections[0].Objects[0].Location.Height == 3);
        }