Example #1
0
        public static void MultyblockRange()
        {
            //Simple test
            var multyblockRange = new MultyblockRange(0, 3,
                                                      new[]
            {
                new BlockRange(BlockSize / 2, BlockSize / 2, 0),
                new BlockRange(0, BlockSize, BlockSize),
                new BlockRange(0, BlockSize / 2, 2 * BlockSize)
            });

            Assert.IsTrue(
                TestStructure.MultyblockRange(new Range(BlockSize / 2, 2 * BlockSize))
                .Equals(multyblockRange));

            //Exceptions

            //Left overlap
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, Range, MultyblockRange>
                    (TestStructure.MultyblockRange, new Range(-1, 2)));
            //Rigth overlap
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, Range, MultyblockRange>
                    (TestStructure.MultyblockRange, new Range(CountOfBlocks * BlockSize - 1, 2)));
            //Wrong count
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, Range, MultyblockRange>
                    (TestStructure.MultyblockRange, new Range(BlockSize, -2)));
        }
        public IHttpActionResult AddTest(int UserId, int TestStructureId)
        {
            Test test = new Test();

            test.SetProperties(UserId: UserId, TestStructureId: TestStructureId);
            db.Tests.Add(test);
            db.SaveChanges();
            TestStructure   testStructure = db.TestStructures.Find(TestStructureId);
            Random          rng           = new Random();
            List <Question> questions     = db.Questions.Where(q => q.Technology == testStructure.Technology &&
                                                               q.Level == testStructure.Level &&
                                                               q.QuestionFile.IsCurrent == true).ToList();

            if (questions.Count == 0)
            {
                db.Tests.Remove(test);
                db.SaveChanges();
                return(Ok(new List <TestQuestion>()));
            }
            for (int i = 0; i < testStructure.NumberOfQuestions; i++)
            {
                TestQuestion testQuestion = new TestQuestion();
                testQuestion.SetProperties(TestId: test.Id, QuestionId: questions[rng.Next(0, questions.Count)].Id);
                db.TestQuestions.Add(testQuestion);
                db.SaveChanges();
            }
            test.StartTime = System.DateTime.Now;
            test.EndTime   = test.StartTime.Value.AddMinutes(testStructure.MaxMinutes);
            db.SaveChanges();
            return(CreatedAtRoute("DefaultApi", new { id = test.Id }, db.TestQuestions.Where(tq => tq.TestId == test.Id).ToList()));
        }
Example #3
0
        public void GenerateCalculations_WithValidData_SetsCorrectCalculations()
        {
            // Setup
            var calculationGroup = new CalculationGroup();

            var structure1 = new TestStructure("testStructure1", "structure1");
            var structure2 = new TestStructure("testStructure2", "structure2");

            // Call
            StructureCalculationConfigurationHelper.GenerateCalculations <TestStructure, TestStructuresInput>(calculationGroup, new[]
            {
                structure1,
                structure2
            });

            // Assert
            Assert.AreEqual(2, calculationGroup.Children.Count);

            var calculation1 = (StructuresCalculationScenario <TestStructuresInput>)calculationGroup.Children.First();

            Assert.AreEqual("structure1", calculation1.Name);
            Assert.AreEqual(structure1, calculation1.InputParameters.Structure);

            var calculation2 = (StructuresCalculationScenario <TestStructuresInput>)calculationGroup.Children.Last();

            Assert.AreEqual("structure2", calculation2.Name);
            Assert.AreEqual(structure2, calculation2.InputParameters.Structure);
        }
