public void Archived_OnlyOnePerRootIdReturned() { var rootId = Guid.NewGuid(); // Let's create two version for same root organization var deletedItem = EntityGenerator.CreateEntity <OrganizationVersioned, Model.Models.Organization, OrganizationLanguageAvailability>(PublishingStatusCache.Get(PublishingStatus.Deleted), rootId); deletedItem.UnificRoot = new Model.Models.Organization { Id = rootId }; var oldPublishedItem = EntityGenerator.CreateEntity <OrganizationVersioned, Model.Models.Organization, OrganizationLanguageAvailability>(PublishingStatusCache.Get(PublishingStatus.OldPublished), rootId); oldPublishedItem.UnificRoot = new Model.Models.Organization { Id = rootId }; var list = new List <OrganizationVersioned> { deletedItem, oldPublishedItem }; var result = ArrangeAndAct(null, list, 1, 1, true); // Assert result.Should().NotBeNull(); result.PageCount.Should().Be(1);// Only one item per root should be found var vmResult = Assert.IsType <VmOpenApiOrganizationGuidPage>(result); vmResult.ItemList.Count.Should().Be(1); }
public void Active_OnlyOnePerRootIdReturned() { var rootId = Guid.NewGuid(); // Let's create two versions for same root channel var publishedItem = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishingStatusCache.Get(PublishingStatus.Published), rootId); publishedItem.UnificRoot = new ServiceChannel { Id = rootId }; var modifiedItem = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishingStatusCache.Get(PublishingStatus.Modified), rootId); modifiedItem.UnificRoot = new ServiceChannel { Id = rootId }; var list = new List <ServiceChannelVersioned> { publishedItem, modifiedItem }; var result = ArrangeAndAct(null, list, 1, 1, false, true); // Assert result.Should().NotBeNull(); result.PageCount.Should().Be(1);// Only one item per root should be found var vmResult = Assert.IsType <V3VmOpenApiGuidPage>(result); vmResult.ItemList.Count.Should().Be(1); }
public void MakeObjectsOnSurface(List <Vector3> points, List <Triangle> triangles, ObjectPlacementDirection placeDir, string pathToObject, EntityGenerator e, int numObjs, int numInCache) { List <Vector3> posns = new List <Vector3>(); List <Quaternion> rots = new List <Quaternion>(); List <int> closestPoints = new List <int>(); for (int i = 0; i < numObjs; i++) { int triangle = r.Next(triangles.Count); Vector3 point = (Vector3.Lerp(points[triangles[triangle].points[0]], points[triangles[triangle].points[1]], (float)r.NextDouble()) + Vector3.Lerp(points[triangles[triangle].points[0]], points[triangles[triangle].points[2]], (float)r.NextDouble())) / 2; int closestPoint = -1; float leastDist = float.MaxValue; for (int i1 = 0; i1 < 3; i1++) { float dist = Vector3.SqrMagnitude(points[triangles[triangle].points[i1]] - point); if (dist < leastDist) { leastDist = dist; closestPoint = triangles[triangle].points[i1]; } } Vector3 forward; if (placeDir == ObjectPlacementDirection.UP) { forward = point.normalized; } else if (placeDir == ObjectPlacementDirection.NORMAL) { forward = triangles[triangle].plane.normal * triangles[triangle].GetDirInt(); } else if (placeDir == ObjectPlacementDirection.RANDOM) { forward = new Vector3((float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f).normalized; } else { throw new Exception("ObjectPlacementDirection parameter is invalid"); } Vector3 randomUp = new Vector3((float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f, (float)r.NextDouble() - 0.5f).normalized; rots.Add(Quaternion.LookRotation(forward, randomUp)); posns.Add(point); closestPoints.Add(closestPoint); } Vector3 scale = ((GameObject)Resources.Load(pathToObject)).transform.localScale; for (int i = 0; i < posns.Count; i++) { e.CreateEntity(posns[i], rots[i], scale, closestPoints[i]); } }
public void ChannelsAttached() { // Arrange var serviceChannel = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishedId); var channelId = serviceChannel.Id; var serviceChannelRepoMock = new Mock <IServiceChannelVersionedRepository>(); serviceChannelRepoMock.Setup(s => s.All()).Returns(new List <ServiceChannelVersioned> { new ServiceChannelVersioned { Id = channelId } }.AsQueryable()); unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceChannelVersionedRepository>()).Returns(serviceChannelRepoMock.Object); _publishedGd.UnificRoot.StatutoryServiceGeneralDescriptionServiceChannels = new List <GeneralDescriptionServiceChannel> { new GeneralDescriptionServiceChannel { ServiceChannel = new ServiceChannel { Versions = new List <ServiceChannelVersioned> { serviceChannel } }, ServiceChannelId = channelId, StatutoryServiceGeneralDescriptionId = _publishedGdId } }; GdRepoMock.Setup(g => g.All()).Returns(_gdList.AsQueryable()); var service = Arrange(); // Act var result = service.GetGeneralDescriptionVersionBase(_publishedGdId, DefaultVersion); // Assert result.Should().NotBeNull(); result.Should().BeOfType <V7VmOpenApiGeneralDescription>(); unitOfWorkMockSetup.Verify(x => x.CreateRepository <IGeneralDescriptionServiceChannelRepository>(), Times.Once()); }
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); }); }