Example #1
0
        public UnitTestHelpers()
        {
            _configPath = DirectoryLocator.GetTargetConfigurationPath();
            var msSqlPath = Path.Combine(DirectoryLocator.GetTargetProjectPath(typeof(Program)), @"..\..\MsSqlDb");

            // For the unit tests we
            _tenantContext = new TenantContext
            {
                DbContext =
                {
                    Catalog       = "LeagueIntegration",
                    Schema        = "dbo",
                    ConnectionKey = "dummy"
                }
            };
            _tenantContext.DbContext.ConnectionString =
                $"Server=(LocalDB)\\MSSQLLocalDB;AttachDbFilename={msSqlPath}\\LeagueIntegrationTest.mdf;Database={_tenantContext.DbContext.Catalog};Integrated Security=true";

            // Make sure we can connect to the database
            using (var connection = new Microsoft.Data.SqlClient.SqlConnection(_tenantContext.DbContext.ConnectionString))
                try
                {
                    connection.Open();
                }
                finally
                {
                    connection.Close();
                }

            InitializeLlBlGenPro();
        }
Example #2
0
        /// <summary>
        /// Funkcija koja daje određeni model kamere
        /// </summary>
        /// <param name="category">Kategorija kamere</param>
        /// <returns>Objekt IFotoaparat-a</returns>
        private IFotoaparat GetCamera(string category)
        {
            string directoryLocation = DirectoryLocator.GetDirectory("Cameras", Directory.GetCurrentDirectory(), 0, 3);

            if (string.Equals(directoryLocation, "ERROR"))
            {
                Console.WriteLine("Ne može se pronaći direktorij s kamerama!");
            }

            string[]           files      = Directory.GetFiles(directoryLocation);
            List <IFotoaparat> cameraList = new List <IFotoaparat>();

            foreach (string file in files)
            {
                XmlTextReader reader = new XmlTextReader(file);
                while (reader.Read())
                {
                    if (XmlNodeType.Element == reader.NodeType)
                    {
                        reader.MoveToAttribute("type");
                        string elementType = reader.Value;
                        if (string.Equals(elementType, category))
                        {
                            CameraFactory cameraFactory;
                            if (string.Equals(category, "DSLR"))
                            {
                                cameraFactory = new CreatorDSLR();
                            }
                            else if (string.Equals(category, "MILC"))
                            {
                                cameraFactory = new CreatorMILC();
                            }
                            else
                            {
                                cameraFactory = new CreatorCompact();
                            }

                            IFotoaparat newCamera = cameraFactory.Create();
                            for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                            {
                                reader.MoveToAttribute(attInd);
                                newCamera.SetValue(reader.Name, reader.Value);
                            }
                            cameraList.Add(newCamera);
                        }
                    }
                }
            }

            Randomizer rnd         = Randomizer.GetInstance();
            int        cameraIndex = rnd.GetNumber(0, cameraList.Count);

            return(cameraList[cameraIndex]);
        }
Example #3
0
        public async Task Create_Should_Work_With_PhysicalFileProvider()
        {
            var localizedTemplateContentReaderFactory = new LocalizedTemplateContentReaderFactory(
                new TestPhysicalVirtualFileProvider(
                    new PhysicalFileProvider(Path.Combine(DirectoryLocator.GetTargetProjectPath(typeof(ServiceSetup)), "Templates"))));

            var reader = await localizedTemplateContentReaderFactory.CreateAsync(_templateDefinitionManager.Get(Templates.WelcomeEmail) !);

            Assert.AreEqual(reader.GetContent("en"), "Welcome {{model.name}} to Axuno.TextTemplating!");
            Assert.AreEqual(reader.GetContent("de"), "Willkommen, {{model.name}}, bei Axuno.TextTemplating!");
        }
Example #4
0
        /// <summary>
        /// Učitava module iz mape Moduli
        /// </summary>
        /// <returns>True ako su moduli učitani, False ako nisu</returns>
        public bool LoadModules()
        {
            string directoryLocation = DirectoryLocator.GetDirectory("Modules", Directory.GetCurrentDirectory(), 0, 3);

            if (string.Equals(directoryLocation, "ERROR"))
            {
                Console.WriteLine("Ne može se pronaći direktorij s modulima!");
                return(false);
            }

            listOfModules = FotoCompetitionModuleLoader.GetModules(directoryLocation);
            Console.WriteLine(listOfModules.Count.ToString() + " modules have been loaded");
            return(true);
        }
