コード例 #1
0
        public void InfoWithNoParametersInTheListIsValid()
        {
            var info = new Info();

            var parametersValidator = new ParametersValidator(info);
            Assert.True(parametersValidator.IsValid);
        }
コード例 #2
0
ファイル: InfoTests.cs プロジェクト: darbio/cap-net
        public void LanguageSetsToUserValue()
        {
            var info = new Info();
            info.Language = "en-UK";

            Assert.Equal("en-UK", info.Language);
        }
コード例 #3
0
ファイル: AlertValidatorTests.cs プロジェクト: darbio/cap-net
        public void GeneralAlertWithAllRequiredFieldsIsValid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            var category = Category.Fire;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.True(alertValidator.IsValid);
        }
コード例 #4
0
        public void InfoWithParametersWithValueAndValueNameIsValid()
        {
            var info = new Info();
            var value = "123";
            var valueName = "HSAS";
            var parameter = new Parameter(valueName, value);
            info.Parameters.Add(parameter);

            var parametersValidator = new ParametersValidator(info);
            Assert.True(parametersValidator.IsValid);
        }
コード例 #5
0
        public void InfoWithEventCodeThatHasValueAndValueNameIsValid()
        {
            var info = new Info();
            string valueName = "HSAS";
            string value = "SVR";
            var eventCode = new EventCode(valueName, value);
            info.EventCodes.Add(eventCode);

            var eventCodesValidator = new EventCodesValidator(info);
            Assert.True(eventCodesValidator.IsValid);
        }
コード例 #6
0
        public void InfoWithParametersWithValueAndValueNameNullIsInvalid()
        {
            var info = new Info();
            var value = "13123";
            string valueName = null;
            var parameter = new Parameter(valueName, value);
            info.Parameters.Add(parameter);

            var parametersValidator = new ParametersValidator(info);
            Assert.False(parametersValidator.IsValid);
            Assert.Equal(typeof(ParameterError), parametersValidator.Errors.ElementAt(0).GetType());
        }
コード例 #7
0
        public void InfoWithEventCodeThatHasValueNullAndValueNameIsInvalid()
        {
            var info = new Info();
            string valueName = "HSAS";
            string value = null;
            var eventCode = new EventCode(valueName, value);
            info.EventCodes.Add(eventCode);

            var eventCodesValidator = new EventCodesValidator(info);
            Assert.False(eventCodesValidator.IsValid);
            Assert.Equal(typeof(EventCodeError), eventCodesValidator.Errors.ElementAt(0).GetType());
        }
コード例 #8
0
ファイル: InfoValidatorTests.cs プロジェクト: darbio/cap-net
        public void InfoWithRequiredFieldsIsValid()
        {
            Info info = new Info();
            //Required Fields : Categories,Event,Urgency,Severity,Certainty
            info.Categories.Add(Category.CBRNE);
            info.Event = "Event";
            info.Urgency = Urgency.Expected;
            info.Severity = Severity.Extreme;
            info.Certainty = Certainty.Likely;

            Alert alert = new Alert();
            alert.Info.Add(info);
            var infoValidator = new InfoValidator(alert);
            Assert.True(infoValidator.IsValid);
        }
コード例 #9
0
ファイル: AlertValidatorTests.cs プロジェクト: darbio/cap-net
        public void GeneralAlertWithNoCategoryAndCertaintyWrongSetAndSentNullIsInvalid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = null;

            var info = new Info();
            //info.Categories Is Empty
            //Certainty is not well set;
            info.Certainty = (Certainty)123;
            //Event is also required
            info.Event = "Important Event";
            //Severity Required
            info.Severity = Severity.Minor;
            //Urgency Required
            info.Urgency = Urgency.Future;

            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.False(alertValidator.IsValid);

            var categoryRequiredErrors = from error in alertValidator.Errors
                                         where typeof(CategoryRequiredError) == error.GetType()
                                         select error;
            Assert.NotEmpty(categoryRequiredErrors);

            var certaintyRequiredErrors = from error in alertValidator.Errors
                                          where typeof(CertaintyRequiredError) == error.GetType()
                                          select error;
            Assert.NotEmpty(certaintyRequiredErrors);

            var sentRequiredErrors = from error in alertValidator.Errors
                             where typeof(SentRequiredError) == error.GetType()
                             select error;
            Assert.NotEmpty(sentRequiredErrors);
        }
