Пример #1
0
        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();
                }
            }
        }
Пример #2
0
        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")));
            }
        }
Пример #4
0
    protected virtual async Task SaveLogAsync(AuditLogInfo auditInfo)
    {
        using var uow = UnitOfWorkManager.Begin(true);
        await AuditLogRepository.InsertAsync(await Converter.ConvertAsync(auditInfo));

        await uow.CompleteAsync();
    }
Пример #5
0
        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);
        }
Пример #6
0
        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);
            }
        }
Пример #8
0
        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)
 {
 }
Пример #10
0
 public AuthorizeActionFilter(
     MixIdentityService idService,
     AuditLogRepository auditlogRepo,
     MixIdentityHelper mixIdentityHelper)
 {
     _idService         = idService;
     _auditlogRepo      = auditlogRepo;
     _mixIdentityHelper = mixIdentityHelper;
 }
Пример #11
0
 public TransactionManager(IContextProviderFactory contextProvider, UserResolverService userService, MongoDBManager _mongoManager
                           , AuditLogRepository _auditLogRepository)
 {
     //Context = context;
     Context            = contextProvider.dbContext;
     auditLogRepository = _auditLogRepository;
     mongoManager       = _mongoManager;
     currentUserId      = userService.GetCurrentUser();
 }
Пример #12
0
 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;
 }
Пример #13
0
 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)
 {
 }
Пример #14
0
 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)
 {
 }
Пример #15
0
 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)
 {
 }
Пример #16
0
 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)
 {
 }
Пример #17
0
        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
            });
        }
Пример #18
0
 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;
 }
Пример #19
0
        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());
        }
Пример #20
0
        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>));
        }
Пример #21
0
        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));
            }
        }
Пример #22
0
 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);
        }
Пример #24
0
        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();
                        }
        }
Пример #25
0
        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());
        }
Пример #26
0
        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>));
        }
Пример #27
0
        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());
        }
Пример #28
0
        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));
                }
            }
        }
Пример #30
0
 public ApiPostClientController(DefaultRepository <MixCmsContext, MixPost, PostViewModel> repo, AuditLogRepository auditlogRepo)
     : base(repo)
 {
     _auditlogRepo = auditlogRepo;
 }