Example #4
0
        public void CanSetSynonymInstanceSuffix()
        {
            var testObject  = new object();
            var testObject2 = new object();

            object internalStorage = null;
            var    testSuffix      = Substitute.For <ISetSuffix>();

            //Mock Set
            testSuffix.When(s => s.Set(Arg.Any <object>())).Do(info => internalStorage = info.Arg <object>());
            //Mock Get
            testSuffix.Get().ReturnsForAnyArgs(info => internalStorage);

            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();
            var suffixName2   = Guid.NewGuid().ToString();

            testStructure.TestAddInstanceSuffix(new[] { suffixName, suffixName2 }, testSuffix);

            Assert.IsNull(testStructure.GetSuffix(suffixName));
            Assert.IsNull(testStructure.GetSuffix(suffixName2));

            testStructure.SetSuffix(suffixName, testObject);
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName2));

            testStructure.SetSuffix(suffixName2, testObject2);
            Assert.AreSame(testObject2, testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject2, testStructure.GetSuffix(suffixName2));
        }
        public void TryReadStructure_WithStructureToFindStructuresContainsStructure_ReturnsTrue()
        {
            // Setup
            const string structureId = "someId";
            const string calculationName = "name";

            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            var expectedProfile = new TestStructure(structureId);

            // Call
            bool valid = importer.PublicTryReadStructure(structureId,
                                                         calculationName,
                                                         new[]
                                                         {
                                                             new TestStructure("otherIdA"),
                                                             expectedProfile,
                                                             new TestStructure("otherIdB")
                                                         },
                                                         out StructureBase structure);

            // Assert
            Assert.IsTrue(valid);
            Assert.AreSame(expectedProfile, structure);
        }
 public IHttpActionResult UpdateTestStructure(int AdminId, TestStructure testStructure)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         TestStructure oldData = db.TestStructures /*.AsNoTracking()*/.Where(ts => ts.Id == testStructure.Id).FirstOrDefault();
         if (oldData == null || !oldData.IsCurrent)
         {
             return(NotFound());
         }
         oldData.SetProperties(AdminId: AdminId, IsCurrent: false /*, SetNumberOfQuestions: false*/);
         db.SaveChanges();
         testStructure.Id = 0;
         if (testStructure.SetProperties(AdminId: AdminId))
         {
             db.TestStructures.Add(testStructure);
             try
             {
                 db.SaveChanges();
             }
             catch (DbUpdateException)
             {
                 if (TestStructureExists(testStructure.Id))
                 {
                     return(Conflict());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(Ok(testStructure));
         }
         return(BadRequest());
     }
 }
Example #7
0
        public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem()
        {
            // Setup
            var simpleStructure = new TestStructure();
            var properties      = new ObjectPropertiesWithStructure(simpleStructure, new[]
            {
                simpleStructure
            });
            var propertyBag       = new DynamicPropertyBag(properties);
            var editor            = new StructureEditor <TestStructure>();
            var someValue         = new object();
            var serviceProvider   = mockRepository.Stub <IServiceProvider>();
            var service           = mockRepository.Stub <IWindowsFormsEditorService>();
            var descriptorContext = mockRepository.Stub <ITypeDescriptorContext>();

            serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service);
            descriptorContext.Stub(c => c.Instance).Return(propertyBag);
            mockRepository.ReplayAll();

            // Call
            object result = editor.EditValue(descriptorContext, serviceProvider, someValue);

            // Assert
            Assert.AreSame(simpleStructure, result);
            mockRepository.VerifyAll();
        }
 public IHttpActionResult AddTestStructure(int AdminId, TestStructure testStructure)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         if (TestStructureExists(testStructure.Technology, testStructure.Level))
         {
             return(Ok(new TestStructure()));
         }
         if (testStructure.SetProperties(AdminId: AdminId))
         {
             db.TestStructures.Add(testStructure);
             try
             {
                 db.SaveChanges();
             }
             catch (DbUpdateException)
             {
                 if (TestStructureExists(testStructure.Id))
                 {
                     return(Conflict());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(CreatedAtRoute("DefaultApi", new { id = testStructure.Id }, testStructure));
         }
         return(BadRequest());
     }
 }
Example #9
0
        public void TestPtrStructureConvert()
        {
            IntPtr pStructure = IntPtr.Zero;

            try
            {
                TestStructure structure = new TestStructure
                {
                    Uint64Val = 1,
                    StringVal = "hello",
                    IntPtrVal = (IntPtr)0x123455,
                    Uint32Val = 18,
                    BoolVal   = false,
                    EnumVal   = TestEnum.One
                };
                pStructure = MarshalUtils.StructureToPtr(structure);
                Assert.AreNotEqual(pStructure, IntPtr.Zero);
                TestStructure convertedStructure = MarshalUtils.PtrToStructure <TestStructure>(pStructure);
                Assert.NotNull(convertedStructure);
                AssertStructureEquals(structure, convertedStructure);
            }
            finally
            {
                MarshalUtils.SafeFreeHGlobal(pStructure);
            }
        }
