/// <summary> /// Compares the non Collection Properties of the BasicClass /// </summary> /// <param name="expected">The expected values.</param> /// <param name="actual">The Actual values.</param> /// <param name="includeCollections"></param> internal void AssertPropertiesEqual(BasicClass expected, BasicClass actual, bool includeCollections) { Assert.AreEqual(expected.Id, actual.Id, "Id"); Assert.AreEqual(expected.CharacterProperty, actual.CharacterProperty, "CharacterProperty"); Assert.AreEqual(expected.ClassProperty, actual.ClassProperty, "ClassProperty"); Assert.AreEqual(expected.CultureInfoProperty, actual.CultureInfoProperty, "CultureInfoProperty"); Assert.AreEqual(expected.DateTimeProperty, actual.DateTimeProperty, "DateTimeProperty"); Assert.AreEqual(expected.Int16Property, actual.Int16Property, "Int16Property"); Assert.AreEqual(expected.Int32Property, actual.Int32Property, "Int32Property"); Assert.AreEqual(expected.Int64Property, actual.Int64Property, "Int64Property"); Assert.AreEqual(expected.SingleProperty, actual.SingleProperty, 0, "SingleProperty"); Assert.AreEqual(expected.StringProperty, actual.StringProperty, "StringProperty"); Assert.AreEqual(expected.TicksProperty, actual.TicksProperty, "TicksProperty"); Assert.AreEqual(expected.TrueFalseProperty, actual.TrueFalseProperty, "TrueFalseProperty"); Assert.AreEqual(expected.YesNoProperty, actual.YesNoProperty, "YesNoProperty"); if (includeCollections) { ObjectAssert.AreEqual(expected.StringArray, actual.StringArray); ObjectAssert.AreEqual(expected.Int32Array, actual.Int32Array); ObjectAssert.AreEqual(expected.StringBag, actual.StringBag, false); ObjectAssert.AreEqual(expected.StringList, actual.StringList); ObjectAssert.AreEqual(expected.StringMap, actual.StringMap, true); ObjectAssert.AreEqual(expected.StringSet, actual.StringSet); } }
public async Task ThenItShouldCallSquashManagerAndReturnFailedDependencyAllAdaptersFail() { var request = _fixture.Create <SquashRequest>(); _squashManagerMock.Setup(m => m.SquashAsync(It.IsAny <SquashRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new SquashResponse { SquashedEntityResults = new[] { new SquashedEntityResult { EntityAdapterErrorDetails = new[] { new EntityAdapterErrorDetail(), } }, }, }); var actual = await _function.RunAsync(GetRequest(request), _cancellationToken); Assert.IsNotNull(actual); Assert.IsInstanceOf <HttpErrorBodyResult>(actual); Assert.AreEqual((int)HttpStatusCode.FailedDependency, ((HttpErrorBodyResult)actual).StatusCode); _squashManagerMock.Verify(m => m.SquashAsync( It.Is <SquashRequest>(r => ObjectAssert.AreEqual(request, r)), _cancellationToken), Times.Once); }
public void ReadWrite() { BinaryClass bcBinary = Create(1); BinaryClass expected = Create(1); ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); s.Save(bcBinary); t.Commit(); s.Close(); s = OpenSession(); t = s.BeginTransaction(); bcBinary = (BinaryClass)s.Load(typeof(BinaryClass), 1); // make sure what was saved was expected ObjectAssert.AreEqual(expected.DefaultSize, bcBinary.DefaultSize); ObjectAssert.AreEqual(expected.WithSize, bcBinary.WithSize); Assert.IsFalse(s.IsDirty(), "The session is dirty: an Update will be raised on commit, See NH-1246"); s.Delete(bcBinary); t.Commit(); s.Close(); }
public async Task ThenItShouldCallSquashManagerAndReturnPartialContentIfRequestHasSomeResultsAndSomeErrorsProcessed() { var request = _fixture.Create <SquashRequest>(); _squashManagerMock.Setup(m => m.SquashAsync(It.IsAny <SquashRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new SquashResponse { SquashedEntityResults = new[] { new SquashedEntityResult { SquashedEntity = new LearningProvider(), EntityAdapterErrorDetails = new[] { new EntityAdapterErrorDetail(), } }, }, }); var actual = await _function.RunAsync(GetRequest(request), _cancellationToken); Assert.IsNotNull(actual); Assert.IsInstanceOf <FormattedJsonResult>(actual); Assert.AreEqual(HttpStatusCode.PartialContent, ((FormattedJsonResult)actual).StatusCode); _squashManagerMock.Verify(m => m.SquashAsync( It.Is <SquashRequest>(r => ObjectAssert.AreEqual(request, r)), _cancellationToken), Times.Once); }
public async Task ThenItShouldDeserializeAndProcessTheQueueItem(SyncQueueItem syncQueueItem) { await _function.RunAsync(GetQueueMessage(syncQueueItem), _cancellationToken); _syncManagerMock.Verify(m => m.ProcessSyncQueueItemAsync( It.Is <SyncQueueItem>(actualQueueItem => ObjectAssert.AreEqual(syncQueueItem, actualQueueItem)), _cancellationToken), Times.Once); }
public void UnQuoteArray() { string[] actualUnquoted = new string[2]; string[] expectedUnquoted = new string[] { tableThatNeedsToBeQuoted[AfterUnquoteIndex], tableAlreadyQuoted[AfterUnquoteIndex] }; actualUnquoted = d.UnQuote(new string[] { tableThatNeedsToBeQuoted[BeforeQuoteIndex], tableAlreadyQuoted[BeforeQuoteIndex] }); ObjectAssert.AreEqual(expectedUnquoted, actualUnquoted, true); }
public void ThenItShouldParseProvidersFromResponse(Provider provider1, Provider provider2) { var deserializer = new ResponseDeserializer(); var response = GetQueryResponse(provider1, provider2); var actual = deserializer.DeserializeResponse(response); Assert.IsNotNull(actual); Assert.AreEqual(2, actual.Length); ObjectAssert.AreEqual(provider1, actual[0]); ObjectAssert.AreEqual(provider2, actual[1]); }
public async Task ThenItShouldCallSquashManagerAndReturnOkIfRequestFullyProcessed() { var request = _fixture.Create <SquashRequest>(); var actual = await _function.RunAsync(GetRequest(request), _cancellationToken); Assert.IsNotNull(actual); Assert.IsInstanceOf <FormattedJsonResult>(actual); Assert.AreEqual(HttpStatusCode.OK, ((FormattedJsonResult)actual).StatusCode); _squashManagerMock.Verify(m => m.SquashAsync( It.Is <SquashRequest>(r => ObjectAssert.AreEqual(request, r)), _cancellationToken), Times.Once); }
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 ReadWriteLargeBlobAsync() { ISession s = OpenSession(); BinaryBlobClass b = new BinaryBlobClass(); b.BinaryBlob = UnicodeEncoding.UTF8.GetBytes(new string('T', 10000)); await(s.SaveAsync(b)); await(s.FlushAsync()); s.Close(); s = OpenSession(); b = (BinaryBlobClass)await(s.LoadAsync(typeof(BinaryBlobClass), b.Id)); ObjectAssert.AreEqual(UnicodeEncoding.UTF8.GetBytes(new string('T', 10000)), b.BinaryBlob); await(s.DeleteAsync(b)); await(s.FlushAsync()); 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); }
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); }
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); }