static void Configure() { Xyperico.Base.MongoDB.Utility.Initialize(); Peach.Profiles.Query.MongoDB.Utility.Initialize(Xyperico.Base.ObjectContainer.Container); ConfigureContainer(Xyperico.Base.ObjectContainer.Container); Builder = Xyperico.Base.ObjectContainer.Container.Instantiate<TestDataBuilder>(); }
public void Match_SubfolderFactMatchSingleSnapshot_OneFieldNotEqual() { // arrange TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().WithAge(5).Build(); // act Action match = () => Snapshot.Match <TestPerson>(testPerson); // assert Assert.Throws <EqualException>(match); }
public void Match_FactMatchSingleSnapshot_GoodCase() { // arrange string snapshotName = nameof(SnapshotTests) + "." + nameof(Match_FactMatchSingleSnapshot_GoodCase); TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build(); // act & assert Snapshot.Match <TestPerson>(testPerson, snapshotName); }
public async Task should_get_self_handled_messages() { _bus.AddHandler <RegisterPeerCommand>(x => new RegisterPeerResponse(new PeerDescriptor[0])); var subscriptions = TestDataBuilder.CreateSubscriptions <FakeCommand>(); await _directory.RegisterAsync(_bus, _self, subscriptions).ConfigureAwait(true); var peerHandlingMessage = _directory.GetPeersHandlingMessage(new FakeCommand(0)).Single(); peerHandlingMessage.Id.ShouldEqual(_self.Id); }
public void Match_TestCaseMatchSingleSnapshot_OneFieldNotEqual(int age, decimal size) { // arrange TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton() .WithAge(age).WithSize(size).Build(); testPerson.Address.Country.CountryCode = CountryCode.DE; // act & assert Assert.Throws <AssertionException>(() => Snapshot.Match(testPerson)); }
public void should_throw_if_a_client_with_a_more_recent_clock_tries_to_register() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); var registerCommand = new RegisterPeerCommand(peerDescriptor); registerCommand.Peer.TimestampUtc = SystemDateTime.UtcNow + 1.Hour(); _configurationMock.SetupGet(x => x.MaxAllowedClockDifferenceWhenRegistering).Returns(15.Minutes()); var exception = Assert.Throws <InvalidOperationException>(() => _handler.Handle(registerCommand)); exception.Message.ShouldContain("is too far ahead of the the server's current time"); }
public void Match_TheoryMatchSingleSnapshot_OneFieldNotEqual(int age, decimal size) { // arrange TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton() .WithAge(age).WithSize(size).Build(); testPerson.Address.Country.CountryCode = CountryCode.US; // act & assert Assert.Throws <EqualException>(() => Snapshot.Match <TestPerson>( testPerson, SnapshotNameExtension.Create(age, size))); }
public void Match_AssertScalarNullIntegerFieldWithNull_SuccessfulMatch() { // arrange TestPerson testChild = TestDataBuilder.TestPersonMarkWalton() .WithAge(null) .Build(); // act & assert Snapshot.Match <TestPerson>(testChild, matchOption => matchOption.Assert(fieldOption => Assert.Null(fieldOption.Field <int?>("Age")))); }
public void Match_AssertScalarStringFieldToIntegerParseFailure_ThrowsSnapshotFieldException() { // arrange TestPerson testChild = TestDataBuilder.TestPersonMarkWalton() .Build(); // act & assert Assert.Throws <SnapshotFieldException>( () => Snapshot.Match <TestPerson>(testChild, matchOption => matchOption.Assert(fieldOption => Assert.Equal(22, fieldOption.Field <int>("Firstname"))))); }
public void Match_AssertScalarStringFieldToInteger_SuccessfulMatch() { // arrange TestPerson testChild = TestDataBuilder.TestPersonMarkWalton() .WithFirstname(22.ToString()) .Build(); // act & assert Snapshot.Match <TestPerson>(testChild, matchOption => matchOption.Assert(fieldOption => Assert.Equal(22, fieldOption.Field <int>("Firstname")))); }
public void Match_AssertScalarStringFieldUnequal_ThrowsSnapshotCompareException() { // arrange TestPerson testChild = TestDataBuilder.TestPersonMarkWalton() .Build(); // act & assert Assert.Throws <SnapshotCompareException>(() => Snapshot.Match <TestPerson>(testChild, matchOption => matchOption.Assert(fieldOption => Assert.Equal("Anna", fieldOption.Field <string>("Children[2].Name"))))); }
public void Match_AssertScalarGuidNullField_SuccessfulMatch() { // arrange TestPerson testPerson = TestDataBuilder.TestPersonSandraSchneider() .WithId(null) .Build(); // act & assert Snapshot.Match <TestPerson>(testPerson, matchOption => matchOption.Assert( fieldOption => Assert.Null(fieldOption.Field <Guid?>("Id")))); }
public void Match_AssertScalarGuidFieldNotMatch_ThrowsSnapshotCompareException() { // arrange TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build(); // act & assert Assert.Throws <SnapshotCompareException>( () => Snapshot.Match <TestPerson>(testPerson, matchOption => matchOption.Assert( fieldOption => Assert.Equal(fieldOption.Field <Guid>("Id"), Guid.Parse("fcf04ca6-d8f2-4214-a3ff-d0ded5bad4de"))))); }
public void Match_IgnoreComplexObjectField_SuccessfulIgnored() { // arrange TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton() .Build(); testPerson.Address = null; // act & assert Snapshot.Match <TestPerson>( testPerson, matchOptions => matchOptions.IgnoreField <object>("Address")); }
public void Match_IsTypeScalarFieldDateTime_SuccessfulMatch() { // arrange string snapshotName = nameof(SnapshotTests) + "." + nameof(Match_IsTypeScalarFieldDateTime_SuccessfulMatch); TestPerson testPerson = TestDataBuilder.TestPersonSandraSchneider().Build(); // act & assert Snapshot.Match(testPerson, snapshotName, matchOptions => matchOptions.IsTypeField <DateTime>("CreationDate")); }
public void should_throw_if_an_existing_peer_tries_to_register() { var existingPeer = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://existingpeer:123", typeof(FakeCommand)); _repositoryMock.Setup(x => x.Get(existingPeer.PeerId)).Returns(existingPeer); var newPeer = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://newpeer:123", typeof(FakeCommand)); var command = new RegisterPeerCommand(newPeer); var exception = (DomainException)typeof(DomainException).ShouldBeThrownBy(() => _handler.Handle(command)); exception.ErrorCode.ShouldEqual(DirectoryErrorCodes.PeerAlreadyExists); }
public void Test_GetNumericRowVector_ByRowName() { // Given var dataFrame = TestDataBuilder.BuildSmallDataFrameNumbersOnly(); var expectedNumericColumnVector = Vector <double> .Build.Dense(new double[] { 1, 2, 3, 4 }); // When var actualNumericColumnVector = dataFrame.GetNumericRowVector(100, true); // Then Assert.IsTrue(expectedNumericColumnVector.Equals(actualNumericColumnVector)); }
public async Task Batch() { await TestDataBuilder.SendMultipleDataAsync(table); var consumer = new QueueManager(table, SqlConnection); var messages = new ConcurrentBag <IncomingVerifyTarget>(); var result = await consumer.Consume( size : 3, action : message => { messages.Add(message.ToVerifyTarget()); }); Assert.Equal(3, result.Count); }
public void should_persist_responding_peer() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); _handler.Handle(new MarkPeerAsRespondingCommand(peerDescriptor.PeerId, SystemDateTime.UtcNow)); _repositoryMock.Verify(x => x.SetPeerResponding(peerDescriptor.PeerId, true)); var respondingEvent = _bus.Events.OfType <PeerResponding>().ExpectedSingle(); respondingEvent.PeerId.ShouldEqual(peerDescriptor.PeerId); }
public void should_specify_datetime_kind_when_removing_all_subscriptions_for_a_peer_during_register() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); peerDescriptor.TimestampUtc = new DateTime(DateTime.Now.Ticks, DateTimeKind.Unspecified); var registerCommand = new RegisterPeerCommand(peerDescriptor); _handler.Handle(registerCommand); _repositoryMock.Verify(x => x.AddOrUpdatePeer(registerCommand.Peer)); _repositoryMock.Verify(x => x.RemoveAllDynamicSubscriptionsForPeer(registerCommand.Peer.PeerId, It.Is <DateTime>(d => d.Kind == DateTimeKind.Utc))); }
public void Test_RegressionWith_BackwardsEliminationKnnModel() { // Given var randomizer = new Random(55); var baseDataFrame = TestDataBuilder.BuildRandomAbstractNumericDataFrameWithRedundantAttrs(randomizer: randomizer, rowCount: 1000); var queryDataFrame = new DataFrame(new DataTable("some data") { Columns = { new DataColumn("F1", typeof(double)), new DataColumn("F2", typeof(double)), new DataColumn("F3", typeof(double)), new DataColumn("F4", typeof(double)), new DataColumn("F5", typeof(double)) }, Rows = { new object[] { 10, 1, 1, 4, 5 }, new object[] { 4, 2, 1, 9, 10 }, new object[] { 2, 1, 1, 3, 7 }, } }); var expectedValues = Enumerable.Range(0, queryDataFrame.RowCount) .Select( rowIdx => TestDataBuilder.CalcualteLinearlyDependentFeatureValue(queryDataFrame.GetNumericRowVector(rowIdx))).ToList(); var weightingFunction = new GaussianFunction(0.07); var predictor = new SimpleKnnRegressor( new EuclideanDistanceMeasure(), new MinMaxNormalizer(), weightingFunction.GetValue); var modelBuilder = new BackwardsEliminationKnnModelBuilder <double>( new MinMaxNormalizer(), predictor, new MeanSquareError() ); var modelParams = new KnnAdditionalParams(3, true); var errorMeasure = new MeanSquareError(); var subject = new BackwardsEliminationKnnRegressor( new EuclideanDistanceMeasure(), new MinMaxNormalizer(), weightingFunction.GetValue); // When var model = modelBuilder.BuildModel(baseDataFrame, "F6", modelParams); var actualOutcomes = subject.Predict(queryDataFrame, model, "F6"); var mse = errorMeasure.CalculateError(Vector <double> .Build.DenseOfEnumerable(expectedValues), Vector <double> .Build.DenseOfEnumerable(actualOutcomes)); Assert.IsTrue(mse < 0.35); }
public void should_not_register_existing_peer() { var subscriptions = TestDataBuilder.CreateSubscriptions <FakeCommand>(); _configurationMock.SetupGet(x => x.IsPersistent).Returns(true); _bus.AddHandler <RegisterPeerCommand>(x => throw new DomainException(DirectoryErrorCodes.PeerAlreadyExists, "Peer already exists")); using (SystemDateTime.PauseTime()) { Assert.Throws <AggregateException>(() => _directory.RegisterAsync(_bus, _self, subscriptions).Wait(20.Seconds())) .InnerException.ShouldBe <TimeoutException>(); } }
protected Portal GetOrCreatePortal() { var portal = Session.Query <Portal>() .SingleOrDefault(); if (portal == null) { portal = TestDataBuilder.NewPortal(GetOrCreateUser("admin")); Session.Save(portal); Session.Flush(); } return(portal); }
public async Task Match_FactAsyncSingleSnapshot_SuccessfulMatch() { // arrange await Task.Delay(1); TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build(); // act Snapshot.Match <TestPerson>(testPerson); // assert await Task.Delay(1); }
public void GetValuesForRows() { // Given var baseDataFrame = TestDataBuilder.ReadWeatherDataWithCategoricalAttributes(); var expectedValues = new[] { "Yes", "Yes", "No" }; var queryRows = new[] { 11, 12, 13 }; // When var actualValues = baseDataFrame.GetValuesForRows <string>(queryRows, "Play"); // Then CollectionAssert.AreEquivalent(expectedValues, actualValues); }
public async Task Batch_all() { await TestDataBuilder.SendMultipleDataAsync(table); var reader = new QueueManager(table, SqlConnection); var messages = new ConcurrentBag <IncomingVerifyTarget>(); await reader.Read( size : 10, startRowVersion : 1, action : message => { messages.Add(message.ToVerifyTarget()); }); await Verify(messages.OrderBy(x => x.Id)); }
public void should_set_registering_peer_up_and_responding() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); peerDescriptor.Peer.IsUp = false; peerDescriptor.Peer.IsResponding = false; var registerCommand = new RegisterPeerCommand(peerDescriptor); _handler.Handle(registerCommand); _repositoryMock.Verify(x => x.AddOrUpdatePeer(It.Is <PeerDescriptor>(p => p.Peer.IsUp && p.Peer.IsResponding))); }
public void should_not_unregister_a_peer_that_started_after_timestamp() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); _repositoryMock.Setup(x => x.Get(peerDescriptor.PeerId)).Returns(peerDescriptor); var command = new UnregisterPeerCommand(peerDescriptor.Peer, peerDescriptor.TimestampUtc.Value.AddSeconds(-2)); _handler.Handle(command); _repositoryMock.Verify(x => x.AddOrUpdatePeer(It.IsAny <PeerDescriptor>()), Times.Never()); _bus.ExpectNothing(); }
public void should_publish_stopped_event_when_unregistering_a_persistent_client() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); peerDescriptor.TimestampUtc = SystemDateTime.UtcNow.AddSeconds(-30); _repositoryMock.Setup(x => x.Get(peerDescriptor.Peer.Id)).Returns(peerDescriptor); var command = new UnregisterPeerCommand(peerDescriptor.Peer, SystemDateTime.UtcNow.AddSeconds(-2)); _handler.Handle(command); _bus.ExpectExactly(new PeerStopped(peerDescriptor.Peer, command.TimestampUtc)); }
public void should_unregister_persistent_peer_when_unregistering() { var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand)); peerDescriptor.TimestampUtc = SystemDateTime.UtcNow.AddSeconds(-30); _repositoryMock.Setup(x => x.Get(peerDescriptor.Peer.Id)).Returns(peerDescriptor); var command = new UnregisterPeerCommand(peerDescriptor.Peer); _handler.Handle(command); _repositoryMock.Verify(x => x.AddOrUpdatePeer(It.Is <PeerDescriptor>(peer => peer.Peer.Id == peerDescriptor.Peer.Id && peer.Peer.IsUp == false && peer.TimestampUtc == command.TimestampUtc))); }
public void should_not_throw_if_an_existing_peer_is_on_the_same_host() { var existingPeer = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://existingpeer:123", typeof(FakeCommand)); existingPeer.Peer.IsResponding = false; _repositoryMock.Setup(x => x.GetPeers(It.IsAny <bool>())).Returns(new[] { existingPeer }); var newPeer = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://existingpeer:123", typeof(FakeCommand)); var command = new RegisterPeerCommand(newPeer); _handler.Handle(command); _repositoryMock.Verify(x => x.AddOrUpdatePeer(newPeer)); }