Example #10
0
        public void IsStructureIntersectionWithReferenceLineInSection_EmptySegmentCollection_ThrowsInvalidOperationException()
        {
            // Setup
            var structure     = new TestStructure(new Point2D(0.0, 0.0));
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(10.0, 0.0)
            });

            var calculation = new TestStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = structure
                }
            };

            // Call
            void Call() => calculation.IsStructureIntersectionWithReferenceLineInSection(Enumerable.Empty <Segment2D>());

            // Assert
            Assert.Throws <InvalidOperationException>(Call);
        }
Example #11
0
        public void IsStructureIntersectionWithReferenceLineInSection_StructureDoesNotIntersectReferenceLine_ReturnsFalse()
        {
            // Setup
            var structure     = new TestStructure(new Point2D(0.0, 0.0));
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(new[]
            {
                new Point2D(10.0, 0.0),
                new Point2D(20.0, 0.0)
            });

            var calculation = new TestStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = structure
                }
            };

            IEnumerable <Segment2D> lineSegments = Math2D.ConvertPointsToLineSegments(referenceLine.Points);

            // Call
            bool intersects = calculation.IsStructureIntersectionWithReferenceLineInSection(lineSegments);

            // Assert
            Assert.IsFalse(intersects);
        }
Example #12
0
        public void CreateStructuresFeatures_WithStructures_ReturnsCollectionWithFeatures()
        {
            // Setup
            var structure1 = new TestStructure("id", "A", new Point2D(1.1, 2.2));
            var structure2 = new TestStructure("id", "B", new Point2D(3.3, 4.4));

            TestStructure[] structures =
            {
                structure1,
                structure2
            };

            // Call
            IEnumerable <MapFeature> features = RiskeerMapDataFeaturesFactory.CreateStructuresFeatures(structures);

            // Assert
            Assert.AreEqual(2, features.Count());
            Point2D locationOne = features.First().MapGeometries.Single().PointCollections.First().Single();
            Point2D locationTwo = features.ElementAt(1).MapGeometries.Single().PointCollections.First().Single();

            Assert.AreEqual(structure1.Location, locationOne);
            Assert.AreEqual(structure2.Location, locationTwo);

            const int expectedNumberOfMetaDataOptions = 1;

            Assert.AreEqual(expectedNumberOfMetaDataOptions, features.First().MetaData.Count);
            Assert.AreEqual(expectedNumberOfMetaDataOptions, features.ElementAt(1).MetaData.Count);
            Assert.AreEqual(structure1.Name, features.First().MetaData["Naam"]);
            Assert.AreEqual(structure2.Name, features.ElementAt(1).MetaData["Naam"]);
        }
        public void Structure_Always_InputChangedAndObservablesNotified()
        {
            var structure = new TestStructure();

            SetPropertyAndVerifyNotificationsAndOutput(
                properties => properties.Structure = structure);
        }
