示例#1
0
        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);
        }
示例#2
0
        public void AlertWithSenderValidIsValid()
        {
            var alert = new Alert();
            alert.Sender = "*****@*****.**";

            var senderValidator = new SenderValidator(alert);
            Assert.True(senderValidator.IsValid);
        }
示例#3
0
        public void AlertWithNoteAndStatusExerciseIsValid()
        {
            var alert = new Alert();
            alert.Note = "maxOccurs";
            alert.Status = Status.Excercise;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
示例#4
0
        public void AlertWithNoteAndMessageTypeErrorIsValid()
        {
            var alert = new Alert();
            alert.Note = "maxOccurs";
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
示例#5
0
        public void AlertWithNoteNullAndStatusDifferentFromExerciseIsValid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.MessageType = MessageType.Cancel;

            var noteValidator = new NoteValidator(alert);
            Assert.True(noteValidator.IsValid);
        }
        public void AlertWithScopeRestrictedAndRestrictionIsValid()
        {
            var alert = new Alert();
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";

            var restrictionValidator = new RestrictionValidator(alert);
            Assert.True(restrictionValidator.IsValid);
        }
        public void AlertWithScopeDifferentFromRestrictedAndRestrictionNullIsValid()
        {
            var alert = new Alert();
            alert.Scope = Scope.Public;
            alert.Restriction = null;

            var restrictionValidator = new RestrictionValidator(alert);
            Assert.True(restrictionValidator.IsValid);
        }
示例#8
0
        public void AlertWithSenderContainingCommaIsInvalid()
        {
            var alert = new Alert();
            alert.Sender = "[email protected],";

            var senderValidator = new SenderValidator(alert);
            Assert.False(senderValidator.IsValid);
            Assert.Equal(typeof(SenderError), senderValidator.Errors.ElementAt(0).GetType());
        }
        public void MsgTypeWithNoErrorThatHasNotExplanationInNoteIsValid()
        {
            var alert = new Alert();
            alert.MessageType = MessageType.Cancel;
            alert.Note = null;

            var msgTypeRejectionValidator = new MessageTypeRejectionValidator(alert);
            Assert.True(msgTypeRejectionValidator.IsValid);
        }
        public void MsgTypeWithErrorThatHasExplanationInNoteIsValid()
        {
            var alert = new Alert();
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";

            var msgTypeRejectionValidator = new MessageTypeRejectionValidator(alert);
            Assert.True(msgTypeRejectionValidator.IsValid);
        }
        public void MsgTypeWithErrorThatHasExplanationInNoteNullIsInvalid()
        {
            var alert = new Alert();
            alert.MessageType = MessageType.Error;
            alert.Note = null;

            var msgTypeRejectionValidator = new MessageTypeRejectionValidator(alert);
            Assert.False(msgTypeRejectionValidator.IsValid);
            Assert.Equal(typeof(MessageTypeRejectionError), msgTypeRejectionValidator.Errors.ElementAt(0).GetType());
        }
示例#12
0
        public void AlertWithNoteNullAndStatusExerciseIsInvalid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.Status = Status.Excercise;

            var noteValidator = new NoteValidator(alert);
            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
示例#13
0
        public void AlertWithNoteNullAndMessageTypeErrorIsInvalid()
        {
            var alert = new Alert();
            alert.Note = null;
            alert.MessageType = MessageType.Error;

            var noteValidator = new NoteValidator(alert);
            Assert.False(noteValidator.IsValid);
            Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType());
        }
示例#14
0
        public void AlertWithScopeRestrictedAndRestrictionNullIsInvalid()
        {
            var alert = new Alert();
            alert.Scope = Scope.Restricted;
            alert.Restriction = null;

            var restrictionValidator = new RestrictionValidator(alert);
            Assert.False(restrictionValidator.IsValid);

            var restrictionErrors = from error in restrictionValidator.Errors
                                    where error.GetType() == typeof(RestrictionError)
                                    select error;
            Assert.NotEmpty(restrictionErrors);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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;
        }
