Esempio n. 1
0
        public void TestVersion1Dot1Resolution()
        {
            // Versions can be v1.1, which we need to support
            const string serviceName     = ServiceNameConstants.PROJECT_SERVICE;
            const string serviceEndpoint = "http://localhost:5020";
            const string serviceRoute    = "/my-special-version";

            const string expectedUrl = "http://localhost:5020/api/v1.1/my-special-version";

            const ServiceResultType serviceType = ServiceResultType.Configuration;

            var mockServiceResolver = new MockServiceResolver(serviceType, 0);

            // Register our service
            mockServiceResolver.ServiceMap[serviceName] = serviceEndpoint;

            serviceCollection.AddSingleton <IServiceResolver>(mockServiceResolver);
            var resolver = serviceCollection.BuildServiceProvider().GetService <IServiceResolution>();

            Assert.NotNull(resolver);

            var url = resolver.ResolveLocalServiceEndpoint(ApiService.Project, ApiType.Public, ApiVersion.V1_1, serviceRoute).Result;

            Assert.Equal(expectedUrl, url);
        }
 public ServiceResult(ServiceResultType resultType, Exception exception, string message, ServiceResultCode code)
 {
     ResultType = resultType;
     Exception  = exception;
     Message    = message;
     Code       = code;
 }
 public ServiceResult(ServiceResultType resultType, Exception exception, string message, int code)
 {
     ResultType = resultType;
     Exception = exception;
     Message = message;
     Code = code;
 }
Esempio n. 4
0
        public void TestSingleResult()
        {
            // Test we can get an endpoint from a single resolver correctly when the service exists, and when it doesn't
            const string serviceName     = "test-service-please-ignore";
            const string serviceEndpoint = "http://localhost:5000";

            const ServiceResultType serviceType = ServiceResultType.Configuration;

            var mockServiceResolver = new MockServiceResolver(serviceType, 0);

            // Register our service
            mockServiceResolver.ServiceMap[serviceName] = serviceEndpoint;

            serviceCollection.AddSingleton <IServiceResolver>(mockServiceResolver);
            var resolver = serviceCollection.BuildServiceProvider().GetService <IServiceResolution>();

            Assert.NotNull(resolver);
            Assert.True(resolver.Resolvers.Count == 1);

            var positiveResult = resolver.ResolveService(serviceName).Result;
            var negativeResult = resolver.ResolveService(serviceName + serviceName).Result;

            Assert.NotNull(negativeResult);
            Assert.Equal(ServiceResultType.Unknown, negativeResult.Type);

            Assert.NotNull(positiveResult);
            Assert.Equal(serviceType, positiveResult.Type);
            Assert.Equal(serviceEndpoint, positiveResult.Endpoint);
        }
 public ServiceResult(ServiceResultType resultType, Exception exception, string message, ServiceResultCode code, object data)
 {
     ResultType = resultType;
     Exception  = exception;
     Message    = message;
     Code       = code;
     Data       = data;
 }
        public void Display_ServiceResultIsValid_InnerResultIsEmpty_MessageIsWrittenToUserInterface(ServiceResultType resultType)
        {
            // Arrange
            var userInterface = new Mock<IUserInterface>();
            string resultMessage = "Yada Yada";
            IServiceResult serviceResult = new ServiceResult(resultType, resultMessage);

            // Act
            this.serviceResultVisualizer.Display(userInterface.Object, serviceResult);

            // Assert
            userInterface.Verify(u => u.WriteLine(It.Is<string>(message => message.EndsWith(resultMessage))), Times.Once());
        }
 public ServiceQueryResult(sones.GraphQL.Result.QueryResult myQueryResult)
 {
     this.Duration = myQueryResult.Duration;
     if (myQueryResult.Error != null)
         this.Error = myQueryResult.Error.Message;
     else
         this.Error = null;
     this.NameOfQueryLanguage = myQueryResult.NameOfQuerylanguage;
     this.NumberOfAffectedVertices = myQueryResult.NumberOfAffectedVertices;
     this.Query = myQueryResult.Query;
     if (myQueryResult.TypeOfResult == ResultType.Successful)
         this.TypeOfResult = ServiceResultType.Successful;
     else if (myQueryResult.TypeOfResult == ResultType.Failed)
         this.TypeOfResult = ServiceResultType.Failed;
     this.Vertices = myQueryResult.Vertices.Select(x => new ServiceVertexView(x)).ToList();
 }
Esempio n. 8
0
        public void TestPriority()
        {
            // Ensure that the higher priority (lower number) service resolver is used before the lower priority
            // But if the higher priority resolver doesn't know about the service, the lower ones will be used if they do
            const string            serviceOneName = "test-service-with-priority";
            const string            higherPriorityServiceOneEndpoint = "http://localhost:1234";
            const string            lowerPriorityServiceOneEndpoint  = "http://127.0.0.1:9999";
            const int               highPriority = 1;
            const int               lowPriority  = 2;
            const ServiceResultType higherPriorityServiceType = ServiceResultType.InternalKubernetes;
            const ServiceResultType lowerPriorityServiceType  = ServiceResultType.Configuration;

            const string serviceTwoName     = "test-service-low-priority-only";
            const string serviceTwoEndpoint = "http://192.168.1.1:64000";

            var highPriorityResolver = new MockServiceResolver(higherPriorityServiceType, highPriority);
            var lowPriorityResolver  = new MockServiceResolver(lowerPriorityServiceType, lowPriority);

            // service one will exist in both, but service two just in the lower priority
            highPriorityResolver.ServiceMap[serviceOneName] = higherPriorityServiceOneEndpoint;
            lowPriorityResolver.ServiceMap[serviceOneName]  = lowerPriorityServiceOneEndpoint;

            lowPriorityResolver.ServiceMap[serviceTwoName] = serviceTwoEndpoint;

            serviceCollection.AddSingleton <IServiceResolver>(highPriorityResolver);
            serviceCollection.AddSingleton <IServiceResolver>(lowPriorityResolver);
            var resolver = serviceCollection.BuildServiceProvider().GetService <IServiceResolution>();

            Assert.NotNull(resolver);
            Assert.True(resolver.Resolvers.Count == 2);

            // Check the first service comes from the higher priority
            var serviceOne = resolver.ResolveService(serviceOneName).Result;

            Assert.NotNull(serviceOne);
            Assert.Equal(higherPriorityServiceType, serviceOne.Type);
            Assert.Equal(higherPriorityServiceOneEndpoint, serviceOne.Endpoint);

            var serviceTwo = resolver.ResolveService(serviceTwoName).Result;

            Assert.NotNull(serviceTwo);
            Assert.Equal(lowerPriorityServiceType, serviceTwo.Type);
            Assert.Equal(serviceTwoEndpoint, serviceTwo.Endpoint);
        }
