コード例 #1
0
        private UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter GetDefaultUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter returnItem = new UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            returnItem.UsaStateDefinitions.Add(this.GetNorthCarolina());
            returnItem.UsaStateDefinitions.Add(this.GetVirginia());
            return(returnItem);
        }
        public void DemonstrateIUsaStateDefinitionConfigurationRetriever()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter wrapper = this.usaStateDefinitionConfigurationRetriever.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            if (null != wrapper)
            {
                this.ShowUsaStateObjects("From.DemonstrateIUsaStateDefinitionConfigurationRetriever", wrapper.UsaStateDefinitions);
            }
        }
コード例 #3
0
        public void UsaStateDefinitionsIsNullByUniqueIdentifierTest()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter configurationWrapper = new UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            configurationWrapper.UsaStateDefinitions = null;

            Mock <IUsaStateDefinitionConfigurationRetriever> mockRetriever = this.GetDefaultIUsaStateDefinitionConfigurationRetrieverMock();

            mockRetriever.Setup(x => x.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter()).Returns(configurationWrapper);
            IUsaStateDefinitionFinder testItem  = new UsaStateDefinitionFinder(mockRetriever.Object);
            UsaStateObject            foundItem = testItem.FindUsaStateObjectByUniqueId(0);

            Assert.IsNull(foundItem);
        }
        public void DemonstrateIUsaStateDefinitionFinder()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter wrapper = this.usaStateDefinitionConfigurationRetriever.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            if (null != wrapper)
            {
                UsaStateObject foundItem = null;

                foundItem = this.usaStateDefinitionFinder.FindUsaStateObject(wrapper, "Virginia");
                this.ShowUsaStateObject("With.Wrapper", foundItem);

                foundItem = this.usaStateDefinitionFinder.FindUsaStateObject("Alaska");
                this.ShowUsaStateObject("Without.Wrapper", foundItem);
            }
        }
コード例 #5
0
        public void DuplicateByFullNameTest()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter configurationWrapper = new UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            configurationWrapper.UsaStateDefinitions.Add(this.GetNorthCarolina());
            UsaStateObject testTriggerItem = this.GetVirginia();

            testTriggerItem.UsaStateFullName = NorthCarolinaUsaStateFullName;
            configurationWrapper.UsaStateDefinitions.Add(testTriggerItem);
            configurationWrapper.UsaStateDefinitions.Add(testTriggerItem);

            Mock <IUsaStateDefinitionConfigurationRetriever> mockRetriever = this.GetDefaultIUsaStateDefinitionConfigurationRetrieverMock();

            mockRetriever.Setup(x => x.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter()).Returns(configurationWrapper);
            IUsaStateDefinitionFinder testItem = new UsaStateDefinitionFinder(mockRetriever.Object);

            testItem.FindUsaStateObject(NorthCarolinaUsaStateFullName);
        }
コード例 #6
0
        public UsaStateObject FindUsaStateObjectByUniqueId(UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter settings, int id)
        {
            UsaStateObject returnItem = null;

            if (null != settings && null != settings.UsaStateDefinitions)
            {
                ICollection <UsaStateObject> matchingFarmItems;
                matchingFarmItems = settings.UsaStateDefinitions.Where(ele => id == ele.UsaStateDefinitionUniqueIdentifier).ToList();

                if (matchingFarmItems.Count > 1)
                {
                    string errorDetails = this.BuildErrorDetails(matchingFarmItems);
                    throw new IndexOutOfRangeException(string.Format(ErrorMessageMoreThanOneMatch, errorDetails));
                }

                returnItem = matchingFarmItems.FirstOrDefault();
            }

            return(returnItem);
        }
コード例 #7
0
        public UsaStateObject FindUsaStateObject(UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter settings, string usaStateFullName)
        {
            UsaStateObject returnItem = null;

            if (null != settings && null != settings.UsaStateDefinitions)
            {
                ICollection <UsaStateObject> matchingFarmItems;
                matchingFarmItems = settings.UsaStateDefinitions.Where(ele => usaStateFullName.Equals(ele.UsaStateFullName, StringComparison.OrdinalIgnoreCase)).ToList();

                if (matchingFarmItems.Count > 1)
                {
                    string errorDetails = this.BuildErrorDetails(matchingFarmItems);
                    throw new IndexOutOfRangeException(string.Format(ErrorMessageMoreThanOneMatch, errorDetails));
                }

                returnItem = matchingFarmItems.FirstOrDefault();
            }

            return(returnItem);
        }
