Ejemplo n.º 1
0
        public void ReadWriteLargeBlob()
        {
            ISession        s = OpenSession();
            BinaryBlobClass b = new BinaryBlobClass();

            b.BinaryBlob = UnicodeEncoding.UTF8.GetBytes(new string('T', 10000));
            s.Save(b);
            s.Flush();
            s.Close();

            s = OpenSession();
            b = (BinaryBlobClass)s.Load(typeof(BinaryBlobClass), b.Id);
            ObjectAssert.AreEqual(UnicodeEncoding.UTF8.GetBytes(new string('T', 10000)), b.BinaryBlob);
            s.Delete(b);
            s.Flush();
            s.Close();
        }
        public async Task ThenItShouldStoreNewMatchedEntity(SyncQueueItem queueItem, Entity synonymEntity)
        {
            synonymEntity.EntityType = queueItem.Entity.EntityType;
            _matcherMock.Setup(m => m.MatchAsync(It.IsAny <Entity>(), It.IsAny <DateTime>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new MatchResult
            {
                Synonyms = new[]
                {
                    new MatchResultItem
                    {
                        MatchReason      = "Matched for testing",
                        RegisteredEntity = new RegisteredEntity
                        {
                            Id        = "other-entity",
                            Type      = queueItem.Entity.EntityType,
                            ValidFrom = queueItem.PointInTime,
                            Entities  = new[]
                            {
                                CloneLinkedEntity(synonymEntity)
                            }
                        }
                    },
                },
                Links = new MatchResultLink[0],
            });

            await _syncManager.ProcessSyncQueueItemAsync(queueItem, _cancellationToken);

            _repositoryMock.Verify(r => r.StoreAsync(
                                       It.Is <RegisteredEntity[]>(entitiesToUpdate =>
                                                                  entitiesToUpdate.Length == 1 &&
                                                                  entitiesToUpdate[0].Type == queueItem.Entity.EntityType &&
                                                                  entitiesToUpdate[0].ValidFrom == queueItem.PointInTime &&
                                                                  !entitiesToUpdate[0].ValidTo.HasValue &&
                                                                  entitiesToUpdate[0].Entities != null &&
                                                                  entitiesToUpdate[0].Entities.Length == 2 &&
                                                                  ObjectAssert.AreEqual(queueItem.Entity, entitiesToUpdate[0].Entities[0]) &&
                                                                  ObjectAssert.AreEqual(synonymEntity, entitiesToUpdate[0].Entities[1]) &&
                                                                  entitiesToUpdate[0].Links != null &&
                                                                  entitiesToUpdate[0].Links.Length == 0),
                                       It.IsAny <RegisteredEntity[]>(),
                                       _cancellationToken),
                                   Times.Once);
        }
        public async Task ThenItShouldStoreNewUnmatchedEntity(SyncQueueItem queueItem)
        {
            await _syncManager.ProcessSyncQueueItemAsync(queueItem, _cancellationToken);

            _repositoryMock.Verify(r => r.StoreAsync(
                                       It.Is <RegisteredEntity[]>(entitiesToUpdate =>
                                                                  entitiesToUpdate.Length == 1 &&
                                                                  entitiesToUpdate[0].Type == queueItem.Entity.EntityType &&
                                                                  entitiesToUpdate[0].ValidFrom == queueItem.PointInTime &&
                                                                  !entitiesToUpdate[0].ValidTo.HasValue &&
                                                                  entitiesToUpdate[0].Entities != null &&
                                                                  entitiesToUpdate[0].Entities.Length == 1 &&
                                                                  ObjectAssert.AreEqual(queueItem.Entity, entitiesToUpdate[0].Entities[0]) &&
                                                                  entitiesToUpdate[0].Links != null &&
                                                                  entitiesToUpdate[0].Links.Length == 0),
                                       It.Is <RegisteredEntity[]>(entitiesToDelete =>
                                                                  entitiesToDelete.Length == 0),
                                       _cancellationToken),
                                   Times.Once);
        }
        private static bool AreEqual <T>(T[] expected, T[] actual)
        {
            if (expected == null && actual == null)
            {
                return(true);
            }

            if (expected?.Length != actual?.Length)
            {
                return(false);
            }

            for (var i = 0; i < expected.Length; i++)
            {
                if (!ObjectAssert.AreEqual(expected[i], actual[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public async Task GetPagedListTModelAsync_Success(QueryParameters <FakeEntity, int> queryParameters, IQueryable <FakeEntity> queryable, IQueryable <FakeEntity> countQueryable)
        {
            ValidateQueryParametersMemberData(queryable, countQueryable);

            if (queryParameters?.Page == null || queryParameters.Page.IsValid == false)
            {
                return;
            }

            // Arrange
            var pagedResultQuery = _fixture.UnitOfWork.FakeEntityRepository.ProtectedPagedResultQuery <FakeModel>(_fixture.DataMapper, queryParameters);

            var expectedPagedResult = new PagedResult <FakeModel>
            {
                PageIndex  = queryParameters.Page.Index,
                PageSize   = queryParameters.Page.Size,
                Items      = pagedResultQuery.ToList(),
                TotalCount = _fixture.UnitOfWork.FakeEntityRepository.Count(queryParameters)
            };

            // Act & Assert
            ObjectAssert.ValueEquals(expectedPagedResult, await _fixture.UnitOfWork.FakeEntityRepository.GetPagedListAsync <FakeModel>(_fixture.DataMapper, queryParameters));
        }
        public async Task ThenItShouldStoreNewVersionOfEntitiesThatAreNewlyLinked(SyncQueueItem queueItem, RegisteredEntity linkedEntity)
        {
            _matcherMock.Setup(m => m.MatchAsync(It.IsAny <Entity>(), It.IsAny <DateTime>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(
                new MatchResult
            {
                Synonyms = new MatchResultItem[0],
                Links    = new[]
                {
                    new MatchResultLink
                    {
                        RegisteredEntity = linkedEntity,
                        Entity           = linkedEntity.Entities[0],
                        LinkType         = "test",
                        MatchReason      = "Linked for testing",
                    },
                },
            });

            await _syncManager.ProcessSyncQueueItemAsync(queueItem, _cancellationToken);

            _repositoryMock.Verify(r => r.StoreAsync(
                                       It.Is <RegisteredEntity[]>(entitiesToUpdate =>
                                                                  entitiesToUpdate.Count(update => update.Entities.Any(entity => ObjectAssert.AreEqual(queueItem.Entity, entity))) == 1 &&
                                                                  entitiesToUpdate.Count(update => AreEqual(linkedEntity.Entities, update.Entities) && update.Id != linkedEntity.Id) == 1 &&
                                                                  entitiesToUpdate.Count(update => update.Links.Count(link => link.LinkType == "test") == 1) == 2),
                                       It.IsAny <RegisteredEntity[]>(),
                                       _cancellationToken),
                                   Times.Once);
        }
Ejemplo n.º 7
0
 public void ValueEquals_Success(object expected, object actual)
 {
     // Arrange & Act & Assert
     ObjectAssert.DeepEquals(expected, actual);
 }
Ejemplo n.º 8
0
        public async Task ThenItShouldSyncUsingTheDeserialisedManagementGroupEvent(SyncEntityEvent <ManagementGroup> @event, string sourceSystemName)
        {
            var request = HttpRequestBuilder
                          .CreateHttpRequest()
                          .WithJsonBody(@event);

            await _function.RunAsync(request, EntityNameTranslator.ManagementGroupPlural, sourceSystemName, _cancellationToken);

            _syncManagerMock.Verify(m => m.ReceiveSyncEntityAsync(
                                        It.Is <SyncEntityEvent <ManagementGroup> >(actual => ObjectAssert.AreEqual(@event, actual)),
                                        sourceSystemName,
                                        _cancellationToken),
                                    Times.Once);
        }