Exemplo n.º 1
0
        public void CloneHydroNetworkWithData()
        {
            var network = HydroNetworkHelper.GetSnakeHydroNetwork(1);

            var publicProperties = ReflectionTestHelper.GetPublicListProperties(network);

            foreach (var prop in publicProperties)
            {
                try
                {
                    var value = prop.GetValue(network, null);
                    if (value is IList)
                    {
                        var genericType = TypeUtils.GetFirstGenericTypeParameter(value.GetType());

                        var concreteType =
                            genericType.Assembly.GetTypes().Where(
                                t => genericType.IsAssignableFrom(t) &&
                                !t.IsInterface &&
                                !t.IsAbstract).FirstOrDefault();

                        var instance = Activator.CreateInstance(concreteType);
                        (value as IList).Add(instance);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine(String.Format("Unable to set property: {0}", prop));
                }
            }

            var clone = (HydroNetwork)network.Clone();

            TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone);
        }
Exemplo n.º 2
0
        public void CloneHydroNetworkWithProxyDefinitions()
        {
            var network          = HydroNetworkHelper.GetSnakeHydroNetwork(1);
            var sharedDefinition = new CrossSectionDefinitionYZ();

            network.SharedCrossSectionDefinitions.Add(sharedDefinition);
            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(network.Channels.First(),
                                                                 new CrossSectionDefinitionProxy(sharedDefinition),
                                                                 10.0d);

            var clone = (HydroNetwork)network.Clone();

            TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone);
        }