コード例 #8
0
        public UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter()
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter returnItem = this.configuration.Get <UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter>();

            if (returnItem != null)
            {
                IEnumerable <int> duplicatesIdentifiers = returnItem.UsaStateDefinitions.GroupBy(i => i.UsaStateDefinitionUniqueIdentifier)
                                                          .Where(g => g.Count() > 1)
                                                          .Select(g => g.Key);

                if (duplicatesIdentifiers.Count() > 1)
                {
                    throw new ArgumentOutOfRangeException("Duplicate UsaStateDefinitionUniqueIdentifier values.", Convert.ToString(duplicatesIdentifiers.First()));
                }

                return(returnItem);
            }

            return(null);
        }
コード例 #9
0
        public UsaStateObject FindUsaStateObjectByUniqueId(int id)
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter settings = this.usaStateDefinitionConfigurationRetriever.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            return(this.FindUsaStateObjectByUniqueId(settings, id));
        }
コード例 #10
0
        public UsaStateObject FindUsaStateObject(string usaStateFullName)
        {
            UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter settings = this.usaStateDefinitionConfigurationRetriever.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

            return(this.FindUsaStateObject(settings, usaStateFullName));
        }
コード例 #11
0
        public static int Main(string[] args)
        {
            ILog lgr = LogManager.GetLogger(typeof(Program));

            try
            {
                /* look at the Project-Properties/Debug(Tab) for this environment variable */
                string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
                Console.WriteLine(string.Format("ASPNETCORE_ENVIRONMENT='{0}'", environmentName));
                Console.WriteLine(string.Empty);

                IConfigurationBuilder builder = new ConfigurationBuilder()
                                                .SetBasePath(Directory.GetCurrentDirectory())
                                                .AddJsonFile("appsettings.json")
                                                .AddJsonFile($"appsettings.{environmentName}.json", true, true)
                                                .AddEnvironmentVariables();

                IConfigurationRoot configuration = builder.Build();

                string defaultConnectionStringValue = configuration.GetConnectionString("DefaultConnection");
                Console.WriteLine(string.Format("defaultConnectionStringValue='{0}'", defaultConnectionStringValue));
                Console.WriteLine(string.Empty);

                ////setup our DI
                IServiceCollection servColl = new ServiceCollection()
                                              .AddSingleton(lgr)
                                              .AddLogging()
                                              .AddSingleton <IBoardGameManager, BoardGameManager>()
                                              .AddSingleton <IUsaStateDefinitionConfigurationRetriever, UsaStateDefinitionConfigurationRetriever>()
                                              .AddSingleton <IUsaStateDefinitionFinder, UsaStateDefinitionFinder>()
                                              .AddSingleton(configuration);

                ServiceProvider servProv = servColl.BuildServiceProvider();

                CustomConfiguration.Domain.FosterExample.AppConfig my7AppConfig = configuration.Get <CustomConfiguration.Domain.FosterExample.AppConfig>();
                ////UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter myUsaStateDefinitionConfigurationSectionName = configuration.Get<UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter>();

                IUsaStateDefinitionConfigurationRetriever customConfigRetriever = servProv.GetService <IUsaStateDefinitionConfigurationRetriever>();

                UsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter myUsaStateDefinitionConfigurationSectionName = customConfigRetriever.GetUsaStateConfigurationWrapperThisObjectNameDoesNotReallyMatter();

                if (null != myUsaStateDefinitionConfigurationSectionName)
                {
                    ShowUsaStateObjects("configuration.Get", myUsaStateDefinitionConfigurationSectionName.UsaStateDefinitions);
                }

                Console.WriteLine(string.Empty);

                IUsaStateDefinitionFinder finder = servProv.GetService <IUsaStateDefinitionFinder>();
                UsaStateObject            foundUsaStateObject = finder.FindUsaStateObject("Virginia");
                ShowUsaStateObject("FindUsaStateObject:(ByVirginia)", foundUsaStateObject);
                Console.WriteLine(string.Empty);

                IBoardGameManager boardGameManager = servProv.GetService <IBoardGameManager>();
                boardGameManager.DemonstrateIUsaStateDefinitionConfigurationRetriever();
                Console.WriteLine(string.Empty);

                boardGameManager.DemonstrateIUsaStateDefinitionFinder();
                Console.WriteLine(string.Empty);
            }
            catch (Exception ex)
            {
                string flattenMsg = GenerateFullFlatMessage(ex, true);
                Console.WriteLine(flattenMsg);
            }

            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();

            return(0);
        }