public void PostAccidentCreationAndDeletionTest() { ///Initialization var db = new IncidentsDataContext(); var incidentType = db.IncidentTypes.FirstOrDefault(); var date = new DateTime(2019, 12, 1); var incident = new Incident() { Description = "Test description", Person = "Test Person", IncidentDate = date, IncidentTypeId = incidentType.Id }; var incidentsApiController = new IncidentsController(); ///Execution var result = incidentsApiController.PostIncident(incident); ///Assertion Assert.IsNotNull(result); int accidentId = incident.Id; Assert.IsTrue(accidentId > 0); ///Accident Car //var incidentAffectedRecord = db.Incidents.FirstOrDefault(c => c.Id == incidentId); //Assert.IsNotNull(accidentCar); //Assert.AreEqual(accidentCar.CarId, car.Id); //Assert.IsNotNull(accidentCar.CreationDate); //Assert.AreEqual(accidentCar.CreationDate.Value.Date, DateTime.Now.Date); /////Report //var report = db.Reports.FirstOrDefault(c => c.AccidentId == accidentId); //Assert.IsNotNull(report); }
public void GetIncidentById() { // Arrange. var testData = GetTestData(); var testEntity = testData.FirstOrDefault(e => e.Id == 1); var mockDbSet = new Mock <DbSet <Incident> >(); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.GetEnumerator()) .Returns(testData.AsQueryable().GetEnumerator); mockDbSet .Setup(m => m.Find(It.IsAny <object[]>())) .Returns <object[]>(ids => testData.FirstOrDefault(d => d.Id == (int)ids[0])); var mockDbContext = new Mock <BankDbContext>(); mockDbContext .Setup(m => m.Incidents) .Returns(mockDbSet.Object); var incidentsController = new IncidentsController(mockDbContext.Object); // Act. var actionResult = incidentsController.GetIncident(testEntity.Id) as OkNegotiatedContentResult <Incident>; // Assert. Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Content); Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Incident>)); Assert.AreEqual(testEntity, actionResult.Content); }
public void DeleteIncident() { // Arrange. var testData = GetTestData(); var testId = 2; var mockDbSet = new Mock <DbSet <Incident> >(); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.GetEnumerator()) .Returns(testData.AsQueryable().GetEnumerator()); mockDbSet .Setup(m => m.Find(It.IsAny <object[]>())) .Returns <object[]>(ids => testData.FirstOrDefault(d => d.Id == (int)ids[0])); mockDbSet .Setup(m => m.Remove(It.IsAny <Incident>())) .Callback <Incident>(entity => testData.Remove(entity)); var mockDbContext = new Mock <BankDbContext>(); mockDbContext .Setup(m => m.Incidents) .Returns(mockDbSet.Object); var incidentsController = new IncidentsController(mockDbContext.Object); // Act. var actionResult = incidentsController.DeleteIncident(testId) as OkResult; // Assert. Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult, typeof(OkResult)); }
public void CreateLinksGeneratesFourLinksWithCorrectIdsOrIncidentIds_WhenPassedAnIncidentId() { // Arrange var methods = new List <string>(); var ids = new List <object>(); var urlHelperMock = new Mock <IUrlHelper>(); urlHelperMock.Setup(link => link.Link(It.IsAny <string>(), It.IsAny <object>())) .Callback <string, object>( (s, o) => { methods.Add(s); ids.Add(o); } ); var incidentsController = new IncidentsController(null, null, urlHelperMock.Object); // Act incidentsController.CreateLinks("1", null, ""); // Assert urlHelperMock.Verify(foo => foo.Link(IncidentsController.GetSingleRouteName, It.IsAny <object>()), Times.Exactly(1)); urlHelperMock.Verify(foo => foo.Link(IncidentsController.PostSingleRouteName, It.IsAny <object>()), Times.Exactly(1)); urlHelperMock.Verify(foo => foo.Link(IncidentsController.GetMultipleRouteName, It.IsAny <object>()), Times.Exactly(1)); urlHelperMock.Verify(foo => foo.Link(EventsController.GetMultipleRouteName, It.IsAny <object>()), Times.Exactly(1)); Assert.AreEqual(GetProperty(ids[0], "id"), "1"); Assert.AreEqual(GetProperty(ids[1], "id"), ""); Assert.AreEqual(GetProperty(ids[2], "id"), ""); Assert.AreEqual(GetProperty(ids[3], "incidentId"), "1"); }
public void PostIncidentWithArchive() { IncidentsController api = new IncidentsController(); var response = api.GetIncidents(1); Assert.IsNotNull(response); }
public void GetIncidents() { IncidentsController api = new IncidentsController(); var response = api.GetIncidents(); Assert.IsNotNull(response); }
public void EditIncident() { // Arrange. var testData = GetTestData(); var testEntity = new Incident { Id = 4, ClientId = 1, Theme = "Жалоба", Date = DateTime.Now }; var mockDbSet = new Mock <DbSet <Incident> >(); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.GetEnumerator()) .Returns(testData.AsQueryable().GetEnumerator()); var mockDbContext = new Mock <BankDbContext>(); mockDbContext .Setup(m => m.Incidents) .Returns(mockDbSet.Object); mockDbContext .Setup(m => m.Entry(It.IsAny <Incident>())) .Callback(() => { testData.ForEach(e => { if (e.Id == testEntity.Id) { e.ClientId = testEntity.ClientId; e.Date = testEntity.Date; e.Text = testEntity.Text; e.Theme = testEntity.Theme; } }); }); var incidentsController = new IncidentsController(mockDbContext.Object); // Act. var actionResult = incidentsController.EditIncident(testEntity.Id, testEntity) as OkResult; var actEntity = testData.Find(e => e.Id == testEntity.Id); // Assert. Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult, typeof(OkResult)); Assert.AreEqual(testEntity.Id, actEntity.Id); Assert.AreEqual(testEntity.ClientId, actEntity.ClientId); Assert.AreEqual(testEntity.Date, actEntity.Date); Assert.AreEqual(testEntity.Text, actEntity.Text); Assert.AreEqual(testEntity.Theme, actEntity.Theme); }
public async Task GetIncidents() { var mockService = new Mock <IIncidentService>(); mockService.Setup(service => service.GetAll(null)).Returns(GetTestIncidents()); var controller = new IncidentsController(mockService.Object); var result = controller.Get(); Assert.Equal(2, result.Count); }
public async Task ArchiveIncident() { var mockService = new Mock <IIncidentService>(); mockService.Setup(service => service.GetAll(null)).Returns(GetTestIncidents()); var controller = new IncidentsController(mockService.Object); var result = controller.Archive("322323"); var incidents = controller.Get(); Assert.Single(incidents); }
public void PostIncident() { IncidentsController api = new IncidentsController(); var response = api.PostIncident(new Model.Models.Incident() { Kind = "TEST", HappenedAt = DateTime.Now, IsArchive = false, LocationId = "TEST" }); Assert.IsTrue(response); }
// List<Task<string>> tasks = new List<Task<string>>(); public AppHost( AlertRulesController alertRulesController, AuthenticationService authenticationService, AlertRuleTemplatesController alertRuleTemplatesController, IncidentsController incidentsController, ActionsController actionsController, BookmarksController bookmarksController, DataConnectorsController dataConnectorsController) { _alertRulesController = alertRulesController; _authenticationService = authenticationService; _alertRuleTemplatesController = alertRuleTemplatesController; _incidentsController = incidentsController; _actionsController = actionsController; _bookmarksController = bookmarksController; _dataConnectorsController = dataConnectorsController; }
public static void SendMail(string templateName, string sendTo, string cc, string subject, Dictionary <string, string> replacements, MailPriority priority = MailPriority.Normal, bool writeAsFile = false) { MailDefinition md = new MailDefinition(); md.BodyFileName = templateName; md.CC = cc; md.From = @"*****@*****.**"; md.Subject = subject; md.IsBodyHtml = true; MailMessage msg = md.CreateMailMessage(@sendTo, null, new System.Web.UI.Control()); foreach (var r in replacements) { string placeholder = String.Format(@"<%{0}%>", r.Key); msg.Body = msg.Body.Replace(placeholder, r.Value); } //string recipient, string subject,string body IncidentsController.SendEmail(sendTo, subject, msg.Body); }
public async Task PostIncident() { var mockService = new Mock <IIncidentService>(); mockService.Setup(service => service.GetAll(null)).Returns(GetTestIncidents()); var controller = new IncidentsController(mockService.Object); var result = controller.Post(new Incident() { _id = Guid.NewGuid().ToString(), isArchived = false, locationId = "23TplPdS", happenedAt = DateTime.Now.AddDays(3), kind = Kinds.ROBBERY }); var incidents = controller.Get(); Assert.Equal(3, incidents.Count); }
public void CreateIncident() { // Arrange. var testData = GetTestData(); var testEntity = new Incident { Id = 5, ClientId = 3, Theme = "Заявление", Date = DateTime.Now }; var mockDbSet = new Mock <DbSet <Incident> >(); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.GetEnumerator()) .Returns(testData.AsQueryable().GetEnumerator); mockDbSet .Setup(m => m.Add(It.IsAny <Incident>())) .Callback <Incident>(entity => testData.Add(entity)); var mockDbContext = new Mock <BankDbContext>(); mockDbContext .Setup(m => m.Incidents) .Returns(mockDbSet.Object); var incidentsController = new IncidentsController(mockDbContext.Object); // Act. var actionResult = incidentsController.CreateIncident(testEntity) as OkResult; var actEntity = testData.Find(e => e.Id == testEntity.Id); // Assert. Assert.IsNotNull(actionResult); Assert.IsInstanceOfType(actionResult, typeof(OkResult)); Assert.AreEqual(testEntity, actEntity); }
public void GetAllIncidents() { // Arrange. var testData = GetTestData(); var testClientId = 3; var mockDbSet = new Mock <DbSet <Incident> >(); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.Provider) .Returns(testData.AsQueryable().Provider); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.Expression) .Returns(testData.AsQueryable().Expression); mockDbSet .As <IQueryable <Incident> >() .Setup(m => m.GetEnumerator()) .Returns(() => testData.AsQueryable().GetEnumerator()); var mockDbContext = new Mock <BankDbContext>(); mockDbContext .Setup(m => m.Incidents) .Returns(mockDbSet.Object); var incidentsController = new IncidentsController(mockDbContext.Object); // Act. var actionResult = incidentsController.GetIncidents(testClientId) as OkNegotiatedContentResult <IQueryable <Incident> >; // Assert. Assert.IsNotNull(actionResult); Assert.IsNotNull(actionResult.Content); Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <IQueryable <Incident> >)); Assert.AreEqual(testData.Select(e => e.ClientId = testClientId).Count(), actionResult.Content.ToList().Count); }
public AppHost( IConfigurationRoot rawConfig, AzureSentinelApiConfiguration[] configurations, AlertRulesController alertRulesController, AuthenticationService authenticationService, AlertRuleTemplatesController alertRuleTemplatesController, IncidentsController incidentsController, ActionsController actionsController, BookmarksController bookmarksController, DataConnectorsController dataConnectorsController, IncidentRelationController incidentRelationController, SavedSearchController savedSearchController) { this.configurations = configurations; this.alertRulesController = alertRulesController; this.authenticationService = authenticationService; this.alertRuleTemplatesController = alertRuleTemplatesController; this.incidentsController = incidentsController; this.actionsController = actionsController; this.bookmarksController = bookmarksController; this.dataConnectorsController = dataConnectorsController; this.incidentRelationController = incidentRelationController; this.savedSearchController = savedSearchController; cliMode = rawConfig.GetValue <bool>("Climode"); string exeName = "AzureSentinel_ManagementAPI.exe"; cmdArgs = new TupleList <string, int> { { $": {exeName} 1 <actionRuleId> [instanceId]", 3 }, { $": {exeName} 2 <actionRuleId> <actionId> [instanceId]", 4 }, { $": {exeName} 3 <actionRuleId> <actionId> [instanceId]", 4 }, { $": {exeName} 4 <actionRuleId> [instanceId]", 3 }, { $": {exeName} 5 <alertRuleTemplateId> [instanceId]", 3 }, { $": {exeName} 6 [instanceId]", 2 }, { $": {exeName} 7 [instanceId]", 2 }, { $": {exeName} 8 [instanceId]", 2 }, { $": {exeName} 9 [instanceId]", 2 }, { $": {exeName} 10 <actionRuleId> [instanceId]", 3 }, { $": {exeName} 11 [instanceId]", 2 }, { $": {exeName} 12 <fusionRuleId> [instanceId]", 3 }, { $": {exeName} 13 <securityRuleId> [instanceId]", 3 }, { $": {exeName} 14 <scheduledRuleId> [instanceId]", 3 }, { $": {exeName} 15 [instanceId]", 2 }, { $": {exeName} 16 <bookmarkId> [instanceId]", 3 }, { $": {exeName} 17 <bookmarkId> [instanceId]", 3 }, { $": {exeName} 18 [instanceId]", 2 }, { $": {exeName} 19 [instanceId]", 2 }, { $": {exeName} 20 <bookmarkId> [instanceId]", 3 }, { $": {exeName} 21 [instanceId]", 2 }, { $": {exeName} 22 [instanceId]", 2 }, { $": {exeName} 23 <incidentId> [instanceId]", 3 }, { $": {exeName} 24 <incidentId> [instanceId]", 3 }, { $": {exeName} 25 [instanceId]", 2 }, { $": {exeName} 26 <incidentId> [instanceId]", 3 }, { $": {exeName} 27 [instanceId]", 2 }, { $": {exeName} 28 <incidentId> [instanceId]", 3 }, { $": {exeName} 29 <incidentId> [instanceId]", 3 }, { $": {exeName} 30 <incidentId> <commentId> [instanceId]", 4 }, { $": {exeName} 31 <incidentId> <bookmarkId> [instanceId]", 4 }, { $": {exeName} 32 <incidentId> <relationId> [instanceId]", 4 }, { $": {exeName} 33 <incidentId> [instanceId]", 3 }, { $": {exeName} 34 <incidentId> <relationId> [instanceId]", 4 }, { $": {exeName} 35 <incidentId> [instanceId]", 3 }, }; }