Example #5
0
        /// <summary>
        /// Funkcija koja generira teme za natječaj
        /// </summary>
        /// <param name="numberOfThemes">Broj tema koji treba generirati</param>
        /// <returns>Lista slučajno odabranih tema</returns>
        private List <Theme> GenerateThemes(int numberOfThemes)
        {
            #region Pronalazak direktorija s temama
            string directoryLocation = DirectoryLocator.GetDirectory("Themes", Directory.GetCurrentDirectory(), 0, 3);
            if (string.Equals("ERROR", directoryLocation))
            {
                Console.WriteLine("Niti jedna tema nije učitana!");
                return(null);
            }
            #endregion

            #region Učitavanje kandidata za teme
            List <Theme>  listOfCandidates = new List <Theme>();
            List <string> listOfThemeNames = new List <string>();
            string[]      files            = Directory.GetFiles(directoryLocation);

            foreach (string file in files)
            {
                Console.WriteLine("Učitavam teme iz " + file);
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    if (listOfThemeNames.Contains(line) || string.Equals(line, ""))
                    {
                        continue;
                    }

                    Theme newTheme = new Theme(line);
                    listOfCandidates.Add(newTheme);
                    listOfThemeNames.Add(line);
                }
            }
            #endregion

            #region Odabir tema za natječaj
            List <Theme> resultList = new List <Theme>();
            Randomizer   rnd        = Randomizer.GetInstance();
            while (resultList.Count < numberOfThemes)
            {
                int   themeIndex  = rnd.GetNumber(0, listOfCandidates.Count);
                Theme randomTheme = listOfCandidates[themeIndex];
                resultList.Add(randomTheme);
                listOfCandidates.Remove(randomTheme);
            }
            #endregion

            return(resultList);
        }
        public UnitTestHelpers()
        {
            _configPath = DirectoryLocator.GetTargetConfigurationPath();
            var orgSiteList   = SiteList.DeserializeFromFile(Path.Combine(_configPath, "SiteList.Development.config"));
            var dbContextList = DbContextList.DeserializeFromFile(Path.Combine(_configPath, "DbContextList.Development.config"));

            foreach (var dbContext in dbContextList)
            {
                dbContext.Catalog = "LeagueIntegration";
                var msSqlPath = Path.Combine(DirectoryLocator.GetTargetProjectPath(), @"..\..\MsSqlDb");
                dbContext.ConnectionString = string.Format("Server={0};Database={1};Integrated Security=true", $"(LocalDB)\\MSSQLLocalDB;AttachDbFilename={msSqlPath}\\LeagueIntegrationTest.mdf", dbContext.Catalog);
            }
            var dbContextResolver = new DbContextResolver(dbContextList);

            InitializeLlBlGenPro();

            _siteContext = new SiteContext(dbContextResolver.Resolve("dbo").OrganizationKey, new OrganizationContextResolver(dbContextResolver, new NullLogger <OrganizationContextResolver>(), _configPath), orgSiteList);
        }
        private void InitializeLlBlGenPro()
        {
            RuntimeConfiguration.ConfigureDQE <SD.LLBLGen.Pro.DQE.SqlServer.SQLServerDQEConfiguration>(c => c
                                                                                                       .SetTraceLevel(System.Diagnostics.TraceLevel.Verbose)
                                                                                                       .AddDbProviderFactory(typeof(System.Data.SqlClient.SqlClientFactory)));
            //RuntimeConfiguration.SetDependencyInjectionInfo(new[] { typeof(TournamentManager.Validators.UserEntityValidator).Assembly }, new[] { "TournamentManager.Validators" });

            RuntimeConfiguration.Tracing.SetTraceLevel("ORMPersistenceExecution", System.Diagnostics.TraceLevel.Verbose);
            RuntimeConfiguration.Tracing.SetTraceLevel("ORMPlainSQLQueryExecution", System.Diagnostics.TraceLevel.Verbose);

            LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(Path.Combine(DirectoryLocator.GetTargetConfigurationPath(), "NLog.Internal.config"));
            TournamentManager.AppLogging.LoggerFactory = ServiceProvider.GetRequiredService <ILoggerFactory>();
        }