Example #14
0
        public static void BlockInfo()
        {
            //Simple tests

            //Start element
            Assert.IsTrue(
                TestStructure.BlockInfo(0).Equals(new BlockInfo(0, 0, BlockSize)));
            //Simple element
            Assert.IsTrue(
                TestStructure.BlockInfo(BlockSize / 2).Equals(new BlockInfo(0, 0, BlockSize)));
            //First element of some block
            Assert.IsTrue(
                TestStructure.BlockInfo(BlockSize).Equals(new BlockInfo(1, BlockSize, BlockSize)));
            //Last element
            Assert.IsTrue(
                TestStructure.BlockInfo(CountOfBlocks * BlockSize - 1).Equals(
                    new BlockInfo(CountOfBlocks - 1, (CountOfBlocks - 1) * BlockSize, BlockSize)));

            //With ranges

            //Start element in range
            Assert.IsTrue(TestStructure.BlockInfo(0, new Range(0, 1))
                          .Equals(new BlockInfo(0, 0, BlockSize)));
            //Last element in range
            Assert.IsTrue(
                TestStructure.BlockInfo(CountOfBlocks * BlockSize - 1, new Range(CountOfBlocks - 1, 1))
                .Equals(new BlockInfo(CountOfBlocks - 1, (CountOfBlocks - 1) * BlockSize, BlockSize)));

            //Exceptions without ranges

            //-1 element
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, BlockInfo>(
                    TestStructure.BlockInfo, -1));
            //Element after last
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, BlockInfo>(
                    TestStructure.BlockInfo, CountOfBlocks * BlockSize));

            //Exceptions with ranges

            //Element at left towards range
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, Range, BlockInfo>(
                    TestStructure.BlockInfo, 0, new Range(1, 1)));
            //Element at right towards range
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, Range, BlockInfo>(
                    TestStructure.BlockInfo, 2, new Range(1, 1)));
            //Wrong left-side range with right location of element
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, Range, BlockInfo>(
                    TestStructure.BlockInfo, 0, new Range(-1, 2)));
            //Wrong right-side range with right location of element
            Assert.IsTrue(
                ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, Range, BlockInfo>(
                    TestStructure.BlockInfo, CountOfBlocks * BlockSize - 1, new Range(CountOfBlocks - 1, 2)));
        }
Example #15
0
 private void AssertStructureEquals(TestStructure s1, TestStructure s2)
 {
     Assert.AreEqual(s1.Uint64Val, s2.Uint64Val);
     Assert.AreEqual(s1.StringVal, s2.StringVal);
     Assert.AreEqual(s1.IntPtrVal, s2.IntPtrVal);
     Assert.AreEqual(s1.Uint32Val, s2.Uint32Val);
     Assert.AreEqual(s1.BoolVal, s2.BoolVal);
     Assert.AreEqual(s1.EnumVal, s2.EnumVal);
 }
Example #16
0
        public void CanAddGlobalSuffix()
        {
            var testObject      = new object();
            var testSuffix      = Substitute.For <ISuffix>();
            var testStuffixName = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            TestStructure.TestAddGlobal <TestStructure>(testStuffixName, testSuffix);
            Assert.AreEqual(testObject, new TestStructure().GetSuffix(testStuffixName));
        }
        public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers()
        {
            // Setup
            const int numberOfChangedProperties = 6;
            var       observer = mockRepository.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties);

            mockRepository.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructureInput>
            {
                InputParameters =
                {
                    Structure = new TestStructure()
                }
            };
            var inputContext = new SimpleInputContext(calculation.InputParameters,
                                                      calculation,
                                                      failureMechanism,
                                                      assessmentSection);

            var properties = new SimpleStructuresInputProperties(
                inputContext,
                new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(),
                new ObservablePropertyChangeHandler(inputContext.Calculation, calculation.InputParameters));

            inputContext.Attach(observer);

            var                       random = new Random(100);
            double                    newStructureNormalOrientation           = random.NextDouble();
            const bool                newShouldIllustrationPointsBeCalculated = true;
            var                       newStructure                           = new TestStructure();
            ForeshoreProfile          newForeshoreProfile                    = new TestForeshoreProfile();
            HydraulicBoundaryLocation newHydraulicBoundaryLocation           = CreateHydraulicBoundaryLocation();
            var                       newSelectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newHydraulicBoundaryLocation, null);

            // Call
            properties.Structure = newStructure;
            properties.StructureNormalOrientation             = (RoundedDouble)newStructureNormalOrientation;
            properties.FailureProbabilityStructureWithErosion = 1e-2;
            properties.SelectedHydraulicBoundaryLocation      = newSelectableHydraulicBoundaryLocation;
            properties.ForeshoreProfile = newForeshoreProfile;
            properties.ShouldIllustrationPointsBeCalculated = newShouldIllustrationPointsBeCalculated;

            // Assert
            Assert.AreSame(newStructure, properties.Structure);
            Assert.AreEqual(newStructureNormalOrientation, properties.StructureNormalOrientation, properties.StructureNormalOrientation.GetAccuracy());
            Assert.AreEqual(0.01, properties.FailureProbabilityStructureWithErosion);
            Assert.AreSame(newHydraulicBoundaryLocation, properties.SelectedHydraulicBoundaryLocation.HydraulicBoundaryLocation);
            Assert.AreSame(newForeshoreProfile, properties.ForeshoreProfile);
            Assert.AreEqual(newShouldIllustrationPointsBeCalculated, properties.ShouldIllustrationPointsBeCalculated);
            mockRepository.VerifyAll();
        }