示例#20
0
        public void CanCreateXElementFromEdxlDistribution()
        {
            var alert1 = new Alert { Identifier = "Alert1" };
            var alert2 = new Alert { Identifier = "Alert2", Code = "Secret" };

            var edxlDistribution = new EdxlDistribution
            {
                SenderId = "*****@*****.**",
                DistributionId = "ea6fa603-a967-4387-a79a-86cbd9cb5227",
                DateTimeSent = new DateTimeOffset(2015, 3, 28, 12, 23, 0, TimeSpan.FromHours(-2)),
                DateTimeExpires = new DateTimeOffset(2015, 3, 29, 12, 23, 0, TimeSpan.FromHours(-2)),
                DistributionStatus = new DistributionStatus
                {
                    StatusKindDefault = new StatusKindDefault
                    {
                        Value = StatusKindDefaultValues.Test
                    }
                },
                DistributionKind = new DistributionKind
                {
                    DistributionKindDefault = new DistributionKindDefault
                    {
                        Value = DistTypeDefaultValues.Report
                    }
                },
                Content = new Content()
            };
            edxlDistribution.Content.ContentObjects.Add(new ContentObject
            {
                ContentXml = new ContentXml
                {
                    EmbeddedXml = CAPNet.XmlCreator.Create(alert1)
                }
            });
            edxlDistribution.Content.ContentObjects.Add(new ContentObject
            {
                ContentXml = new ContentXml
                {
                    EmbeddedXml = CAPNet.XmlCreator.Create(alert2)
                }
            });
            var element = edxlDistribution.ToXElement();

            element.ToString()
                .ShouldBe(
            @"<EDXLDistribution xmlns:ct=""urn:oasis:names:tc:emergency:edxl:ct:1.0"" xmlns=""urn:oasis:names:tc:emergency:EDXL:DE:2.0"">
              <DistributionID>ea6fa603-a967-4387-a79a-86cbd9cb5227</DistributionID>
              <SenderID>[email protected]</SenderID>
              <DateTimeSent>2015-03-28T12:23:00-02:00</DateTimeSent>
              <DateTimeExpires>2015-03-29T12:23:00-02:00</DateTimeExpires>
              <DistributionStatus>
            <StatusKindDefault>
              <ct:ValueListURI>urn:oasis:names:tc:emergency:EDXL:DE:2.0:Defaults:StatusKind</ct:ValueListURI>
              <ct:Value>Test</ct:Value>
            </StatusKindDefault>
              </DistributionStatus>
              <DistributionKind>
            <DistributionKindDefault>
              <ct:ValueListURI>urn:oasis:names:tc:emergency:EDXL:DE:2.0:Defaults:DistributionType</ct:ValueListURI>
              <ct:Value>Report</ct:Value>
            </DistributionKindDefault>
              </DistributionKind>
              <Content>
            <ContentObject>
              <ContentXML>
            <EmbeddedXMLContent>
              <alert xmlns=""urn:oasis:names:tc:emergency:cap:1.2"">
            <identifier>Alert1</identifier>
            <status>Actual</status>
            <msgType>Alert</msgType>
            <scope>Public</scope>
              </alert>
            </EmbeddedXMLContent>
              </ContentXML>
            </ContentObject>
            <ContentObject>
              <ContentXML>
            <EmbeddedXMLContent>
              <alert xmlns=""urn:oasis:names:tc:emergency:cap:1.2"">
            <identifier>Alert2</identifier>
            <status>Actual</status>
            <msgType>Alert</msgType>
            <scope>Public</scope>
            <code>Secret</code>
              </alert>
            </EmbeddedXMLContent>
              </ContentXML>
            </ContentObject>
              </Content>
            </EDXLDistribution>");
        }
示例#21
0
        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);
        }