Esempio n. 1
0
        public async Task GetFreeSlotsByAddressIdAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var orderRepo = new EfDeletableEntityRepository <Order>(dbContext);
            var taskRepo  = new EfDeletableEntityRepository <EnginieringTask>(dbContext);
            var slotRepo  = new EfDeletableEntityRepository <InstalationSlot>(dbContext);

            var moqAddressService = new Mock <IAddressService>();

            moqAddressService.Setup(x => x.GetCityIdByAddressIdAsync(It.IsAny <int>())).Returns(Task.FromResult(1));

            var service = new TasksService(
                slotRepo,
                moqAddressService.Object,
                taskRepo,
                orderRepo);

            var startingTime = DateTime.UtcNow.AddDays(2);
            var endingTime   = startingTime.AddHours(2);
            await slotRepo.AddAsync(new InstalationSlot
            {
                StartingTime = startingTime,
                EndingTime   = endingTime,
                Team         = new Team
                {
                    CityId = 1,
                },
            });

            await slotRepo.AddAsync(new InstalationSlot
            {
                StartingTime = startingTime,
                EndingTime   = endingTime,
                Team         = new Team
                {
                    CityId = 1,
                },
            });

            await slotRepo.SaveChangesAsync();

            var slots = await service.GetFreeSlotsByAddressIdAsync <SlotModel>(1);

            Assert.Equal(2, slots.Count());
            Assert.Contains(slots, x => x.TeamId == 1);
            Assert.Contains(slots, x => x.StartingTime == startingTime);
            Assert.Contains(slots, x => x.EndingTime == endingTime);
        }