Example #1
0
        /// <inheritdoc />
        public async Task <ResolvedEndpoint> RetrieveAsync(ClientRegionLocale locale, string serviceType)
        {
            if (!await HasEntryAsync(locale, serviceType))
            {
                throw new InvalidOperationException($"Does not contain informations for Region: {locale} Type: {serviceType}");
            }

            NameEndpointResolutionStorageModel regionInfo = await Retrieve(locale);

            return(new ResolvedEndpoint(regionInfo.ServiceEndpoints[serviceType].EndpointAddress, regionInfo.ServiceEndpoints[serviceType].EndpointPort));
        }
Example #2
0
        /// <inheritdoc />
        public async Task <bool> HasEntryAsync(ClientRegionLocale locale, string serviceType)
        {
            if (!await HasDataForRegionAsync(locale))
            {
                return(false);
            }

            NameEndpointResolutionStorageModel regionInfo = await Retrieve(locale);

            if (regionInfo.ServiceEndpoints.ContainsKey(serviceType))
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        public static void Test_Can_JSON_Serialize_To_NonNull_Non_Whitespace(ClientRegionLocale value)
        {
            //arrange
            Dictionary <string, ResolvedEndpoint> endpoints = new Dictionary <string, ResolvedEndpoint>()
            {
                { "AuthenticationService", new ResolvedEndpoint("127.0.0.1", 5555) }
            };
            NameEndpointResolutionStorageModel model = new NameEndpointResolutionStorageModel(value, endpoints);

            //act
            string serializedModel = JsonConvert.SerializeObject(model);

            //assert
            Assert.NotNull(serializedModel);
            Assert.IsNotEmpty(serializedModel);
            Assert.True(serializedModel.Contains(endpoints.Values.First().EndpointAddress));
            Assert.True(serializedModel.Contains(nameof(model.ServiceEndpoints)));
            Assert.True(serializedModel.Contains(endpoints.Values.First().EndpointPort.ToString()));
            Assert.True(serializedModel.Contains(value.ToString()));
        }
Example #4
0
        public static void Test_Can_JSON_Serialize_Then_Deserialize_With_Preserved_Values(ClientRegionLocale value)
        {
            //arrange
            Dictionary <string, ResolvedEndpoint> endpoints = new Dictionary <string, ResolvedEndpoint>()
            {
                { "AuthenticationService", new ResolvedEndpoint("127.0.0.1", 5555) }
            };
            NameEndpointResolutionStorageModel model = new NameEndpointResolutionStorageModel(value, endpoints);

            //act
            NameEndpointResolutionStorageModel deserializedModel =
                JsonConvert.DeserializeObject <NameEndpointResolutionStorageModel>(JsonConvert.SerializeObject(model));

            //assert
            Assert.NotNull(deserializedModel);
            Assert.NotNull(deserializedModel.ServiceEndpoints);
            Assert.IsNotEmpty(deserializedModel.ServiceEndpoints);
            Assert.True(Enum.IsDefined(typeof(ClientRegionLocale), deserializedModel.Region));
            Assert.NotNull(deserializedModel.ServiceEndpoints.Keys.First());
            Assert.AreEqual(endpoints.First().Key, deserializedModel.ServiceEndpoints.First().Key);
            Assert.AreEqual(endpoints.First().Value.EndpointAddress, deserializedModel.ServiceEndpoints.First().Value.EndpointAddress);
        }
        public NamedEndpointDbContext(DbContextOptions options, [FromServices] IRegionNamedEndpointStoreRepository regionEndpointStore)
            : base(options)
        {
            if (regionEndpointStore == null)
            {
                throw new ArgumentNullException(nameof(regionEndpointStore));
            }

            //TODO: We should probably use a database, a real one, at some point.
            foreach (ClientRegionLocale region in Enum.GetValues(typeof(ClientRegionLocale)).Cast <ClientRegionLocale>())
            {
                if (regionEndpointStore.HasRegionStore(region).Result)
                {
                    NameEndpointResolutionStorageModel model = regionEndpointStore.Retrieve(region).Result;
                    foreach (var kvp in model.ServiceEndpoints)
                    {
                        Endpoints.Add(new NamedResolvedEndpointEntryModel(model.Region, kvp.Key, kvp.Value.EndpointAddress, kvp.Value.EndpointPort));
                    }
                }
            }

            this.SaveChanges();
        }