Exemple #1
0
        public async Task GetTourByDate(string date, TaskCompletionSource <Tour> receivedTask)
        {
            if (string.IsNullOrWhiteSpace(date))
            {
                throw new ArgumentNullException(nameof(date));
            }

            using (var context = ToursContextFactory.Create())
            {
                try
                {
                    DateTime dt         = DateTime.Parse(date);
                    Tour     tourEntity = await context.Tours.SingleAsync(t => t.Date == dt);

                    if (tourEntity is null)
                    {
                        receivedTask.TrySetCanceled();
                        return;
                    }

                    receivedTask.TrySetResult(tourEntity);
                }
                catch (Exception e)
                {
                    receivedTask.TrySetException(e);
                }
            }
        }
Exemple #2
0
        private ToursContext CreateContextAndMigrateDb()
        {
            var context = ToursContextFactory.Create();

            context.Database.Migrate();
            return(context);
        }
Exemple #3
0
        public async Task GetTourById(int id, TaskCompletionSource <Tour> receivedTask)
        {
            using (var context = ToursContextFactory.Create())
            {
                try
                {
                    var entity = await context.Tours.SingleOrDefaultAsync(t => t.Id == id);

                    if (entity is null)
                    {
                        receivedTask.TrySetCanceled();
                    }
                    receivedTask.TrySetResult(entity);
                }
                catch (Exception e)
                {
                    receivedTask.TrySetException(e);
                }
            }
        }
Exemple #4
0
 public TestDbFixture()
 {
     ToursContextFactory = new ToursContextFactory(
         "Server=(localdb)\\mssqllocaldb;Database=FliGen.Tours.Test;Trusted_Connection=True;MultipleActiveResultSets=true");
     Context = GetInitiatedToursContext();
 }