Exemple #1
0
        /// <summary>
        /// Convert a <see cref="SignalboxHoursSetModel" /> instance to a <see cref="SignalboxHoursSet" /> instance.
        /// </summary>
        /// <param name="model">The object to convert.</param>
        /// <param name="signalboxes">A dictionary of known signalboxes, for resolving references.</param>
        /// <param name="existingSets">An enumeration of existing signalbox hours sets, to ensure this routine does not duplicate the ID of an existing set.</param>
        /// <returns>A <see cref="SignalboxHoursSet" /> containing the same data as the <c>model</c> parameter with references resolved.</returns>
        /// <exception cref="NullReferenceException">Thrown if the <c>model</c> parameter is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Thrown if the <c>signalboxes</c> or <c>existingSets</c> parameters are <c>null</c>.</exception>
        public static SignalboxHoursSet ToSignalboxHoursSet(
            this SignalboxHoursSetModel model,
            IDictionary <string, Signalbox> signalboxes,
            IEnumerable <SignalboxHoursSet> existingSets)
        {
            if (model is null)
            {
                throw new NullReferenceException();
            }
            if (signalboxes is null)
            {
                throw new ArgumentNullException(nameof(signalboxes));
            }
            if (existingSets is null)
            {
                throw new ArgumentNullException(nameof(existingSets));
            }

            SignalboxHoursSet hoursSet = new SignalboxHoursSet {
                Id = GeneralHelper.GetNewId(existingSets), Category = model.Category
            };

            foreach (SignalboxHoursModel hoursModel in model.Signalboxes)
            {
                SignalboxHours hours = hoursModel.ToSignalboxHours(signalboxes);
                hoursSet.Hours.Add(hours.Signalbox.Id, hours);
            }
            return(hoursSet);
        }
Exemple #2
0
        private static SignalboxHoursSetModel GetTestObject()
        {
            int count = _rnd.Next(1, 10);
            SignalboxHoursSetModel output = new SignalboxHoursSetModel
            {
                Category = _rnd.NextString(_rnd.Next(20)),
            };

            for (int i = 0; i < count; ++i)
            {
                string boxId;
                do
                {
                    boxId = _rnd.NextHexString(8);
                } while (output.Signalboxes.Any(b => b.SignalboxId == boxId));
                output.Signalboxes.Add(new SignalboxHoursModel
                {
                    SignalboxId         = boxId,
                    StartTime           = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.HoursMinutesSeconds).Model,
                    FinishTime          = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.HoursMinutesSeconds).Model,
                    TokenBalanceWarning = _rnd.NextNullableBoolean()
                });
            }

            return(output);
        }
        public void SignalboxHoursSetModelClass_Constructor_SetsSignalboxesPropertyToEmptyCollection()
        {
            SignalboxHoursSetModel testOutput = new SignalboxHoursSetModel();

            Assert.IsNotNull(testOutput.Signalboxes);
            Assert.AreEqual(0, testOutput.Signalboxes.Count);
        }
Exemple #4
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithHoursPropertyContainingCorrectNumberOfElements()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.AreEqual(testParam0.Signalboxes.Count, testOutput.Hours.Count);
        }
Exemple #5
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithCorrectCategoryProperty()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.AreEqual(testParam0.Category, testOutput.Category);
        }
Exemple #6
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithIdPropertyThatDiffersFromIdsOfContentsOfThirdParameter()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.IsFalse(testParam2.Any(s => s.Id == testOutput.Id));
        }
Exemple #7
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsArgumentNullException_IfSecondParameterIsNull()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = null;
            IEnumerable <SignalboxHoursSet> testParam2 = new List <SignalboxHoursSet>();

            _ = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.Fail();
        }
Exemple #8
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsNullReferenceException_IfFirstParameterIsNull()
        {
            SignalboxHoursSetModel          testParam0 = null;
            IDictionary <string, Signalbox> testParam1 = new Dictionary <string, Signalbox>();
            IEnumerable <SignalboxHoursSet> testParam2 = new List <SignalboxHoursSet>();

            _ = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.Fail();
        }
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsArgumentNullException_IfFirstParameterIsNull()
        {
            SignalboxHoursSetModel          testObject = null;
            IDictionary <string, Signalbox> testParam1 = new Dictionary <string, Signalbox>();
            IEnumerable <SignalboxHoursSet> testParam2 = Array.Empty <SignalboxHoursSet>();

            _ = testObject.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.Fail();
        }
Exemple #10
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithHoursPropertyContainingCorrectlyIndexedElements()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            foreach (KeyValuePair <string, SignalboxHours> item in testOutput.Hours)
            {
                Assert.AreEqual(item.Key, item.Value.Signalbox.Id);
            }
        }
Exemple #11
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithHoursPropertyContainingElementsWithCorrectSignalboxProperties()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            foreach (string id in testParam0.Signalboxes.Select(s => s.SignalboxId))
            {
                Assert.AreSame(testParam1[id], testOutput.Hours[id].Signalbox);
            }
        }