Example #8
0
        /// <summary>
        /// Funkcija koja generira natjecatelje,e zajedno sn jihovim imenima i prezimenima
        /// </summary>
        /// <param name="numberOfCompetitors">Broj natjecatelja</param>
        /// <returns>Lista natjecatelja</returns>
        private List <Competitor> GenerateCompetitors(int numberOfCompetitors)
        {
            #region Pronalazaz direktorija s imenima i prezimenima
            string namesLocation    = DirectoryLocator.GetDirectory("Person Names", Directory.GetCurrentDirectory(), 0, 3);
            string surnamesLocation = DirectoryLocator.GetDirectory("Person Surnames", Directory.GetCurrentDirectory(), 0, 3);
            if (string.Equals("ERROR", namesLocation) || string.Equals("ERROR", surnamesLocation))
            {
                return(null);
            }
            #endregion

            #region Učitavanje listi imena i perzimena
            List <string> listOfNames = new List <string>();
            string[]      files1      = Directory.GetFiles(namesLocation);
            foreach (string file in files1)
            {
                Console.WriteLine("Učitavam imena iz " + file);
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string name = line;
                    if (listOfNames.Contains(name) || string.Equals(name, ""))
                    {
                        continue;
                    }
                    listOfNames.Add(name);
                }
            }

            List <string> listOfSurnames = new List <string>();
            string[]      files2         = Directory.GetFiles(surnamesLocation);
            foreach (string file in files2)
            {
                Console.WriteLine("Učitavam prezimena iz " + file);
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string surname = line;
                    if (listOfSurnames.Contains(surname) || string.Equals(surname, ""))
                    {
                        continue;
                    }
                    listOfSurnames.Add(surname);
                }
            }
            #endregion

            #region Generiranje natjecatelja
            List <Competitor> competitors           = new List <Competitor>();
            List <string>     listOfCompetitorNames = new List <string>();
            Randomizer        rnd = Randomizer.GetInstance();
            while (competitors.Count < numberOfCompetitors)
            {
                int    nameIndex = rnd.GetNumber(0, listOfNames.Count);
                string name      = listOfNames[nameIndex];

                int    surnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                string surname      = listOfSurnames[surnameIndex];

                string competitorName = name + " " + surname;
                if (rnd.GetNumber(0, 7) == 4)
                {
                    //Dodajemo i drugo prezime
                    int    secondSurnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                    string secondSurname      = listOfSurnames[secondSurnameIndex];
                    if (!string.Equals(surname, secondSurname))
                    {
                        competitorName = competitorName + "-" + secondSurname;
                    }
                }

                if (!listOfCompetitorNames.Contains(competitorName))
                {
                    listOfCompetitorNames.Add(competitorName);
                    Competitor competitor = new Competitor(competitorName);
                    competitors.Add(competitor);
                }
            }
            #endregion

            return(competitors);
        }