Example #18
0
        public void GlobalSuffixesAreInFactGlobal()
        {
            var suffixName = Guid.NewGuid().ToString();
            var testObject = Substitute.For <ISuffixResult>();
            var testSuffix = Substitute.For <ISuffix>();

            testSuffix.Get().Returns(testObject);

            TestStructure.TestAddGlobal <TestStructure>(suffixName, testSuffix);
            Assert.AreEqual(testObject, new TestStructure().GetSuffix(suffixName));
            Assert.AreEqual(testObject, new TestStructure().GetSuffix(suffixName));
        }
Example #19
0
        public void CanAddInstanceSuffix()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
        }
Example #20
0
        public void Equals_SameInstance_ReturnTrue()
        {
            // Setup
            var comparer  = new StructureIdEqualityComparer();
            var structure = new TestStructure();

            // Call
            bool areEqual = comparer.Equals(structure, structure);

            // Assert
            Assert.IsTrue(areEqual);
        }
Example #21
0
        public void Equals_SameId_ReturnTrue(TestStructure secondStructure)
        {
            // Setup
            var comparer       = new StructureIdEqualityComparer();
            var firstStructure = new TestStructure();

            // Call
            bool firstEqualsSecond = comparer.Equals(firstStructure, secondStructure);
            bool secondEqualsFirst = comparer.Equals(secondStructure, firstStructure);

            // Assert
            Assert.IsTrue(firstEqualsSecond);
            Assert.IsTrue(secondEqualsFirst);
        }
 public IHttpActionResult DeleteTestStructure(int AdminId, int TestStructureId)
 {
     using (db_OnlineExaminationEntities db = new db_OnlineExaminationEntities())
     {
         TestStructure testStructure = db.TestStructures.Find(TestStructureId);
         if (testStructure == null || !testStructure.IsCurrent)
         {
             return(NotFound());
         }
         testStructure.SetProperties(AdminId: AdminId, IsCurrent: false /*, SetNumberOfQuestions: false*/);
         db.SaveChanges();
         return(Ok(testStructure));
     }
 }
Example #23
0
        public void CanAddGlobalSuffixWithTwoNames()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();
            var suffixName2   = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            TestStructure.TestAddGlobal <TestStructure>(new[] { suffixName, suffixName2 }, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName2));
        }
Example #24
0
        public void GetHashCode_EqualStructures_ReturnsSameHashCode()
        {
            // Setup
            var comparer     = new StructureIdEqualityComparer();
            var structureOne = new TestStructure();
            var structureTwo = new TestStructure();

            // Call
            int hashCodeOne = comparer.GetHashCode(structureOne);
            int hashCodeTwo = comparer.GetHashCode(structureTwo);

            // Assert
            Assert.AreEqual(hashCodeOne, hashCodeTwo);
        }
Example #25
0
        public void Equals_UnequalInstance_ReturnFalse()
        {
            // Setup
            var comparer        = new StructureIdEqualityComparer();
            var firstStructure  = new TestStructure("id");
            var secondStructure = new TestStructure("other id");

            // Call
            bool firstEqualsSecond = comparer.Equals(firstStructure, secondStructure);
            bool secondEqualsFirst = comparer.Equals(secondStructure, firstStructure);

            // Assert
            Assert.IsFalse(firstEqualsSecond);
            Assert.IsFalse(secondEqualsFirst);
        }
