Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var db = new DataBaseMicrosoft(SolutionConfiguration.DatabaseType, SolutionConfiguration.DatabaseArguments);
            var groups = db.GetElements<Group>();

            foreach (var group in groups)
            {
                db.FillElement(group);
            }

            var maxLengthPeople = groups.Max(group => group.Peoples.Max(people => people.Name.Length));
            var maxLengthGroup = groups.Max(group => group.Name.Length);
            var tab = "\t\t";

            var report = new StringBuilder();

            report.Append($"{"Тестируемый".ModifyToTotalLength(maxLengthPeople)}{tab}{"Группа".ModifyToTotalLength(maxLengthGroup)}{tab}Пароль\n\n");

            foreach (var group in groups)
            {
                foreach (var people in group.Peoples)
                {
                    report.Append($"{people.Name.ModifyToTotalLength(maxLengthPeople)}{tab}{group.Name.ModifyToTotalLength(maxLengthGroup)}{tab}{people.Password}\n");
                }

                report.Append("\n");
            }

            File.WriteAllText("Passwords.txt", report.ToString());

            System.Diagnostics.Process.Start("Passwords.txt");
        }
Exemplo n.º 2
0
        public void ShouldInsertPeoples()
        {
            // Given
            var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
            var peoples = new[]
            {
                new People("Акакий", "Программист"),
                new People("Генка", "Плотник")
            };
            var expected = new[]
            {
                new People("Иванов Иван", "Плотник"),
                new People("Князь Владимир", "Программист"),
                new People("Петров Петр", "Плотник"),
                new People("Клинт Бартон", "Программист"),
                new People("Акакий", "Программист"),
                new People("Генка", "Плотник")
            };

            // When
            foreach (var people in peoples)
            {
                db.ExecuteCommand(Parameters.Insert, people);
            }
            var actual = db.GetElements<People>();
            TestHelper.DeleteTemp();

            // Then
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsInstanceOf<People>(actual[0]);
            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void ShouldInsertTests()
        {
            // Given
            var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
            var test = new Test("Пробный Тест", 70);
            var questions = new[]
            {
                new Question("Вопрос 1"),
                new Question("Вопрос 2")
            };
            var expected = new[]
            {
                new Test("Первый тест", 100),
                new Test("Пробный Тест", 70)
            };

            // When
            test.SetQuestions(questions);
            test.SetComponent(new Component("", 1));
            questions[0].SetAssessments(new Assessments());
            questions[1].SetAssessments(new Assessments());
            var status = db.ExecuteCommand(Parameters.Insert, test);
            var actual = db.GetElements<Test>();
            db.FillElement(actual[1]);
            TestHelper.DeleteTemp();

            // Then
            Assert.AreEqual(0, status.ExitCode);
            Assert.IsNull(status.ErrorMessage);
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsInstanceOf<Test>(actual[0]);
            CollectionAssert.AreEqual(expected, actual);
            CollectionAssert.AreEqual(questions, actual[1].Questions);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var commands = new[]
            {
                "cleanDatabase",
                "createTestData"
            };

            if (args.Length == 0)
            {
                Console.WriteLine($"Using {AppDomain.CurrentDomain.FriendlyName} {{{commands.ConcatArrayItems('|')}}}");

                return;
            }

            var db = new DataBaseMicrosoft(SolutionConfiguration.DatabaseType, SolutionConfiguration.DatabaseArguments);

            var @switch = new Dictionary<string, Action>
            {
                {
                    commands[0], () =>
                    {
                        db.CleanDataBase();
                    }
                },
                {
                    commands[1], () =>
                    {
                        var types = AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(s => s.GetTypes())
                            .Where(p => typeof(ICommandInsert).IsAssignableFrom(p))
                            .ToArray()
                            .Sort();

                        foreach (var type in types)
                        {
                            type.GetMethod(nameof(ICommandInsert.Execute)).Invoke(Activator.CreateInstance(type), new object[] { db });
                        }
                    }
                }
            };

            Action action;

            if (@switch.TryGetValue(args[0], out action))
            {
                action();
            }
            else
            {
                Console.WriteLine("Incorrect command");
            }
        }
Exemplo n.º 5
0
        public void ShouldGetTestList()
        {
            // Given
            var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
            var expected = new Test("Первый тест", 100);

            // When
            var actual = db.GetElements<Test>().Last();
            TestHelper.DeleteTemp();

            // Then
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void Execute(Dictionary<string, List<string[]>> dictionary)
        {
            const string nameTest = nameof(GroupTest);

            dictionary[nameTest].Add(new[] { "Group count", "People count" });

            var goupCounts = new[]
            {
                5,
                10,
                50
            };
            var peopleCounts = new[]
            {
                5,
                50,
                100
            };

            foreach (var goupCount in goupCounts)
            {
                foreach (var peopleCount in peopleCounts)
                {
                    var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
                    var watch = new Stopwatch();
                    var position = Guid.NewGuid().ToString();
                    var groups = GenerateGroupsWithPeoples(goupCount, peopleCount, position);

                    db.CleanDataBase();
                    db.InsertPosition(position);

                    watch.Start();

                    foreach (var group in groups)
                    {
                        db.ExecuteCommand(Parameters.Insert, group);
                    }

                    watch.Stop();

                    dictionary[nameTest].Add(new[] { $"{goupCount}", $"{peopleCount}", $"{watch.Elapsed.TotalMilliseconds}" });
                }
            }
        }
Exemplo n.º 7
0
        public void ShouldGetPeopleList()
        {
            // Given
            var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
            var expected = new[]
            {
                new People("Иванов Иван", "Плотник"),
                new People("Князь Владимир", "Программист"),
                new People("Петров Петр", "Плотник"),
                new People("Клинт Бартон", "Программист")
            };

            // When
            var actual = db.GetElements<People>();
            TestHelper.DeleteTemp();

            // Then
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.IsInstanceOf<People>(actual[0]);
            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void ShouldInsertComponent()
        {
            // Given
            var db = new DataBaseMicrosoft(DataBasesTypes.MicrosoftAccess, TestHelper.CreateTempFile());
            var generalComponents = new[]
            {
                new Component("ОбщийКомпонент№1"),
                new Component("ОбщийКомпонент№2"),
                new Component("ОбщийКомпонент№3")
            };
            var component = new Component("Компонент1Уровня")
            {
                Components =
                {
                    new Component("Компонент2Уровня№1")
                    {
                        Components =
                        {
                            new Component("Компонент3Уровня№1")
                            {
                                Components =
                                {
                                    generalComponents[0],
                                    generalComponents[1],
                                    generalComponents[2]
                                }
                            },
                            new Component("Компонент3Уровня№2")
                            {
                                Components =
                                {
                                    generalComponents[0],
                                    generalComponents[1],
                                    generalComponents[2]
                                }
                            }
                        }
                    }
                }
            };

            // When
            db.ExecuteCommand(Parameters.Insert, component);
            var actual = db.GetElements<Component>().Last();
            db.FillElement(actual);
            TestHelper.DeleteTemp();

            // Then

            // Top Level
            Assert.AreEqual(component, actual);

            // 2 Level
            Assert.AreEqual(component.Components[0], actual.Components[0]);

            // 3 Level
            Assert.AreEqual(component.Components[0].Components[0], actual.Components[0].Components[0]);
            Assert.AreEqual(component.Components[0].Components[1], actual.Components[0].Components[1]);

            // General
            Assert.AreEqual(component.Components[0].Components[0].Components[0], actual.Components[0].Components[0].Components[0]);
            Assert.AreEqual(component.Components[0].Components[0].Components[1], actual.Components[0].Components[0].Components[1]);
            Assert.AreEqual(component.Components[0].Components[0].Components[2], actual.Components[0].Components[0].Components[2]);

            Assert.AreEqual(component.Components[0].Components[1].Components[0], actual.Components[0].Components[1].Components[0]);
            Assert.AreEqual(component.Components[0].Components[1].Components[1], actual.Components[0].Components[1].Components[1]);
            Assert.AreEqual(component.Components[0].Components[1].Components[2], actual.Components[0].Components[1].Components[2]);
        }