Esempio n. 9
0
 /// <summary>
 ///     初始化一个 定义返回消息、日志消息与附加数据的业务操作结果信息类 的新实例
 /// </summary>
 /// <param name="resultType">业务操作结果类型</param>
 /// <param name="message">业务返回消息</param>
 /// <param name="logMessage">业务日志记录消息</param>
 /// <param name="result">业务返回数据</param>
 public ServiceResult(ServiceResultType resultType, string message, string logMessage, T result)
     : this(resultType, message, logMessage)
 {
     Result = result;
 }
 public ServiceResult(ServiceResultType resultType, int code)
 {
     ResultType = resultType;
     Code = code;
 }
Esempio n. 11
0
 /// <summary>
 ///     初始化一个 定义返回消息的业务操作结果信息类 的新实例
 /// </summary>
 /// <param name="resultType">业务操作结果类型</param>
 /// <param name="message">业务返回消息</param>
 public ServiceResult(ServiceResultType resultType, string message)
     : this(resultType)
 {
     this.message = message;
 }
Esempio n. 12
0
 /// <summary>
 ///     初始化一个 定义返回消息与日志消息的业务操作结果信息类 的新实例
 /// </summary>
 /// <param name="resultType">业务操作结果类型</param>
 /// <param name="message">业务返回消息</param>
 /// <param name="logMessage">业务日志记录消息</param>
 public ServiceResult(ServiceResultType resultType, string message, string logMessage)
     : this(resultType, message)
 {
     LogMessage = logMessage;
 }
 public ServiceResult(ServiceResultType resultType, string message, ServiceResultCode code)
 {
     ResultType = resultType;
     Message    = message;
     Code       = code;
 }
Esempio n. 14
0
 /// <summary>
 ///     初始化一个 业务操作结果信息类 的新实例
 /// </summary>
 /// <param name="resultType">业务操作结果类型</param>
 public ServiceResult(ServiceResultType resultType)
 {
     ResultType     = resultType;
     Success        = ResultType == ServiceResultType.Success;
     HttpStatusCode = System.Net.HttpStatusCode.OK;
 }
Esempio n. 15
0
 public ServiceResult(ServiceResultType resultType)
 {
     ResultType = resultType;
 }
 public ServiceResult(ServiceResultType resultType, Exception exception, int code)
 {
     ResultType = resultType;
     Exception = exception;
     Code = code;
 }
 public ServiceResultList(ServiceResultType resultType)
     : base(resultType)
 {
     ResultList = null;
 }
Esempio n. 18
0
 public ServiceResult(ServiceResultType type = ServiceResultType.Success, string message = "")
 {
     ResultType = type;
     Message    = message;
 }
 public ServiceResult(ServiceResultType resultType, ServiceResultCode code)
 {
     ResultType = resultType;
     Code       = code;
 }
Esempio n. 20
0
 public ServiceResultObject(ServiceResultType resultType, string message)
     : base(resultType, message)
 {
     ResultObject = default(T);
 }
Esempio n. 21
0
 public ServiceResultObject(ServiceResultType resultType)
     : base(resultType)
 {
     ResultObject = default(T);
 }
 public ServiceResult(ServiceResultType resultType, string message, int code)
 {
     ResultType = resultType;
     Message = message;
     Code = code;
 }
 public ServiceResult(ServiceResultType resultType)
 {
     ResultType = resultType;
 }
Esempio n. 24
0
 public ServiceResult(ServiceResultType status, string message, params object[] messageArguments)
 {
     this.status = status;
     this.message = message != null ? string.Format(message, messageArguments) : null;
 }
 public ServiceResult(ServiceResultType resultType, string message)
 {
     ResultType   = resultType;
     ErrorMessage = message;
 }
 public ServiceResultList(ServiceResultType resultType, IEnumerable <T> resultList)
 {
     ResultList = resultList;
     TotalCount = resultList.Count();
     ResultType = resultType;
 }
 public ServiceResult(ServiceResultType resultType, Exception exception, ServiceResultCode code)
 {
     ResultType = resultType;
     Exception  = exception;
     Code       = code;
 }
 public ServiceResultList(ServiceResultType resultType, string message)
     : base(resultType, message)
 {
     ResultList = null;
 }
Esempio n. 29
0
 public MockServiceResolver(ServiceResultType resultType, int priority)
 {
     ServiceMap  = new Dictionary <string, string>();
     ServiceType = resultType;
     Priority    = priority;
 }