Example #1
0
        public async Task <Guid> AvailableOfficesAsync(CheckOfficeAvailailityCommand command)
        {
            Check.NotNull(command, nameof(command));

            return(await _applicationContext.Offices
                   .Where(x => x.OpenTime <= command.StartTime &&
                          x.CloseTime >= command.EndTime &&
                          x.Location == command.Location)
                   .Select(x => x.Id)
                   .FirstOrDefaultAsync());
        }
        public async Task AvailableOfficesAsync_Should_Return_Available_Office_By_Current_User_Is_Location()
        {
            //Arrange
            var context = Context;

            IOfficeBusiness officeBusiness = new OfficeBusiness(context,
                                                                _mapper,
                                                                _cache,
                                                                _busMock.Object);

            Office amsterdamOffice = new Office
            {
                Id        = Guid.NewGuid(),
                OpenTime  = new TimeSpan(8, 0, 0),
                CloseTime = new TimeSpan(17, 30, 0),
                Location  = "Amsterdam"
            };

            Office berlinOffice = new Office
            {
                Id        = Guid.NewGuid(),
                OpenTime  = new TimeSpan(8, 0, 0),
                CloseTime = new TimeSpan(20, 0, 0),
                Location  = "Berlin"
            };

            await context.Offices.AddAsync(amsterdamOffice);

            await context.Offices.AddAsync(berlinOffice);

            await context.SaveChangesAsync();

            CheckOfficeAvailailityCommand commandShouldCoverBoth = new CheckOfficeAvailailityCommand
            {
                //Should cover both offices
                Location  = "Amsterdam",
                StartTime = new TimeSpan(8, 0, 0),
                EndTime   = new TimeSpan(16, 0, 0)
            };

            //Act

            var amsterdamOfficeId = await officeBusiness.AvailableOfficesAsync(commandShouldCoverBoth);

            //Assert
            Assert.Equal(amsterdamOffice.Id, amsterdamOfficeId);
        }
Example #3
0
 public async Task <IActionResult> CheckAvailableOffices([FromBody] CheckOfficeAvailailityCommand command)
 {
     return(Ok(await _officeBusiness.AvailableOfficesAsync(command)));
 }