Example #1
0
        public void CreateTicket_WithTicket_AddsTicketNumber()
        {
            // arrange
            using (var factory = new SupportCenterDbContextFactory())
            {
                Ticket toAdd = new Ticket()
                {
                    AccountId = 1, DateOpened = DateTime.Now, Responses = new List <TicketResponse>(),
                    State     = TicketState.Open, Text = "Test Ticket"
                };
                Ticket result = null;
                // get ctx
                using (var ctx = factory.CreateContext())
                {
                    // act
                    var repo = new TicketRepository(ctx);
                    result = repo.CreateTicket(toAdd);
                }

                // assert
                Assert.NotNull(result);
//				Assert.Null(result.TicketNumber);
                Assert.Equal(TestTicketsProvider.GetTestTickets().Count + 1, result.TicketNumber);
            }
        }
Example #2
0
        public void ReadTickets_WithTicketsInDb_ReturnsListOfTickets()
        {
            // arrange
            using (var factory = new SupportCenterDbContextFactory())
            {
                IEnumerable <Ticket> result = null;
                // get ctx
                using (var ctx = factory.CreateContext())
                {
                    // act
                    var repo = new TicketRepository(ctx);
                    result = repo.ReadTickets().ToList();
                }

                // assert
                Assert.NotNull(result);
                Assert.Equal(TestTicketsProvider.GetTestTickets().Count, result.Count());
            }
        }
Example #3
0
        public SupportCenterDbContext CreateContext(bool addTestData = true)
        {
            if (_connection == null)
            {
                _connection = new SqliteConnection("DataSource=:memory:");
                _connection.Open();

                var options = CreateOptions();
                using (var ctx = new SupportCenterDbContext(options))
                {
                    ctx.Database.EnsureCreated();
                    if (addTestData)
                    {
                        ctx.AddRange(TestTicketsProvider.GetTestTickets());
                        ctx.SaveChanges();
                    }
                }
            }

            return(new SupportCenterDbContext(CreateOptions()));
        }