Beispiel #1
0
        private UsaStateObject GetVirginia()
        {
            UsaStateObject returnItem = new UsaStateObject();

            returnItem.UsaStateDefinitionUniqueIdentifier = VirginiaUsaStateDefinitionUniqueIdentifier;
            returnItem.UsaStateAbbreviation = VirginiaUsaStateAbbreviation;
            returnItem.UsaStateFullName     = VirginiaUsaStateFullName;

            return(returnItem);
        }
Beispiel #2
0
        private UsaStateObject GetNorthCarolina()
        {
            UsaStateObject returnItem = new UsaStateObject();

            returnItem.UsaStateDefinitionUniqueIdentifier = NorthCarolinaUsaStateDefinitionUniqueIdentifier;
            returnItem.UsaStateAbbreviation = NorthCarolinaUsaStateAbbreviation;
            returnItem.UsaStateFullName     = NorthCarolinaUsaStateFullName;

            return(returnItem);
        }
Beispiel #3
0
        public void FindByUniqueIdentifier()
        {
            IUsaStateDefinitionFinder testItem  = new UsaStateDefinitionFinder(this.GetDefaultIUsaStateDefinitionConfigurationRetrieverMock().Object);
            UsaStateObject            foundItem = testItem.FindUsaStateObjectByUniqueId(VirginiaUsaStateDefinitionUniqueIdentifier);

            Assert.IsNotNull(foundItem);
            Assert.AreEqual(VirginiaUsaStateDefinitionUniqueIdentifier, foundItem.UsaStateDefinitionUniqueIdentifier);
            Assert.AreEqual(VirginiaUsaStateAbbreviation, foundItem.UsaStateAbbreviation);
            Assert.AreEqual(VirginiaUsaStateFullName, foundItem.UsaStateFullName);
        }
 private void ShowUsaStateObject(string label, UsaStateObject item)
 {
     if (null != item)
     {
         Console.WriteLine(string.Format("Label='{0}', UsaStateAbbreviation='{1}', UsaStateFullName='{2}', IsContenential='{3}', CountyLabelName(Enum)='{4}'", label, item.UsaStateAbbreviation, item.UsaStateFullName, item.IsContenential, item.CountyLabelName));
         if (null != item.UsaCounties)
         {
             foreach (UsaCountyObject currentCounty in item.UsaCounties)
             {
                 Console.WriteLine(string.Format("....UsaCountyValue='{0}'", currentCounty.UsaCountyValue));
             }
         }
     }
 }
Beispiel #5
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);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
        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);
        }