Пример #1
0
        private static void SeedInternalErrorLogEntries(LoggingDbContext context)
        {
            if (!context.InternalErrorLogEntries.Any())
            {
                context.InternalErrorLogEntries.AddRange(InternalErrorLogEntryFaker.Generate());
            }

            if (!context.AccountLogEntries.Any())
            {
                context.AccountLogEntries.AddRange(AccountLogEntryFaker.Generate());
            }

            if (!context.PaymentLogEntries.Any())
            {
                context.PaymentLogEntries.AddRange(PaymentLogEntryFaker.Generate());
            }

            if (!context.SearchQueryLogEntries.Any())
            {
                context.SearchQueryLogEntries.AddRange(SearchQueryLogEntryFaker.Generate());
            }

            if (!context.TicketActionLogEntries.Any())
            {
                context.TicketActionLogEntries.AddRange(TicketActionLogEntryFaker.Generate());
            }

            if (!context.TicketDealLogEntries.Any())
            {
                context.TicketDealLogEntries.AddRange(TicketDealLogEntryFaker.Generate());
            }

            context.SaveChanges();
        }
        public async Task ShouldGetFilteredEntries(string userId, string ticketId, string ticketName, TicketActionType type, string description, DateTime?dateFrom = null, DateTime?dateTo = null)
        {
            // Arrange
            Context.TicketActionLogEntries.AddRange(TicketActionLogEntryFaker.Generate(10));

            Context.TicketActionLogEntries.Add(new TicketActionLogEntryDbModel
            {
                UserId      = "alexpvt",
                TicketId    = "ticket",
                TicketName  = "opera aida",
                Type        = (int)TicketActionType.Add,
                Description = "TicketDescription",
                EventDate   = DateTimeNow
            });

            await Context.SaveChangesAsync();

            var filter = new TicketLogsFilter
            {
                UserId      = userId,
                TicketId    = ticketId,
                TicketName  = ticketName,
                Description = description,
                ActionType  = type,
                DateFrom    = dateFrom,
                DateTo      = dateTo
            };

            // Act
            var entries = await _ticketLogService.GetLogsAsync(filter);

            // Assert
            entries.Count().ShouldBeEqualTo(1);

            var entry = entries.Single();

            entry.UserId.ShouldBeEqualTo("alexpvt");
            entry.TicketId.ShouldBeEqualTo("ticket");
            entry.TicketName.ShouldBeEqualTo("opera aida");
            entry.ActionType.ShouldBeEqualTo(TicketActionType.Add);
            entry.Description.ShouldBeEqualTo("TicketDescription");
            entry.EventDate.ShouldBeEqualTo(DateTimeNow);
        }