public async Task TestUpdateCreateLocationAsync_InvalidModel()
        {
            controller.ModelState.AddModelError("key", "error");
            var model = new UpdatedLocationBindingModel
            {
                LocationTypeId = LocationType.Building.Id,
            };
            var response = await controller.PutUpdateLocationAsync(model);

            Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult));
        }
        public async Task TestPutUpdateLocationAsync()
        {
            var model = new UpdatedLocationBindingModel
            {
                LocationTypeId = LocationType.Building.Id,
            };

            userProvider.Setup(x => x.GetBusinessUser(It.IsAny <IWebApiUser>())).Returns(new User(1));
            serviceMock.Setup(x => x.GetLocationByIdAsync(It.IsAny <int>())).ReturnsAsync(new LocationDTO());
            var response = await controller.PutUpdateLocationAsync(model);

            Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <LocationDTO>));
            serviceMock.Verify(x => x.UpdateAsync(It.IsAny <UpdatedLocation>()), Times.Once());
            serviceMock.Verify(x => x.SaveChangesAsync(), Times.Once());
            userProvider.Verify(x => x.GetCurrentUser(), Times.Once());
            userProvider.Verify(x => x.GetBusinessUser(It.IsAny <IWebApiUser>()), Times.Once());
        }
        public async Task <IHttpActionResult> PutUpdateLocationAsync([FromBody] UpdatedLocationBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var currentUser  = this.userProvider.GetCurrentUser();
                var businessUser = this.userProvider.GetBusinessUser(currentUser);
                await this.locationService.UpdateAsync(model.ToUpdatedLocation(businessUser));

                await this.locationService.SaveChangesAsync();

                var dto = await this.locationService.GetLocationByIdAsync(model.Id);

                return(Ok(dto));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public void TestToUpdatedLocation()
        {
            var userId         = 1;
            var user           = new User(userId);
            var latitude       = 1.0f;
            var longitude      = 2.0f;
            var cityId         = 3;
            var divisionId     = 4;
            var countryId      = 5;
            var regionId       = 6;
            var name           = "name";
            var locationTypeId = LocationType.Building.Id;
            var model          = new UpdatedLocationBindingModel
            {
                CityId         = cityId,
                CountryId      = countryId,
                DivisionId     = divisionId,
                RegionId       = regionId,
                Latitude       = latitude,
                Name           = name,
                LocationTypeId = locationTypeId,
                Longitude      = longitude
            };

            var instance = model.ToUpdatedLocation(user);

            Assert.AreEqual(latitude, instance.Latitude);
            Assert.AreEqual(longitude, instance.Longitude);
            Assert.AreEqual(cityId, instance.CityId);
            Assert.AreEqual(divisionId, instance.DivisionId);
            Assert.AreEqual(countryId, instance.CountryId);
            Assert.AreEqual(regionId, instance.RegionId);
            Assert.AreEqual(name, instance.LocationName);
            Assert.AreEqual(locationTypeId, instance.LocationTypeId);
            Assert.IsTrue(Object.ReferenceEquals(user, instance.Audit.User));
        }