예제 #1
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()));
        }
예제 #2
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();
        }