Example #26
0
        public void CantFindStaticSuffixThatDoesntExist()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);

            Assert.Throws(typeof(KOSSuffixUseException),
                          (() => testStructure.GetSuffix(suffixName)),
                          "failed to throw exception getting nonexistent static suffix");

            TestStructure.TestAddGlobal <TestStructure>(suffixName, testSuffix);
            Assert.IsNotNull(testStructure.GetSuffix(suffixName));
        }
Example #27
0
        public void InstanceSuffixesAreInFactInstanced()
        {
            var testObject    = new object();
            var testSuffix    = Substitute.For <ISuffix>();
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            testSuffix.Get().Returns(testObject);


            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);
            Assert.AreEqual(testObject, testStructure.GetSuffix(suffixName));
            Assert.Throws(typeof(KOSSuffixUseException),
                          (() => new TestStructure().GetSuffix(suffixName)),
                          "failed to throw exception getting instance suffix of unpopulated object");
        }
        public void Structure_Always_ExpectedValues()
        {
            // Setup
            var structure = new TestStructure();
            var input     = new SimpleStructuresInput();

            // Precondition
            Assert.IsFalse(input.Synchronized);

            // Call
            input.Structure = structure;

            // Assert
            Assert.AreSame(structure, input.Structure);
            Assert.IsTrue(input.Synchronized);
        }
Example #29
0
        public CourseStructure CreateCourseStructure(int courseId)
        {
            Course          course          = db.Courses.Find(courseId);
            CourseStructure courseStructure = new CourseStructure();

            courseStructure.IdCourse = course.Id;
            List <ParagraphStructure> listParag = new List <ParagraphStructure>();
            var paragraphs = db.Paragraphs.Where(p => p.CourseId == courseId).ToList();

            foreach (var par in paragraphs)
            {
                List <TestStructure> tests = new List <TestStructure>();
                var t = db.Tests.Where(te => te.ParagraphId == par.Id).ToList();
                foreach (var test in t)
                {
                    var           questions     = db.Questions.Where(q => q.TestId == test.Id);
                    TestStructure testStructure = new TestStructure()
                    {
                        NumQuestion = questions.Count(), IdTest = test.Id, NumInParagraph = test.NumInParagraph
                    };
                    List <QuestionStructure> queStructure = new List <QuestionStructure>();
                    foreach (var que in questions)
                    {
                        QuestionStructure q = new QuestionStructure()
                        {
                            Passed = false, NumInTest = que.NumInTest, IdQuestion = que.Id
                        };
                        queStructure.Add(q);
                    }
                    testStructure.QuestionStructures = queStructure;
                    db.TestStructures.Add(testStructure);
                    tests.Add(testStructure);
                }
                ParagraphStructure paragraphStructure = new ParagraphStructure()
                {
                    NumTest = tests.Count, Tests = tests, IdParagraph = par.Id, NumInCourse = par.NumInCourse
                };
                db.ParagraphStructures.Add(paragraphStructure);
                listParag.Add(paragraphStructure);
            }
            courseStructure.NumParagraph = listParag.Count();
            courseStructure.Paragraphs   = listParag;
            db.CourseStructures.Add(courseStructure);
            db.SaveChanges();
            return(courseStructure);
        }
Example #30
0
        public void CanLetInstanceTakePrecedenceOverStatic()
        {
            var testStructure = new TestStructure();
            var suffixName    = Guid.NewGuid().ToString();

            var testObject = new object();
            var testSuffix = Substitute.For <ISuffix>();

            testSuffix.Get().ReturnsForAnyArgs(info => testObject);
            testStructure.TestAddInstanceSuffix(suffixName, testSuffix);

            var testSuffixStatic = Substitute.For <ISuffix>();

            testSuffixStatic.Get().ReturnsForAnyArgs(info => int.MaxValue);
            TestStructure.TestAddGlobal <object>(suffixName, testSuffixStatic);

            Assert.IsNotNull(testStructure.GetSuffix(suffixName));
            Assert.AreSame(testObject, testStructure.GetSuffix(suffixName));
        }
