public void RepositoryCanInsertSerializedEvents() { // Arrange DbContextOptions options = new DbContextOptionsBuilder().UseInMemoryDatabase().Options; SerializedEvent serializedEvent = new SerializedEvent { RoutingKey = "BackendService.RoomCreated", EventType = "RoomCreatedEvent", Body = "{room: 'chess123'}" }; // Act using (IRepository repository = new AuditLogRepository(new InMemoryAuditLogDbContext(options))) { repository.Insert(serializedEvent); } // Assert using (InMemoryAuditLogDbContext context = new InMemoryAuditLogDbContext(options)) { try { Assert.AreEqual(1, context.SerializedEvents.Count()); } finally { context.SerializedEvents.RemoveRange(context.SerializedEvents); context.SaveChanges(); } } }
public void RepositoryCanFindBy() { // Arrange DbContextOptions options = new DbContextOptionsBuilder().UseInMemoryDatabase().Options; InMemoryAuditLogDbContext context = new InMemoryAuditLogDbContext(options); SerializedEvent serializedEvent = new SerializedEvent { RoutingKey = "BackendService.RoomCreated", EventType = "RoomCreatedEvent", Body = "{room: 'chess123'}" }; SerializedEvent otherSerializedEvent = new SerializedEvent { RoutingKey = "BackendService.RoomCreated", EventType = "RoomCreatedEvent", Body = "{game: 'theultimategame'}" }; using (IRepository repository = new AuditLogRepository(new InMemoryAuditLogDbContext(options))) { repository.Insert(serializedEvent); repository.Insert(otherSerializedEvent); } // Assert using (IRepository repository = new AuditLogRepository(context)) { IEnumerable <SerializedEvent> foundItems = repository.FindBy(s => s.ID == otherSerializedEvent.ID); try { Assert.AreEqual(1, foundItems.Count()); Assert.AreEqual(otherSerializedEvent.ID, foundItems.First().ID); } finally { context.SerializedEvents.RemoveRange(context.SerializedEvents); context.SaveChanges(); } } }
public void WhenPublishingEventShouldResultInLogEntriesCountOfOne() { // Arrange using (var context = new AuditLogContext(_options)) { var repository = new AuditLogRepository(context); var eventListener = new AuditLogEventListener(repository); using var eventBus = new EventBusBuilder() .FromEnvironment() .CreateEventBus(new ConnectionFactory()) .AddEventListener(eventListener, "#"); var awaitHandle = new ManualResetEvent(false); // Act PublishMessage(eventBus); awaitHandle.WaitOne(1000); } // Assert using (var context = new AuditLogContext(_options)) { Assert.AreEqual(1, context.LogEntries.Count()); Assert.IsTrue(context.LogEntries.Any(entry => entry.EventJson.Contains("Hello world"))); } }
protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo) { using var uow = UnitOfWorkManager.Begin(true); await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo)); await uow.CompleteAsync(); }
public List <AuditLogsExt> GetListOfAuditLog(AuditLogSearch au) { AuditLogRepository modelRepo = new AuditLogRepository(); var logs = modelRepo.searchResult(au.StxtDateFrom, au.StxtDateTo, au.StxtAction, au.SUserID).ToList(); return(logs); }
public void CreateOneLogEntryResultsInCountOf5() { // Arrange using (var context = new AuditLogContext(_options)) { var repository = new AuditLogRepository(context); var logEntry = new LogEntry { Timestamp = new DateTime(2019, 7, 2).Ticks, EventJson = "{'title': 'Something'}", EventType = "DomainEvent", RoutingKey = "Test.TestQueue.TestCreated" }; // Act repository.Create(logEntry); } // Assert using (var context = new AuditLogContext(_options)) { var result = context.LogEntries.Count(); Assert.AreEqual(5, result); } }
/// <summary> /// Add Audit Log Entries /// </summary> /// <param name="_Action"> Action happened </param> /// <param name="ctlr">Object of Current Controller, just use "this" keyword</param> public static void AddAuditLog(string AuditLogShortDesc, string AuditLogLongDesc, Controller ctlr = null) { long?userID = null; if (ctlr != null && ctlr.User != null) { if (ctlr.User.Identity.IsAuthenticated) { using (DBEntities db = new DBEntities()) { var user = db.Users.FirstOrDefault(m => m.EmailAddress == ctlr.User.Identity.Name); userID = user.UserID; } } } AuditLogs log = new AuditLogs() { LogDate = DateTime.Now, AuditLogShortDesc = AuditLogShortDesc, AuditLogLongDesc = AuditLogLongDesc, UserID = userID }; if (log.UserID == null) { //If UserID is null it means this log is generated by Automation so add to AuditLog History Table in MVF_AuditHistory Database var auditLogRepository = new AuditLogRepository(); auditLogRepository.AddAuditLog_ToHistory(log); } else { var auditLogRepository = new AuditLogRepository(); auditLogRepository.AddAuditLog(log); } }
protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo) { using (var uow = UnitOfWorkManager.Begin(true)) { await AuditLogRepository.InsertAsync(new AuditLog (GuidGenerator, auditInfo)); await uow.SaveChangesAsync(); } }
public ApiTemplateController( DefaultRepository <MixCmsContext, MixTemplate, ReadViewModel> repo, DefaultRepository <MixCmsContext, MixTemplate, UpdateViewModel> updRepo, DefaultRepository <MixCmsContext, MixTemplate, DeleteViewModel> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) : base(repo, updRepo, delRepo, mixIdentityHelper, auditlogRepo) { }
public AuthorizeActionFilter( MixIdentityService idService, AuditLogRepository auditlogRepo, MixIdentityHelper mixIdentityHelper) { _idService = idService; _auditlogRepo = auditlogRepo; _mixIdentityHelper = mixIdentityHelper; }
public TransactionManager(IContextProviderFactory contextProvider, UserResolverService userService, MongoDBManager _mongoManager , AuditLogRepository _auditLogRepository) { //Context = context; Context = contextProvider.dbContext; auditLogRepository = _auditLogRepository; mongoManager = _mongoManager; currentUserId = userService.GetCurrentUser(); }
public ApiRoleController( DefaultRepository <MixCmsAccountContext, AspNetRoles, ReadViewModel> repo, DefaultRepository <MixCmsAccountContext, AspNetRoles, UpdateViewModel> updRepo, MixIdentityHelper mixIdentityHelper, RoleManager <IdentityRole> roleManager, AuditLogRepository auditlogRepo) : base(repo, updRepo, updRepo, mixIdentityHelper, auditlogRepo) { _roleManager = roleManager; }
public ApiConfigurationPortalController( DefaultRepository <MixCmsContext, MixConfiguration, ReadMvcViewModel> repo, DefaultRepository <MixCmsContext, MixConfiguration, UpdateViewModel> updRepo, DefaultRepository <MixCmsContext, MixConfiguration, UpdateViewModel> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) : base(repo, updRepo, delRepo, mixIdentityHelper, auditlogRepo) { }
public ApiLanguageController( DefaultRepository <MixCmsContext, MixLanguage, ReadMvcViewModel> repo, DefaultRepository <MixCmsContext, MixLanguage, UpdateViewModel> updRepo, DefaultRepository <MixCmsContext, MixLanguage, UpdateViewModel> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) : base(repo, updRepo, delRepo, mixIdentityHelper, auditlogRepo) { }
public MixDatabaseDataPortalController( DefaultRepository <MixCmsContext, MixDatabaseData, FormViewModel> repo, DefaultRepository <MixCmsContext, MixDatabaseData, FormViewModel> updRepo, DefaultRepository <MixCmsContext, MixDatabaseData, DeleteViewModel> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) : base(repo, updRepo, delRepo, mixIdentityHelper, auditlogRepo) { }
public ApiModuleController( DefaultRepository <MixCmsContext, MixModule, ReadListItemViewModel> repo, DefaultRepository <MixCmsContext, MixModule, UpdateViewModel> updRepo, DefaultRepository <MixCmsContext, MixModule, UpdateViewModel> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) : base(repo, updRepo, delRepo, mixIdentityHelper, auditlogRepo) { }
public ActionResult GenerateAuditLogDetails(long AuditLogID) { AuditLogRepository modelRepo = new AuditLogRepository(); var auditLog = modelRepo.ReadOne(AuditLogID); string InnerBody = SecurityUtils.RenderPartialToString(this, "GenerateAuditLogDetails", auditLog, ViewData, TempData); return(new JsonResult { Data = InnerBody }); }
public ApiThemeController( HttpService httpService, DefaultRepository <MixCmsContext, MixTheme, ReadViewModel> repo, DefaultRepository <MixCmsContext, MixTheme, UpdateViewModel> updRepo, DefaultRepository <MixCmsContext, MixTheme, DeleteViewModel> delRepo, MixIdentityHelper idHelper, AuditLogRepository auditlogRepo, IHubContext <PortalHub> hubContext) : base(repo, updRepo, delRepo, idHelper, auditlogRepo) { _httpService = httpService; _hubContext = hubContext; }
public void FindAllResultCountIs4() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); // Act var result = repository.FindAll(); // Assert Assert.AreEqual(4, result.Count()); }
public void FindAllIsInstanceOfIEnumerableOfLogEntry() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); // Act var result = repository.FindAll(); // Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <LogEntry>)); }
public void RepositoryCanBeInstantiated() { // Arrange DbContextOptions options = new DbContextOptionsBuilder().UseInMemoryDatabase().Options; InMemoryAuditLogDbContext context = new InMemoryAuditLogDbContext(options); // Assert using (IRepository repository = new AuditLogRepository(context)) { Assert.IsInstanceOfType(repository, typeof(IRepository)); } }
public BaseAuthorizedRestApiController( DefaultRepository <TDbContext, TModel, TRead> repo, DefaultRepository <TDbContext, TModel, TUpdate> updRepo, DefaultRepository <TDbContext, TModel, TDelete> delRepo, MixIdentityHelper mixIdentityHelper, AuditLogRepository auditlogRepo) { _repo = repo; _updRepo = updRepo; _delRepo = delRepo; _mixIdentityHelper = mixIdentityHelper; _auditlogRepo = auditlogRepo; }
public static void AddAuditLog(string AuditLogShortDesc, string AuditLogLongDesc, long UserID) { AuditLogs log = new AuditLogs() { LogDate = DateTime.Now,//DateTime.Now, AuditLogShortDesc = AuditLogShortDesc, AuditLogLongDesc = AuditLogLongDesc, UserID = UserID }; var auditLogRepository = new AuditLogRepository(); auditLogRepository.AddAuditLog(log); }
public static void Main(string[] args) { string connectionString = @"server=db;userid=admin;password=1234;database=auditlog;"; DbContextOptions options = new DbContextOptionsBuilder().UseMySQL(connectionString).Options; AuditLogDbContext context = new AuditLogDbContext(options); BusOptions busOptions = new BusOptions(hostname: "rabbitmq", port: 5672, username: "******", password: "******", exchangeName: "Lapiwe.GMS"); using (IRepository repo = new AuditLogRepository(context)) using (var all = new AllEventDispatcher(repo, busOptions)) using (var publisher = new AuditPublisher(busOptions)) using (var dispatcher = new AuditDispatcher(repo, publisher, busOptions)) { Console.Read(); } }
public void FindByWithNoDomainEventShouldBeCountOf4() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { FromTimestamp = new DateTime(2019, 2, 2).Ticks, ToTimestamp = new DateTime(2019, 9, 10).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.AreEqual(4, result.Count()); }
public void FindByIsInstanceOfIEnumerableOfLogEntry() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { EventType = "DomainEvent", FromTimestamp = new DateTime(2019, 7, 1).Ticks, ToTimestamp = new DateTime(2019, 7, 3).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <LogEntry>)); }
public void FindByWithTimestampsOutOfReachShouldBeCountOf0() { // Arrange using var context = new AuditLogContext(_options); var repository = new AuditLogRepository(context); var criteria = new LogEntryCriteria { EventType = "DomainEvent", FromTimestamp = new DateTime(2019, 6, 7).Ticks, ToTimestamp = new DateTime(2019, 6, 10).Ticks, }; // Act var result = repository.FindBy(criteria); // Assert Assert.AreEqual(0, result.Count()); }
public void Can_Add_AuditLog() { //Arrange IAuditLogRepository auditLogRepository = new AuditLogRepository(context); var log = new AuditLog { UserId = 1, EventMassage = "test", EventType = "test" }; //Act auditLogRepository.Add(log); var objectInDb = context.AuditLog.First(); //Assert Assert.True(context.AuditLog.Count() == 1); Assert.True(objectInDb.Id == 1); Assert.True(objectInDb.EventMassage == "test"); Assert.True(objectInDb.EventType == "test"); }
protected override void LoadChildren() { var auditRepository = new AuditLogRepository(); var unclaimedChanges = auditRepository.GetObjectsWithUnclimainedChangesByDatabaseAndType(_categoryItem.DatabaseName, _categoryItem.Type, DateTime.Today.AddMonths(-3), null); //ToDo: Not consistent with other viewmodel patterns. Store this in private variable field. //ToDo: Not consistent with other viewmodel patterns. Store this in private variable field. var utility = new UtilityRepository(); foreach (var child in _repository.GetObjectBasicInformationFromDatabaseAndType(_categoryItem.DatabaseName, _categoryItem.Type)) { var item = new DatabaseObjectItem(child.ObjectName, child.ObjectSchema, child.DatabaseName, _categoryItem.Type); var dbItem = new DatabaseObject { DatabaseName = child.DatabaseName, ObjectSchema = child.ObjectSchema, ObjectName = child.ObjectName, TypeCode = _categoryItem.Type }; item.HasPendingCheckin = !dbItem.IsUpToDate; if (unclaimedChanges.Any(u => u.ObjectInformation.DatabaseName == _categoryItem.DatabaseName && u.ObjectInformation.ObjectSchema == child.ObjectSchema && u.ObjectInformation.ObjectName == child.ObjectName)) { item.HasUnclaimedChanges = true; } if (_filter == DatabaseCategoryItemFilter.All || (_filter == DatabaseCategoryItemFilter.OnlyPendingCheckins && item.HasPendingCheckin) || (_filter == DatabaseCategoryItemFilter.OnlyUnclaimedChanges && item.HasUnclaimedChanges) || (_filter == DatabaseCategoryItemFilter.OnlyPendingOrUnclaimedChanges && (item.HasPendingCheckin || item.HasUnclaimedChanges)) ) { Children.Add(new DatabaseObjectItemViewModel(item, this)); } } }
public ApiPostClientController(DefaultRepository <MixCmsContext, MixPost, PostViewModel> repo, AuditLogRepository auditlogRepo) : base(repo) { _auditlogRepo = auditlogRepo; }