Example #9
0
        /// <summary>
        /// Generira članove žiria
        /// </summary>
        /// <returns>Lista članova žiria</returns>
        List <Jury> GenerateJury()
        {
            ArgumentHandler arguments  = ArgumentHandler.GetInstance();
            int             juryNumber = (int)arguments.GetArgument("JuryNumber");

            #region Pronalazak direktorija s imenima i prezimenima
            string namesLocation    = DirectoryLocator.GetDirectory("Person Names", Directory.GetCurrentDirectory(), 0, 3);
            string surnamesLocation = DirectoryLocator.GetDirectory("Person Surnames", Directory.GetCurrentDirectory(), 0, 3);
            #endregion

            #region Učitavanje listi imena i perzimena
            List <string> listOfNames = new List <string>();
            string[]      files1      = Directory.GetFiles(namesLocation);
            foreach (string file in files1)
            {
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string name = line;
                    if (listOfNames.Contains(name) || string.Equals(name, ""))
                    {
                        continue;
                    }
                    listOfNames.Add(name);
                }
            }

            List <string> listOfSurnames = new List <string>();
            string[]      files2         = Directory.GetFiles(surnamesLocation);
            foreach (string file in files2)
            {
                Console.WriteLine("Učitavam prezimena iz " + file);
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string surname = line;
                    if (listOfSurnames.Contains(surname) || string.Equals(surname, ""))
                    {
                        continue;
                    }
                    listOfSurnames.Add(surname);
                }
            }
            #endregion

            #region Generiranje članova žiria
            List <Jury>   jury            = new List <Jury>();
            List <string> listOfJuryNames = new List <string>();
            Randomizer    rnd             = Randomizer.GetInstance();

            while (jury.Count < juryNumber)
            {
                int    nameIndex = rnd.GetNumber(0, listOfNames.Count);
                string name      = listOfNames[nameIndex];

                int    surnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                string surname      = listOfSurnames[surnameIndex];

                string juryMemberName = name + " " + surname;
                if (rnd.GetNumber(0, 7) == 4)
                {
                    int    secondSurnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                    string secondSurname      = listOfSurnames[secondSurnameIndex];
                    if (!string.Equals(surname, secondSurname))
                    {
                        juryMemberName = juryMemberName + "-" + secondSurname;
                    }
                }

                if (!listOfJuryNames.Contains(juryMemberName))
                {
                    listOfJuryNames.Add(juryMemberName);
                    Jury juryMember = new Jury(juryMemberName);
                    jury.Add(juryMember);
                }
            }
            #endregion

            #region Ispis članova žiria
            Console.WriteLine("\nČlanovi žiria:");
            foreach (Jury juryMember in jury)
            {
                Console.WriteLine(juryMember.Name);
            }
            #endregion
            return(jury);
        }