Example #31
0
        public void LogValues_LogsCorrectValues()
        {
            // Arrange
            var sink = new TestSink();
            var logger = SetUp(sink);
            var testStructure = new TestStructure()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(testStructure);
            logger.LogInformation(testStructure);
            logger.LogWarning(testStructure);
            logger.LogError(testStructure);
            logger.LogCritical(testStructure);
            logger.LogDebug(testStructure);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];
            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Equal(testStructure, verbose.State);
            Assert.Equal(0, verbose.EventId);
            Assert.Equal(null, verbose.Exception);
            Assert.Equal("Test 1", verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];
            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Equal(testStructure, information.State);
            Assert.Equal(0, information.EventId);
            Assert.Equal(null, information.Exception);
            Assert.Equal("Test 1", information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];
            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Equal(testStructure, warning.State);
            Assert.Equal(0, warning.EventId);
            Assert.Equal(null, warning.Exception);
            Assert.Equal("Test 1", warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];
            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Equal(testStructure, error.State);
            Assert.Equal(0, error.EventId);
            Assert.Equal(null, error.Exception);
            Assert.Equal("Test 1", error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];
            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Equal(testStructure, critical.State);
            Assert.Equal(0, critical.EventId);
            Assert.Equal(null, critical.Exception);
            Assert.Equal("Test 1", critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[5];
            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Equal(testStructure, debug.State);
            Assert.Equal(0, debug.EventId);
            Assert.Equal(null, debug.Exception);
            Assert.Equal("Test 1", debug.Formatter(debug.State, debug.Exception));
        }
Example #32
0
        public void LogValuesEventIdAndError_LogsCorrectValues()
        {
            // Arrange
            var sink = new TestSink();
            var logger = SetUp(sink);
            var testStructure = new TestStructure()
            {
                Value = 1
            };

            // Act
            logger.LogVerbose(1, testStructure, _exception);
            logger.LogInformation(2, testStructure, _exception);
            logger.LogWarning(3, testStructure, _exception);
            logger.LogError(4, testStructure, _exception);
            logger.LogCritical(5, testStructure, _exception);
            logger.LogDebug(6, testStructure, _exception);

            // Assert
            Assert.Equal(6, sink.Writes.Count);

            var verbose = sink.Writes[0];
            Assert.Equal(LogLevel.Verbose, verbose.LogLevel);
            Assert.Equal(testStructure, verbose.State);
            Assert.Equal(1, verbose.EventId);
            Assert.Equal(_exception, verbose.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                verbose.Formatter(verbose.State, verbose.Exception));

            var information = sink.Writes[1];
            Assert.Equal(LogLevel.Information, information.LogLevel);
            Assert.Equal(testStructure, information.State);
            Assert.Equal(2, information.EventId);
            Assert.Equal(_exception, information.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                information.Formatter(information.State, information.Exception));

            var warning = sink.Writes[2];
            Assert.Equal(LogLevel.Warning, warning.LogLevel);
            Assert.Equal(testStructure, warning.State);
            Assert.Equal(3, warning.EventId);
            Assert.Equal(_exception, warning.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                warning.Formatter(warning.State, warning.Exception));

            var error = sink.Writes[3];
            Assert.Equal(LogLevel.Error, error.LogLevel);
            Assert.Equal(testStructure, error.State);
            Assert.Equal(4, error.EventId);
            Assert.Equal(_exception, error.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                error.Formatter(error.State, error.Exception));

            var critical = sink.Writes[4];
            Assert.Equal(LogLevel.Critical, critical.LogLevel);
            Assert.Equal(testStructure, critical.State);
            Assert.Equal(5, critical.EventId);
            Assert.Equal(_exception, critical.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                critical.Formatter(critical.State, critical.Exception));

            var debug = sink.Writes[4];
            Assert.Equal(LogLevel.Debug, debug.LogLevel);
            Assert.Equal(testStructure, debug.State);
            Assert.Equal(6, debug.EventId);
            Assert.Equal(_exception, debug.Exception);
            Assert.Equal(
                "Test 1" + Environment.NewLine + _exception,
                debug.Formatter(debug.State, debug.Exception));
        }