コード例 #1
0
        public async void AdditionTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Database")
                          .Options;


            // Use a clean instance of the context to run the test
            using (var context = new ApplicationDbContext(options))
            {
                EFRepositoryAsync <Calendar> calendarRepository =
                    new EFRepositoryAsync <Calendar>(context);

                List <Calendar> calendars = context.Calendars.ToList();

                await calendarRepository.AddAsync(new Calendar { Title = "calendar 4" });

                await calendarRepository.SaveAsync();

                List <Calendar> updatedCalendars = context.Calendars.ToList();

                int expected = calendars.Count + 1;
                int actual   = updatedCalendars.Count;

                Assert.Equal(expected, actual);
            }
        }
コード例 #2
0
        public async void DeletionTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Database")
                          .Options;

            const string CALENDAR_NAME = "calendar to delete";

            // Use a clean instance of the context to run the test
            using (var context = new ApplicationDbContext(options))
            {
                EFRepositoryAsync <Calendar> calendarRepository =
                    new EFRepositoryAsync <Calendar>(context);

                await calendarRepository.AddAsync(new Calendar { Title = CALENDAR_NAME });

                await calendarRepository.SaveAsync();

                List <Calendar> calendars = context.Calendars.ToList();

                Calendar calendarToDelete = calendars.First(c => c.Title == CALENDAR_NAME);

                calendarRepository.Remove(calendarToDelete);
                await calendarRepository.SaveAsync();

                List <Calendar> updatedCalendars = context.Calendars.ToList();

                int actual   = updatedCalendars.Count();
                int expected = calendars.Count() - 1;

                Assert.Equal(expected, actual);
            }
        }
コード例 #3
0
        public async void UpdationTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Database")
                          .Options;

            const string CALENDAR_TO_UPDATE_NAME = "calendar to update";
            const string UPDATED_CALENDAR_NAME   = "updated calendar";

            using (var context = new ApplicationDbContext(options))
            {
                EFRepositoryAsync <Calendar> calendarRepository =
                    new EFRepositoryAsync <Calendar>(context);

                await calendarRepository.AddAsync(new Calendar { Title = CALENDAR_TO_UPDATE_NAME });

                await calendarRepository.SaveAsync();

                List <Calendar> calendars = context.Calendars.ToList();

                Calendar calendarToUpdate = calendars
                                            .First(c => c.Title == CALENDAR_TO_UPDATE_NAME);
                calendarToUpdate.Title = UPDATED_CALENDAR_NAME;
                HashSet <Calendar> expectedCalendars = calendars.ToHashSet();

                calendarRepository.Update(calendarToUpdate);
                await calendarRepository.SaveAsync();

                HashSet <Calendar> actualCalendars = context.Calendars.ToHashSet();

                Assert.Equal(expectedCalendars, actualCalendars);
            }
        }