public async Task TestCreateHotelFacilityRelation_SuccessOkResponse() { //Arrange var userName = "******"; var id = 1; var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); mockFacilitiesRepository.Setup(x => x.InsertAndUpdateHotelFacilityRelation(It.IsAny <HotelFacilityViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>() { Result = 1 })); //Act IActionResult result = await mockFacilitiesController.CreateHotelFacilityRelation(facilityModel); BaseResult <long> finalResult = (result as Microsoft.AspNetCore.Mvc.OkObjectResult).Value as BaseResult <long>; //Assert Assert.AreEqual(((Microsoft.AspNetCore.Mvc.ObjectResult)result).StatusCode, 200); Assert.IsNotNull(finalResult); Assert.IsTrue(!finalResult.IsError); Assert.IsTrue(finalResult.Result != default(long)); Assert.IsTrue(finalResult.Result == id); }
public void TestCreateHotelFacilityRelation_Failed_Error() { //Arrange var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); mockFacilitiesRepository.Setup(x => x.InsertAndUpdateHotelFacilityRelation(It.IsAny <HotelFacilityViewModel>(), It.IsAny <string>())).Returns(Task.FromResult(new BaseResult <long>() { IsError = true, ExceptionMessage = Helper.Common.GetMockException() })).Verifiable(); //Act var result = mockFacilitiesController.CreateHotelFacilityRelation(facilityModel); //Assert mockFacilitiesRepository.Verify(); Assert.IsTrue(result.Result is StatusCodeResult); Assert.AreEqual(((StatusCodeResult)result.Result).StatusCode, 500); }
public async Task <IActionResult> CreateHotelFacilityRelation([FromBody] HotelFacilityViewModel hotelFacilityViewModel) { string userName = base.LoggedInUserName; if (hotelFacilityViewModel != null) { BaseResult <long> result = await this.iFacilities.InsertAndUpdateHotelFacilityRelation(hotelFacilityViewModel, userName); if (result.IsError || result.ExceptionMessage != null) { return(new StatusCodeResult(500)); } return(this.Ok(result)); ////200 } else { return(this.BadRequest()); } }
public async Task <IActionResult> CreateContractFacilityRelation([FromBody] HotelFacilityViewModel hotelFacilityViewModel) { BaseResult <long> result = new BaseResult <long>(); if (hotelFacilityViewModel != null) { result = await this.iFacilities.InsertAndUpdateContractFacilityRelation(hotelFacilityViewModel, base.LoggedInUserName); if (result.IsError || result.ExceptionMessage != null) { return(StatusCode(500, result)); } return(this.Ok(result)); ////200 } else { result.IsError = true; result.Message = Core.Model.Helper.Constants.ErrorMessage.EmptyModel; return(this.BadRequest(result)); } }
public void TestCreateHotelFacilityRelation_Id() { //Arrange var hotelId = 73; var id = 1; HotelFacilityRelation hotelFacilityRelation = new HotelFacilityRelation { HotelId = hotelId, FacilityId = id, FacilityTypeId = id, FacilityGroupId = id, IsDeleted = false, IsProvisioned = true, CreatedBy = "MGIT", UpdatedBy = "MGIT", StartDate = DateTime.Now, EndDate = DateTime.Now }; var userName = "******"; var facilities = new FacilityViewModel() { Id = 1, FacilityGroupId = 1, FacilityTypeId = 1, IsSelected = true, IsActive = true, Name = "ABC" }; var facilityType = new HotelFacilityTypeViewModel() { FacilityTypeId = 1, FacilityGroupId = 1, FacilityTypeName = "TypeName", }; facilityType.FacilityList.Add(facilities); var facilityGroup = new HotelFacilityGroupViewModel() { FacilityGroupId = 1, FacilityGroupName = "Group1", IconPath = "", }; facilityGroup.HotelFacilityTypes.Add(facilityType); var facilityModel = new HotelFacilityViewModel() { HotelId = 73, }; facilityModel.FacilityGroupList.Add(facilityGroup); iHotelFacilityRelationLibrary.Setup(a => a.InsertEntity(It.IsAny <HotelFacilityRelation>())).Returns(Task.FromResult(new BaseResult <long>() { Result = id })); //Act var result = facilitiesRepository.InsertAndUpdateHotelFacilityRelation(facilityModel, userName); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Result.Result == id); }
/// <summary> /// Saves The Facilities of that specific hotel /// </summary> /// <param name="hotelFacilityViewModel">hotel Facility View Model</param> /// <returns>long</returns> public async Task <BaseResult <long> > InsertAndUpdateHotelFacilityRelation(HotelFacilityViewModel hotelFacilityViewModel, string userName) { BaseResult <long> result = new BaseResult <long>(); if (hotelFacilityViewModel != null) { foreach (var item in hotelFacilityViewModel.FacilityGroupList) { foreach (var facilityType in item.HotelFacilityTypes) { foreach (var facility in facilityType.FacilityList) { if (facility.ObjectState == ObjectState.Added) { if (facility.IsSelected == true) { HotelFacilityRelation hotelFacilityRelation = new HotelFacilityRelation { HotelId = hotelFacilityViewModel.HotelId, FacilityId = facility.Id, FacilityTypeId = facility.FacilityTypeId, FacilityGroupId = facility.FacilityGroupId, IsDeleted = false, IsProvisioned = facility.IsSelected, CreatedBy = userName, UpdatedBy = userName, StartDate = DateTime.Now, EndDate = DateTime.Now }; result = await this.iHotelFacilityRelationLibrary.InsertEntity(hotelFacilityRelation); if (result.IsError) { return(result); } } } if (facility.ObjectState == ObjectState.Deleted) { BaseResult <bool> updateResult = new BaseResult <bool>(); var facilities = this.iHotelFacilityRelationLibrary.GetListByPredicate(x => x.HotelId == hotelFacilityViewModel.HotelId && x.Id == facility.FacilityRelationId && x.FacilityId == facility.Id && x.IsDeleted == false).Result.Result.FirstOrDefault(); if (facilities != null) { facilities.IsDeleted = true; facilities.UpdatedBy = userName; facilities.UpdatedDate = DateTime.Now.JakartaOffset(); updateResult = await this.iHotelFacilityRelationLibrary.UpdateEntityByDapper(facilities); if (updateResult.IsError && updateResult.ExceptionMessage != null) { result.IsError = updateResult.IsError; result.ExceptionMessage = updateResult.ExceptionMessage; return(result); } result.Result = facilities.Id; } if (result.IsError) { return(result); } } } } } } return(result); }