/// <summary>
        /// Save an IncidentType to document store
        /// </summary>
        /// <param name="jsonIncidentType">Serilized IncidentType as Json string</param>
        /// <param name="repository">Document Storage as RavenDataController</param>
        /// <returns>Id of saved IncidentType as string</returns>
        public string CreateIncidentType(string jsonIncidentType, RavenDataController dataController)
        {
            Enforce.That(string.IsNullOrEmpty(jsonIncidentType) == false,
                                    "ErrorLoggingConntroller.CreateIncidentType - jsonIncidentType can not be null");

            var incidentType = JsonConvert.DeserializeObject<IncidentType>(jsonIncidentType);
            dataController.Save<IncidentType>(incidentType);

            return incidentType.Id;
        }
Esempio n. 2
0
        public void CanFetchAllIncidents()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIndicents = Create15Incidents();
            var dataController = new RavenDataController(docStore);
            batchIndicents.ForEach(x => dataController.Save<Incident>(x));

            int totalCount = 0;
            using(var session = docStore.OpenSession())
            {
                totalCount = session.Query<Incident>()
                                    .Customize(x => x.WaitForNonStaleResults())
                                    .Count();
            }

            //  Test
            var allIncidents = dataController.GetAll<Incident>();
            Assert.AreEqual(totalCount, allIncidents.Count);
        }
        /// <summary>
        /// Accept an Incident object, locate a potential parent incident
        /// and related incidents, and save to document storeage 
        /// </summary>
        /// <param name="incident">The new Incident object</param>
        /// <param name="dataController">Document storeage as RavenDataController</param>
        /// <returns>Logged Incident Id as string</returns>
        public string LogIncident(Incident incident, RavenDataController dataController)
        {
            //  When the minimum data is missing catalog this as unserviceable then save
            if (incident.CanIncidentBeLogged() == false)
            {
                incident.Title = "Unspecified error!";
                incident.IncidentDateTime = DateTime.Now;
                incident.Catalogged = false;
                incident.PageName = "No page name!";

                var unspecifiedIncidentType = new IncidentType("Unspecified", DateTime.Now, "Error logging did not capture results",
                                                                        "Gather more data");
                incident.IncidentType = unspecifiedIncidentType;
            }

            //  Has this occurred before?  Associate to parent / primary occurence
            var parentIncident = FindParent(incident.HashedTitle, dataController);
            if (string.IsNullOrEmpty(parentIncident.Id) == false)
            {
                incident.ParentIncidentId = parentIncident.Id;
                incident.RelatedIncidents = parentIncident.RelatedIncidents;
                incident.Resolved = parentIncident.Resolved;
                incident.Catalogged = parentIncident.Catalogged;
            }

            dataController.Save<Incident>(incident);

            return incident.Id;
        }
Esempio n. 4
0
        public void CanFindParentIncident()
        {
            //  Prep
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var parentIncident = CreateTransitionError();
            parentIncident.IncidentType = new IncidentType("ParentTypeError", new DateTime(2012, 1, 31),
                                                "The Parent Type", "Truncate database");

            var repository = new RavenDataController(docStore);
            repository.Save<Incident>(parentIncident);

            //  2 more incidents for our searching
            var incident2 = CreateTransitionError();
            incident2.PageName = "Incident 2";
            repository.Save<Incident>(incident2);

            var incident3 = CreateTransitionError();
            incident3.PageName = "Incident 3";
            repository.Save<Incident>(incident3);

            //  Test
            var errorLoggingController = new ErrorLoggingController();
            var foundParent = errorLoggingController.FindParent(parentIncident.HashedTitle, repository);

            Console.WriteLine(parentIncident.Id);
            Assert.AreEqual(parentIncident.IncidentType.Type, foundParent.IncidentType.Type);
        }
Esempio n. 5
0
        public void CanQueryIndexForUnresolvedIncidents()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIncidents = Create15Incidents();

            //  Mark 5 of these as resolved
            for (int i = 0; i <= 4; i++ )
            {
                batchIncidents[i].Resolved = true;
            }

            var dataController = new RavenDataController(docStore);
            batchIncidents.ForEach(x => dataController.Save<Incident>(x));

            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(UnresolvedIncidentIndex).Assembly, docStore);

            var unresolved = dataController.GetAll<Incident>("UnresolvedIncidentIndex");
            Assert.AreEqual(10, unresolved.Count);
        }
