public Switch()
        {
#if DEBUG_IN_EXTERNAL_APP
            MessageBox.Show("Attach debugger now");
#endif
            HandleAssemblyResolveEvents();
            device       = CompositionRoot.GetDeviceLayer();
            idOutOfRange = new InvalidValueException($"The switch ID must be in the range 0 .. {MaxSwitch-1}");
        }
示例#2
0
        protected static T Parse <T, K>(K value, string name, Func <T, bool> predicate) where T : Enumeration
        {
            var matchingItem = All <T>().FirstOrDefault(predicate);

            if (matchingItem == null)
            {
                throw InvalidValueException.Error <T, K>(name, value);
            }
            return(matchingItem);
        }
示例#3
0
        public void TestBasicExceptionGeneration()
        {
            const string expectedErrorMessage = "The provided value ('Provided') is not the one expected ('Expected').";
            const string expectedValue        = "Expected";
            const string providedValue        = "Provided";

            var error = new InvalidValueException(providedValue, expectedValue);

            Assert.NotNull(error);
            Assert.Null(error.InnerException);
            Assert.Equal(expectedErrorMessage, error.Message);
        }
示例#4
0
        public void TestOuterExceptionGeneration()
        {
            const string expectedErrorMessage      = "The provided value ('Provided') is not the one expected ('Expected').";
            const string expectedOuterErrorMessage = "An error occured while checking the provided value ('Provided').";
            const string expectedValue             = "Expected";
            const string providedValue             = "Provided";

            var error = new InvalidValueException(providedValue, expectedValue);

            var outerError = new CheckProvidedValueException(error, providedValue);

            Assert.NotNull(outerError);
            Assert.NotNull(outerError.InnerException);
            Assert.Equal(expectedOuterErrorMessage, outerError.Message);
            Assert.Equal(expectedErrorMessage, outerError.InnerException.Message);
        }