Example #10
0
        /// <summary>
        /// Funkcija koja proglašava pobjednike i stvara datoteku rezultata
        /// </summary>
        /// <param name="competition">Singleton natječaja iz kojeg se vuku podaci</param>
        void VictoryProclamation(Competition competition)
        {
            ArgumentHandler arguments         = ArgumentHandler.GetInstance();
            string          resultFileName    = (string)arguments.GetArgument("ResultFile");
            string          directoryLocation = DirectoryLocator.GetDirectory("Results", Directory.GetCurrentDirectory(), 0, 3);
            string          resultFile        = directoryLocation + "\\" + resultFileName;

            List <string>       listOfCategories    = competition.DownloadCategories();
            List <Theme>        listOfThemes        = competition.DownloadThemess();
            List <Registration> listOfRegistrations = competition.DownloadRegistrations();
            List <Competitor>   listOfCompetitors   = competition.DownloadCompetitors();

            using (StreamWriter sw = new StreamWriter(resultFile))
            {
                #region Pobjednici po temama unutar kategorija
                sw.WriteLine("Pobjednici po temama unutar kategorija".ToUpper());
                foreach (string category in listOfCategories)
                {
                    sw.WriteLine(Indent(0) + "KATEGORIJA " + category + ":");
                    foreach (Theme theme in listOfThemes)
                    {
                        sw.WriteLine(Indent(1) + "TEMA " + theme.Name + ":");
                        List <Registration>        disqualifiedRegistrations = new List <Registration>();
                        Dictionary <string, float> victoryCandidatesPerTheme = new Dictionary <string, float>();
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (!string.Equals(registration.Category, category) || !string.Equals(registration.Theme.Name, theme.Name))
                            {
                                continue;
                            }

                            if (registration.IsDisqualified())
                            {
                                disqualifiedRegistrations.Add(registration);
                                continue;
                            }

                            sw.Write(Indent(2) + "NATJECATELJ " + registration.Competitor.Name);
                            sw.Write(Indent(1) + registration.ID);
                            foreach (KeyValuePair <string, int> score in registration.GetAllScores())
                            {
                                sw.Write(Indent(1) + score.Key + ": " + score.Value.ToString());
                            }
                            sw.WriteLine(Indent(1) + "UKUPNO: " + registration.FinalScore.ToString());

                            victoryCandidatesPerTheme.Add(registration.Competitor.Name, registration.FinalScore);
                        }
                        Dictionary <string, float> victorsPerTheme = VictoryHandler.GetVictors(victoryCandidatesPerTheme);
                        Console.WriteLine("\nPobjednici u temi " + theme.Name + ", kategorija " + category + ": ");
                        foreach (KeyValuePair <string, float> score in victorsPerTheme)
                        {
                            Console.WriteLine(score.Key + ": " + score.Value.ToString());
                        }

                        sw.WriteLine(Indent(3) + "DISKVALIFICIRANE PRIJAVE");
                        foreach (Registration disqualifiedRegistration in disqualifiedRegistrations)
                        {
                            sw.Write(Indent(4) + disqualifiedRegistration.Competitor.Name);
                            sw.WriteLine(Indent(1) + disqualifiedRegistration.ID);
                        }
                    }
                }
                #endregion

                #region Pobjednici po kategorijama
                sw.WriteLine();
                sw.WriteLine("Pobjednici po kategorijama".ToUpper());
                foreach (string category in listOfCategories)
                {
                    sw.WriteLine(Indent(0) + "KATEGORIJA " + category + ":");
                    Dictionary <string, float> victoryCandidatesPerCategory = new Dictionary <string, float>();
                    foreach (Competitor competitor in listOfCompetitors)
                    {
                        sw.WriteLine();
                        sw.WriteLine(Indent(1) + "NATJECATELJ " + competitor.Name + ":");
                        float totalScore = 0;
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (registration.IsDisqualified() || !string.Equals(registration.Category, category) || !string.Equals(registration.Competitor.Name, competitor.Name))
                            {
                                continue;
                            }

                            sw.Write(Indent(2) + "TEMA " + registration.Theme.Name);
                            sw.Write(Indent(2) + "PRIJAVA " + registration.ID);
                            sw.WriteLine(Indent(2) + "UKUPNI BODOVI " + registration.GetFinalScore().ToString());
                            totalScore += registration.GetFinalScore();
                        }
                        sw.WriteLine(Indent(1) + "UKUPNI BODOVI SVIH PRIJAVA: " + totalScore.ToString());
                        victoryCandidatesPerCategory.Add(competitor.Name, totalScore);
                    }

                    Dictionary <string, float> victorsPerCategory = VictoryHandler.GetVictors(victoryCandidatesPerCategory);
                    Console.WriteLine("\nPobjednici u kategoriji " + category + ": ");
                    foreach (KeyValuePair <string, float> score in victorsPerCategory)
                    {
                        Console.WriteLine(score.Key + ": " + score.Value.ToString());
                    }
                }
                #endregion

                #region Ukupni pobjednik
                sw.WriteLine();
                sw.WriteLine("Ukupno".ToUpper());
                Dictionary <string, float> victoryCandidates = new Dictionary <string, float>();
                foreach (Competitor competitor in listOfCompetitors)
                {
                    sw.WriteLine();
                    sw.WriteLine(Indent(0) + "NATJECATELJ " + competitor.Name + ":");
                    float globalScore = 0;
                    foreach (string category in listOfCategories)
                    {
                        float totalScore = 0;
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (!registration.IsDisqualified() && string.Equals(registration.Category, category) && string.Equals(registration.Competitor.Name, competitor.Name))
                            {
                                totalScore += registration.GetFinalScore();
                            }
                        }

                        sw.Write(Indent(2) + category);
                        sw.WriteLine(Indent(2) + "UKUPNI BODOVI: " + totalScore.ToString());
                        globalScore += totalScore;
                    }
                    sw.WriteLine(Indent(1) + "UKUPNI BODOVI NATJECATELJA: " + globalScore.ToString());
                    victoryCandidates.Add(competitor.Name, globalScore);
                }

                Dictionary <string, float> victors = VictoryHandler.GetVictors(victoryCandidates);
                Console.WriteLine("\nUkupni pobjednici: ");
                foreach (KeyValuePair <string, float> score in victors)
                {
                    Console.WriteLine(score.Key + ": " + score.Value.ToString());
                }
                #endregion
            }
        }