Exemple #12
0
        /// <summary>
        /// Convert a <see cref="SignalboxHoursSet" /> instance into a <see cref="SignalboxHoursSetModel" /> instance.
        /// </summary>
        /// <param name="hoursSet">The data to be converted.</param>
        /// <returns>A <see cref="SignalboxHoursSetModel" /> instance that is equivalent to the hoursSet parameter.</returns>
        public static SignalboxHoursSetModel ToSignalboxHoursSetModel(this SignalboxHoursSet hoursSet)
        {
            if (hoursSet is null)
            {
                throw new ArgumentNullException(nameof(hoursSet));
            }

            SignalboxHoursSetModel model = new SignalboxHoursSetModel
            {
                Category = hoursSet.Category,
            };

            model.Signalboxes.AddRange(hoursSet.Hours.Values.Select(h => h.ToSignalboxHoursModel()));
            return(model);
        }
        /// <summary>
        /// Convert a <see cref="SignalboxHoursSet" /> instance to a <see cref="SignalboxHoursSetModel" /> instance.
        /// </summary>
        /// <param name="set">The object to convert.</param>
        /// <returns>A <see cref="SignalboxHoursSetModel" /> instance containing the same data as the parameter in serialisable form.</returns>
        /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception>
        public static SignalboxHoursSetModel ToYamlSignalboxHoursSetModel(this SignalboxHoursSet set)
        {
            if (set is null)
            {
                throw new NullReferenceException();
            }

            SignalboxHoursSetModel shsm = new SignalboxHoursSetModel
            {
                Category = set.Category,
            };

            shsm.Signalboxes.AddRange(set.Hours.Values.Select(h => h.ToYamlSignalboxHoursModel()));
            return(shsm);
        }
Exemple #14
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsFormatException_IfFirstParameterHasSignalboxesPropertyContainingElementsWithFinishTimePropertyThatHaveTimePropertyThatIsNotNumeric()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            foreach (SignalboxHoursModel box in testParam0.Signalboxes)
            {
                box.FinishTime = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.NonNumericValue).Model;
            }

            _ = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.Fail();
        }
Exemple #15
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsNullReferenceException_IfFirstParameterHasSignalboxesPropertyContainingElementsWithFinishTimePropertyThatIsNull()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();

            foreach (SignalboxHoursModel box in testParam0.Signalboxes)
            {
                box.FinishTime = null;
            }

            _ = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            Assert.Fail();
        }
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfFirstParameterIsNull()
        {
            SignalboxHoursSetModel          testObject = null;
            IDictionary <string, Signalbox> testParam1 = new Dictionary <string, Signalbox>();
            IEnumerable <SignalboxHoursSet> testParam2 = Array.Empty <SignalboxHoursSet>();

            try
            {
                _ = testObject.ToSignalboxHoursSet(testParam1, testParam2);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("model", ex.ParamName);
            }
        }
Exemple #17
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithHoursPropertyContainingElementsWithCorrectTokenBalanceWarningProperty()
        {
            SignalboxHoursSetModel          testParam0 = GetTestObject();
            IDictionary <string, Signalbox> testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet> testParam2 = GetExistingSets();
            Dictionary <string, bool?>      tokenBalanceWarningFlags = new Dictionary <string, bool?>();

            foreach (SignalboxHoursModel box in testParam0.Signalboxes)
            {
                tokenBalanceWarningFlags.Add(box.SignalboxId, box.TokenBalanceWarning);
            }

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            foreach (string id in testParam0.Signalboxes.Select(s => s.SignalboxId))
            {
                Assert.AreEqual(tokenBalanceWarningFlags[id] ?? false, testOutput.Hours[id].TokenBalanceWarning);
            }
        }
Exemple #18
0
        public void SignalboxHoursSetModelExtensionsClass_ToSignalboxHoursSetMethod_ReturnsObjectWithHoursPropertyContainingElementsWithCorrectEndTimeProperty_IfFirstParameterHasSignalboxesPropertyContainingElementsWithFinishTimePropertiesThatHaveTimePropertyThatIsMoreThanThreeNumbersWithinRangeSeparatedByColons()
        {
            SignalboxHoursSetModel                      testParam0 = GetTestObject();
            IDictionary <string, Signalbox>             testParam1 = GetSignalboxCollectionWithItems(testParam0.Signalboxes.Select(s => s.SignalboxId));
            IEnumerable <SignalboxHoursSet>             testParam2 = GetExistingSets();
            Dictionary <string, TimeOfDaySpecification> timeSpecs  = new Dictionary <string, TimeOfDaySpecification>();

            foreach (SignalboxHoursModel box in testParam0.Signalboxes)
            {
                TimeOfDaySpecification timeSpec = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.HoursMinutesSecondsAndMore);
                box.FinishTime = timeSpec.Model;
                timeSpecs.Add(box.SignalboxId, timeSpec);
            }

            SignalboxHoursSet testOutput = testParam0.ToSignalboxHoursSet(testParam1, testParam2);

            foreach (string id in testParam0.Signalboxes.Select(s => s.SignalboxId))
            {
                Assert.AreEqual(timeSpecs[id].Hours.Value, testOutput.Hours[id].EndTime.Hours24);
                Assert.AreEqual(timeSpecs[id].Minutes.Value, testOutput.Hours[id].EndTime.Minutes);
                Assert.AreEqual(timeSpecs[id].Seconds.Value, testOutput.Hours[id].EndTime.Seconds);
            }
        }
        public void SignalboxHoursSetModelClass_Constructor_CreatesObjectThatHasSignalboxesPropertyThatIsNotNull()
        {
            SignalboxHoursSetModel testOutput = new SignalboxHoursSetModel();

            Assert.IsNotNull(testOutput.Signalboxes);
        }