public async Task GetBookingByOutletAndDate_IsSuccess_Test() { //arrange var appointmentBooked = prepareAppointmentDetails(); var services = prepareServices(); var therapists = prepareTherapists(); AppointmentDetailRepoMock.Setup(p => p.GetAsync(It.IsAny <Expression <Func <AppointmentDetail, bool> > >(), null, null, null, null)).ReturnsAsync(appointmentBooked); ServiceRepoMock.Setup(p => p.GetAsync(It.IsAny <Expression <Func <Domain.Models.Service, bool> > >(), null, null, null, null)).ReturnsAsync(services); TherapistRepoMock.Setup(p => p.GetAsync(It.IsAny <Expression <Func <Staff, bool> > >(), null, null, null, null)); BedRepoMock.Setup(p => p.Get(It.IsAny <Expression <Func <Bed, bool> > >(), null, null, null, null)).Returns(new List <Bed>() { new Bed() { ID = 1 }, new Bed() { ID = 2 } }); AppointmentDetailRepoMock.Setup(p => p.Get(It.IsAny <Expression <Func <AppointmentDetail, bool> > >(), null, null, null, null)).Returns(appointmentBooked); //act var appointmentService = new AppointmentService(RepoHelperMock.Object, MapperMock.Object); var result = await appointmentService.GetBookingByOutletAndDate(1, new DateTime(2019, 12, 18)); //Assert Assert.IsTrue(result.IsSuccess); }
private ServiceService Arrange(List <ServiceVersioned> list = null) { var serviceList = list ?? _list; var publishedItem = serviceList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault(); var id = publishedItem.Id; var rootId = publishedItem.UnificRootId; unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes( It.IsAny <IQueryable <ServiceVersioned> >(), It.IsAny <Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > >(), It.IsAny <bool>() )).Returns((IQueryable <ServiceVersioned> services, Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > func, bool applyFilters) => { return(services); }); var unitOfWork = unitOfWorkMockSetup.Object; var contextManager = new TestContextManager(unitOfWork, unitOfWork); var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService, VersioningManager, UserInfoService, UserOrganizationChecker); translationManagerMockSetup.Setup(t => t.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>())) .Returns((ServiceVersioned entity) => { if (entity == null) { return(null); } return(new VmOpenApiServiceVersionBase() { Id = entity.UnificRootId, PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId) }); }); var translationManagerMock = translationManagerMockSetup.Object; VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, rootId, PublishingStatus.Published, true)).Returns(id); // repositories ServiceRepoMock.Setup(g => g.All()).Returns(serviceList.AsQueryable()); ServiceNameRepoMock.Setup(m => m.All()).Returns(Enumerable.Empty <ServiceName>().AsQueryable()); var serviceNameRepoMock = new Mock <IServiceNameRepository>(); unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceNameRepository>()).Returns(serviceNameRepoMock.Object); return(new ServiceService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, serviceUtilities, DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache, VersioningManager, gdService, UserOrganizationChecker)); }
public void NoLanguageVersionsPublished() { // Arrange var list = EntityGenerator.GetServiceEntityList(1, PublishingStatusCache); // set available languages to empty list.ForEach(o => o.LanguageAvailabilities = new List <ServiceLanguageAvailability>()); var publishedOrganization = list.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault(); var service = Arrange(list); // Act var result = service.GetServiceById(publishedOrganization.UnificRootId, DefaultVersion, VersionStatusEnum.Published); // Assert result.Should().BeNull(); ServiceRepoMock.Verify(x => x.All(), Times.Once()); unitOfWorkMockSetup.Verify(x => x.ApplyIncludes(It.IsAny <IQueryable <ServiceVersioned> >(), It.IsAny <Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > >(), It.IsAny <bool>()), Times.Once()); translationManagerMockSetup.Verify(x => x.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>()), Times.Never); }
public AddServiceTests() { _serviceId = Guid.NewGuid(); _serviceVersionedId = Guid.NewGuid(); _channelId = Guid.NewGuid(); _channelVersionedId = Guid.NewGuid(); SetupTypesCacheMock <ServiceType>(); SetupTypesCacheMock <ServiceChargeType>(); var serviceVersioned = new ServiceVersioned { Id = _serviceVersionedId, UnificRootId = _serviceId, UnificRoot = new Model.Models.Service() { Id = _serviceId, ServiceServiceChannels = new List <ServiceServiceChannel>() }, Organization = new Model.Models.Organization() }; var channelVersioned = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishedId, _channelId, _channelVersionedId); channelVersioned.UnificRoot = new ServiceChannel { Id = _channelId, Versions = new List <ServiceChannelVersioned> { channelVersioned } }; var connectionList = new List <ServiceServiceChannel> { new ServiceServiceChannel { Service = serviceVersioned.UnificRoot, ServiceId = serviceVersioned.UnificRootId, ServiceChannel = channelVersioned.UnificRoot, ServiceChannelId = channelVersioned.UnificRootId } }; translationManagerVModelMockSetup.Setup(t => t.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <IVmOpenApiServiceInVersionBase>(), It.IsAny <IUnitOfWorkWritable>())) .Returns((IVmOpenApiServiceInVersionBase x, IUnitOfWorkWritable y) => { if (!string.IsNullOrEmpty(x.StatutoryServiceGeneralDescriptionId)) { serviceVersioned.StatutoryServiceGeneralDescriptionId = x.StatutoryServiceGeneralDescriptionId.ParseToGuid(); } serviceVersioned.PublishingStatusId = PublishingStatusCache.Get(x.PublishingStatus); if (x.ServiceNames?.Count > 0) { serviceVersioned.ServiceNames = new List <ServiceName>(); x.ServiceNames.ForEach(n => serviceVersioned.ServiceNames.Add(new ServiceName { Name = n.Value })); } if (!string.IsNullOrEmpty(x.Type)) { serviceVersioned.TypeId = TypeCache.Get <ServiceType>(x.Type); } if (!string.IsNullOrEmpty(x.ServiceChargeType)) { serviceVersioned.ChargeTypeId = TypeCache.Get <ServiceChargeType>(x.ServiceChargeType); } return(serviceVersioned); }); translationManagerVModelMockSetup.Setup(t => t.TranslateAll <VmOpenApiServiceServiceChannelInVersionBase, ServiceServiceChannel>(It.IsAny <List <V7VmOpenApiServiceServiceChannelAstiInBase> >(), It.IsAny <IUnitOfWorkWritable>())) .Returns((List <V7VmOpenApiServiceServiceChannelAstiInBase> x, IUnitOfWorkWritable y) => { var connections = new List <ServiceServiceChannel>(); x.ForEach(c => { var cv = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishedId, c.ChannelGuid, _channelVersionedId); cv.UnificRoot = new ServiceChannel { Id = c.ChannelGuid, Versions = new List <ServiceChannelVersioned> { cv } }; var connection = new ServiceServiceChannel { ServiceChannelId = c.ChannelGuid, ServiceChannel = cv.UnificRoot }; if (c.Description?.Count > 0) { connection.ServiceServiceChannelDescriptions = new List <ServiceServiceChannelDescription>(); c.Description.ForEach(d => { var description = new ServiceServiceChannelDescription { Description = d.Value }; connection.ServiceServiceChannelDescriptions.Add(description); }); connections.Add(connection); } }); return(connections); }); ServiceRepoMock.Setup(g => g.All()).Returns((new List <ServiceVersioned> { serviceVersioned }).AsQueryable()); ConnectionRepoMock.Setup(g => g.All()).Returns(connectionList.AsQueryable()); //ServiceChannelRepoMock.Setup(g => g.All()).Returns((new List<ServiceChannelVersioned> { channelVersioned }).AsQueryable()); unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes( It.IsAny <IQueryable <ServiceVersioned> >(), It.IsAny <Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > >(), It.IsAny <bool>() )).Returns(new List <ServiceVersioned> { serviceVersioned }.AsQueryable()); unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes( It.IsAny <IQueryable <ServiceServiceChannel> >(), It.IsAny <Func <IQueryable <ServiceServiceChannel>, IQueryable <ServiceServiceChannel> > >(), It.IsAny <bool>() )).Returns(connectionList.AsQueryable()); VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWorkMockSetup.Object, _serviceId, PublishingStatus.Published, true)).Returns(_serviceVersionedId); translationManagerMockSetup.Setup(t => t.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>())) .Returns((ServiceVersioned sv) => { var vm = new VmOpenApiServiceVersionBase() { Id = sv.UnificRootId, StatutoryServiceGeneralDescriptionId = sv.StatutoryServiceGeneralDescriptionId, PublishingStatus = PublishingStatusCache.GetByValue(sv.PublishingStatusId) }; if (sv.ServiceNames?.Count > 0) { vm.ServiceNames = new List <VmOpenApiLocalizedListItem>(); sv.ServiceNames.ForEach(n => vm.ServiceNames.Add(new VmOpenApiLocalizedListItem { Value = n.Name })); } if (sv.UnificRoot?.ServiceServiceChannels?.Count > 0) { vm.ServiceChannels = new List <V7VmOpenApiServiceServiceChannel>(); sv.UnificRoot.ServiceServiceChannels.ForEach(c => { var channel = new V7VmOpenApiServiceServiceChannel { ServiceChannel = new VmOpenApiItem { Id = c.ServiceChannelId } }; vm.ServiceChannels.Add(channel); }); } return(vm); }); }