public async Task GetLocationQuery_GetLocationByCity_Executes_Failure(string invalidCity)
        {
            // Arrange
            IGetLocationQuery query = new GetLocationQuery();

            // Act & Assert
            await Assert.ThrowsAsync <LocationByCityNotFoundError>(async() => await query.GetLocationByCity(invalidCity));
        }
示例#2
0
        public async Task Ok()
        {
            var query = new GetLocationQuery {
                LocationId = 1
            };

            var result = await _handler.Handle(query, CancellationToken.None);

            Assert.NotNull(result);
            Assert.StrictEqual(_location, result);
        }
        public async Task GetLocationQuery_GetLocationByCity_Executes_Successfully(string city)
        {
            // Arrange
            IGetLocationQuery query = new GetLocationQuery();

            // Act
            var response = await query.GetLocationByCity(city);

            // Assert
            Assert.Equal(city, response.Title);
        }
示例#4
0
        public async Task LocationNotExist_Exception()
        {
            var query = new GetLocationQuery {
                LocationId = 2
            };

            Task Act() => _handler.Handle(query, CancellationToken.None);

            var ex = await Record.ExceptionAsync(Act) as EntityNotFoundException <Location>;

            Assert.NotNull(ex);
            Assert.Equal(2, ex.EntityId);
        }
        public async Task GetLocationQuery_GetLocationByLatLon_Executes_Successfully(double lat, double lon)
        {
            // Arrange
            Position          position = new Position(lat, lon);
            IGetLocationQuery query    = new GetLocationQuery();

            // Act
            var response = await query.GetLocationByLatLon(position);

            // Assert
            Assert.Equal(position.Lat, response.Position.Lat);
            Assert.Equal(position.Lon, response.Position.Lon);
            Assert.True(!string.IsNullOrWhiteSpace(response.Title));
        }
示例#6
0
        public async Task Then_The_Service_Is_Called(
            GetLocationQuery query,
            Domain.Entities.Location location,
            [Frozen] Mock <ILocationService> service,
            GetLocationQueryHandler handler)
        {
            //Arrange
            service.Setup(x => x.GetLocationsByLocationAuthorityName(query.LocationName, query.AuthorityName)).ReturnsAsync(location);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            actual.Location.Should().BeEquivalentTo(location);
        }
        public async Task <Result <LocationView> > Get([FromQuery] int locationId)
        {
            var result = new Result <LocationView>();

            try
            {
                var query    = new GetLocationQuery(locationId);
                var location = _mediator.Execute(query);
                result.Data = _mapper.Map <LocationView>(location);
            }
            catch (Exception e)
            {
                result.Error     = e.Message;
                result.IsSuccess = false;
            }
            finally
            {
                _logger.LogInformation($"Location for {locationId} retrieved.");
            }

            return(result);
        }
示例#8
0
        public List <LocationViewModel> GetAllLocation(GetLocationQuery q = null)
        {
            if (q == null)
            {
                q = new GetLocationQuery();
            }
            var query = @"select l.LocationCode,ser.ServerCode,ser.DefaultIP, l.RackUnit, s.StatusName,r.RackName,r.RackCode, ser.Id,r.StatusCode as RackStatus, acc.Fullname, acc1.Fullname as ServerOwner, ser.Power, s1.StatusName as ServerStatus, ser.Bandwidth, ser.Size,acc1.Phone, acc1.Email from Location as l
                            left join Status as s
                            on s.StatusCode = l.StatusCode
                            join Rack as r
                            on r.RackCode = l.RackCode
                            left join Server as ser on ser.ServerCode = l.ServerCode
                            left join RackOfCustomer as rack on rack.RackCode = r.RackCode and (rack.StatusCode='STATUS26' OR rack.StatusCode='STATUS27')
                            left join Account as acc on acc.Username = rack.Customer                            
							left join Account as acc1 on acc1.Username = ser.Customer
							left join Status as s1
							on s1.StatusCode = ser.StatusCode
                            where (isnull(@rackcode, '') = '' or l.RackCode = @rackcode)";

            return(RawQuery <LocationViewModel>(query,
                                                new SqlParameter("rackcode", q.RackCode)
                                                ));
        }
        public async Task <Result <LocationView> > AddDescription([FromForm] DescriptionRequestModel model)
        {
            var result = new Result <LocationView>();

            try
            {
                var addDescriptionqQery = new AddLocationDescriptionCommand(model.Location, model.Description);
                _mediator.Execute(addDescriptionqQery);
                var getLocationQuery = new GetLocationQuery(model.Location);
                var location         = _mediator.Execute(getLocationQuery);
                result.Data = _mapper.Map <LocationView>(location);
            }
            catch (Exception e)
            {
                result.Error     = e.Message;
                result.IsSuccess = false;
            }
            finally
            {
                _logger.LogInformation($"Location retrieved.");
            }

            return(result);
        }
示例#10
0
 public List <LocationViewModel> GetAllLocation(GetLocationQuery q = null)
 {
     return(dao.GetAllLocation(q));
 }