コード例 #10
0
ファイル: InfoValidatorTests.cs プロジェクト: darbio/cap-net
        public void InfoWithRequiredFieldsExceptCertaintyIsInvalid()
        {
            Info info = new Info();
            //Required Fields : Categories,Event,Urgency,Severity,Certainty
            info.Categories.Add(Category.CBRNE);
            info.Event = "Event";
            info.Urgency = Urgency.Expected;
            info.Severity = Severity.Extreme;
            //info.Certainty is missing

            Alert alert = new Alert();
            alert.Info.Add(info);
            var infoValidator = new InfoValidator(alert);
            Assert.False(infoValidator.IsValid);

            var infoErrors = from error in infoValidator.Errors
                             where error.GetType() == typeof(CertaintyRequiredError)
                             select error;
            Assert.NotEmpty(infoErrors);
        }
コード例 #11
0
ファイル: InfoValidatorTests.cs プロジェクト: darbio/cap-net
        public void InfoWithRequiredFieldsAndInvalidResponseTypeIsInvalid()
        {
            Info info = new Info();
            //Required Fields : Categories,Event,Urgency,Severity,Certainty
            info.Categories.Add(Category.CBRNE);
            info.Event = "Event";
            info.Urgency = Urgency.Expected;
            info.Severity = Severity.Extreme;
            info.Certainty = Certainty.Likely;
            info.ResponseTypes.Add((ResponseType)123);

            Alert alert = new Alert();
            alert.Info.Add(info);
            var infoValidator = new InfoValidator(alert);
            Assert.False(infoValidator.IsValid);

            var infoErrors = from error in infoValidator.Errors
                             where error.GetType() == typeof(ResponseTypeError)
                             select error;
            Assert.NotEmpty(infoErrors);
        }