Esempio n. 6
0
        public void CreateIncidentTypes()
        {
            var docStore = GetDocStore();
            TruncateIncidentTypes(docStore);

            var dataController = new RavenDataController(docStore);

            var databaseType = new IncidentType("Database", new DateTime(2012, 3, 4), "Database offline", "reboot");
            dataController.Save<IncidentType>(databaseType);

            var javascriptType = new IncidentType("Javascript", new DateTime(2012, 3, 4), "jQuery not loaded", "review script");
            dataController.Save<IncidentType>(javascriptType);

            var nullObjectType = new IncidentType("Null Object Reference", new DateTime(2012, 3, 4), "Not record returned", "check database");
            dataController.Save<IncidentType>(nullObjectType);

            var pageNotFound = new IncidentType("Page Not Found", new DateTime(2012, 3, 4), "404", "check IIS");
            dataController.Save<IncidentType>(pageNotFound);
        }
Esempio n. 7
0
        public void CanQueryIndexForParentIncidents()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIncidents = Create15Incidents();
            var dataController = new RavenDataController(docStore);
            batchIncidents.ForEach(x => dataController.Save<Incident>(x));

            var parentIncidents = dataController.GetAll<Incident>("ParentIncidentIndex");
            Assert.AreEqual(2, parentIncidents.Count);
        }
Esempio n. 8
0
        public void CanQueryIndexForJavascriptIncidentType()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIndicents = Create15Incidents();
            var dataController = new RavenDataController(docStore);
            batchIndicents.ForEach(x => dataController.Save<Incident>(x));

            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(DistinctIncidentTypeIndex).Assembly, docStore);

            var javascriptIncidentType = dataController.GetAllWhere<DistinctIncidentTypeIndex.DistinctIncidentType>
                                                            (x => x.Name == "javascript",
                                                            "DistinctIncidentTypeIndex");

            Assert.AreEqual(5, javascriptIncidentType[0].Count);
        }
Esempio n. 9
0
        public void CanQueryForJavascriptIncidentType()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIndicents = Create15Incidents();
            var dataController = new RavenDataController(docStore);
            batchIndicents.ForEach(x => dataController.Save<Incident>(x));

            int totalJavascriptCount = 0;

            using(var session = docStore.OpenSession())
            {
                totalJavascriptCount = session.Query<Incident>()
                                                .Customize(x => x.WaitForNonStaleResults())
                                                .Where(x => x.IncidentType.Type == "javascript")
                                                .Count();
            }

            //  Test
            var javascriptIncidents = dataController.GetAllWhere<Incident>(inc => inc.IncidentType.Type == "javascript");
            Assert.AreEqual(totalJavascriptCount, javascriptIncidents.Count);
        }
Esempio n. 10
0
        public void CanLogIncidentAndAssociateToParent()
        {
            //  Prep
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            //  Parent
            var parentIncident = CreateTransitionError();
            parentIncident.IncidentType = new IncidentType("ParentTypeError", new DateTime(2012, 1, 31),
                                                "The Parent Type", "Truncate database");

            var repository = new RavenDataController(docStore);
            repository.Save<Incident>(parentIncident);

            //  2 more incidents for our searching
            var incident2 = CreateTransitionError();
            incident2.PageName = "Incident 2";
            repository.Save<Incident>(incident2);

            var incident3 = CreateTransitionError();
            incident3.PageName = "Incident 3";
            repository.Save<Incident>(incident3);

            //The child incident
            var childincident = CreateTransitionError();
            var errorController = new ErrorLoggingController();
            string childId = errorController.LogIncident(JsonConvert.SerializeObject(childincident), repository);

            var savedChild = repository.Get<Incident>(childId);

            Console.WriteLine("Child Parent Id " + savedChild.ParentIncidentId + " : Parent Id " + parentIncident.Id);
            Assert.AreEqual(parentIncident.Id, savedChild.ParentIncidentId);
        }
Esempio n. 11
0
        public void CanGetDistincIncidentTypeByIndex()
        {
            var docStore = GetDocStore();
            TruncateIncidentDocuments(docStore);

            var batchIndicents = Create15Incidents();
            var dataController = new RavenDataController(docStore);
            batchIndicents.ForEach(x => dataController.Save<Incident>(x));

            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(DistinctIncidentTypeIndex).Assembly, docStore);

            var distinctIncidentTypes = dataController
                                        .GetAll<DistinctIncidentTypeIndex.DistinctIncidentType>
                                                ("DistinctIncidentTypeIndex");

            Assert.AreEqual(4, distinctIncidentTypes.Count);
        }