コード例 #12
0
ファイル: XmlCreatorTests.cs プロジェクト: darbio/cap-net
        private static Alert CreateMultipleAlertXmlAlert()
        {
            var orangeAlert = new Alert
            {
                //<?xml version = "1.0" encoding = "UTF-8"?>
                //<alert xmlns = "urn:oasis:names:tc:emergency:cap:1.2">
                //  <identifier>43b080713727</identifier>
                Identifier = "43b080713727",
                //  <sender>[email protected]</sender>
                Sender = "*****@*****.**",
                //  <sent>2003-04-02T14:39:01-05:00</sent>
                Sent = new DateTimeOffset(2003, 4, 2, 14, 39, 1, TimeSpan.FromHours(-5)),
                //  <status>Actual</status>
                Status = Status.Actual,
                //  <msgType>Alert</msgType>
                MessageType = MessageType.Alert,
                //  <scope>Public</scope>
                Scope = Scope.Public,
                //  <source>source</source>
                Source = "source",
                //   <restriction>restriction</restriction>
                Restriction = "restriction",
                //   <code>code</code>
                Code = "code",
                //   <note>note</note>
                Note = "note",
                //   <references>references</references>

            };

            //<references>references reference2</references>
            orangeAlert.References.Add("references");
            orangeAlert.References.Add("reference2");

            //<addresses>"address 1" address2 " address 3" address4</addresses>
            orangeAlert.Addresses.Add("address 1");
            orangeAlert.Addresses.Add("address2");
            orangeAlert.Addresses.Add(" address 3");
            orangeAlert.Addresses.Add("address4");

            //<incidents>" incident0" incident1 incident2 "bad incident" "another bad incident"</incidents>
            orangeAlert.Incidents.Add(" incident0");
            orangeAlert.Incidents.Add("incident1");
            orangeAlert.Incidents.Add("incident2");
            orangeAlert.Incidents.Add("bad incident");
            orangeAlert.Incidents.Add("another bad incident");

            //  <info>
            var info = new Info();

            //    <language>en-US</language>
            info.Language = "en-US";
            //    <category>Security</category>
            info.Categories.Add(Category.Security);
            //    <event>Homeland Security Advisory System Update</event>
            info.Event = "Homeland Security Advisory System Update";
            //    <responsetype>Shelter</responsetype>
            info.ResponseTypes.Add(ResponseType.Shelter);
            //    <urgency>Immediate</urgency>
            info.Urgency = Urgency.Immediate;
            //    <severity>Severe</severity>
            info.Severity = Severity.Severe;
            //    <certainty>Likely</certainty>
            info.Certainty = Certainty.Likely;
            //    <audience>audience</audience>
            info.Audience = "audience";
            //<eventcode>
            //  <valuename>valN</valuename>
            //  <value>val</value>
            //</eventcode>
            info.EventCodes.Add(new EventCode("valN", "val"));
            info.EventCodes.Add(new EventCode("valN1", "val1"));
            //  <effective>2003-04-02T14:39:01-05:00</effective>
            info.Effective = new DateTimeOffset(2003, 4, 2, 14, 39, 1, TimeSpan.FromHours(-5));
            //  <onset>2003-04-02T14:39:01-05:00</onset>
            info.Onset = new DateTimeOffset(2003, 4, 2, 14, 39, 1, TimeSpan.FromHours(-5));
            //  <expires>2003-04-02T14:39:01-05:00</expires>
            info.Expires = new DateTimeOffset(2003, 4, 2, 14, 39, 1, TimeSpan.FromHours(-5));
            //    <senderName>U.S. Government, Department of Homeland Security</senderName>
            info.SenderName = "U.S. Government, Department of Homeland Security";
            //    <headline>Homeland Security Sets Code ORANGE</headline>
            info.Headline = "Homeland Security Sets Code ORANGE";
            //    <description>The Department of Homeland Security has elevated the Homeland Security Advisory System threat level to ORANGE / High in response to intelligence which may indicate a heightened threat of terrorism.</description>
            info.Description = "The Department of Homeland Security has elevated the Homeland Security Advisory System threat level to ORANGE / High in response to intelligence which may indicate a heightened threat of terrorism.";
            //    <instruction>A High Condition is declared when there is a high risk of terrorist attacks. In addition to the Protective Measures taken in the previous Threat Conditions, Federal departments and agencies should consider agency-specific Protective Measures in accordance with their existing plans.</instruction>
            info.Instruction = "A High Condition is declared when there is a high risk of terrorist attacks. In addition to the Protective Measures taken in the previous Threat Conditions, Federal departments and agencies should consider agency-specific Protective Measures in accordance with their existing plans.";
            //    <web>http://www.dhs.gov/dhspublic/display?theme=29</web>
            info.Web = new Uri("http://www.dhs.gov/dhspublic/display?theme=29");
            //    <contact>contact</contact>
            info.Contact = "contact";
            //    <parameter>
            //      <valueName>HSAS</valueName>
            //      <value>ORANGE</value>
            //    </parameter>
            info.Parameters.Add(new Parameter("HSAS", "ORANGE"));
            //    <resource>
            info.Resources.Add(new Resource
            {
                //      <resourceDesc>Image file (GIF)</resourceDesc>
                Description = "Image file (GIF)",
                //      <mimeType>image/gif</mimeType>
                MimeType = "image/gif",
                //      <size>1</size>
                Size = 1,
                //      <uri>http://www.dhs.gov/dhspublic/getAdvisoryImage</uri>
                Uri = new Uri("http://www.dhs.gov/dhspublic/getAdvisoryImage"),
                //      <derefUri>ZGVyZWZVcmk=</derefUri>
                DereferencedUri = Convert.FromBase64String("ZGVyZWZVcmk="),
                //      <digest>digest</digest>
                Digest = "digest",
                //    </resource>

            });

            //  <area>
            var area = new Area
            {
                //  <areaDesc>U.S. nationwide and interests worldwide</areaDesc>
                Description = "U.S. nationwide and interests worldwide",
                //  <altitude>altitude</altitude>
                Altitude = 100,
                //  <ceiling>ceiling</ceiling>
                Ceiling = 120,
            };

            //<polygon>1 2 3 4</polygon>
            //<polygon>1 22 33 4</polygon>
            area.Polygons.Add(new Polygon("1,2 2,2 3,3 4,4"));
            area.Polygons.Add(new Polygon("1,1 22,1 33,1 1,1"));
            //<circle>1 2</circle>
            //<circle>1 22</circle>
            area.Circles.Add(new Circle(new Coordinate(1, 2), 2));
            area.Circles.Add(new Circle(new Coordinate(1, 2), 22));
            //<geocode>
            //  <valueName>valN</valueName>
            //  <value>val</value>
            //</geocode>
            //<geocode>
            //  <valueName>valN1</valueName>
            //  <value>val1</value>
            //</geocode>
            area.GeoCodes.Add(new GeoCode("valN", "val"));
            area.GeoCodes.Add(new GeoCode("valN1", "val1"));
            info.Areas.Add(area);
            //  </area>
            //  </info>

            orangeAlert.Info.Add(info);
            //</alert>
            return orangeAlert;
        }
コード例 #13
0
ファイル: InfoTests.cs プロジェクト: darbio/cap-net
        public void LanguageDefaultsToEnglish()
        {
            var info = new Info();

            Assert.Equal("en-US", info.Language);
        }
コード例 #14
0
ファイル: AlertValidatorTests.cs プロジェクト: darbio/cap-net
        public void GeneralAlertWithWrongCategoryInInfoIsInvalid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            //invalid category set :
            var category = (Category)123;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.False(alertValidator.IsValid);
            var categoryErrors = from error in alertValidator.Errors
                                 where typeof(InvalidCategoryError) == error.GetType()
                                 select error;
            Assert.NotEmpty(categoryErrors);
        }