internal static async void VerifyConnectionIsDuplexed( IConnection child, IConnection parent, CancellationTokenSource cancel, MockChannel childSideChannel, MockChannel parentSideChannel, TaskCompletionSource <bool> task) { await Task.Yield(); try { var rnd = new Random(); for (var index = 0; index < 1000 && !cancel.IsCancellationRequested; index++) { await Task.Yield(); Thread.SpinWait(rnd.Next(1, 1000)); if (cancel.IsCancellationRequested) { break; } await VerifyConnectionIsDuplexed(child, parent, cancel, childSideChannel, parentSideChannel).ConfigureAwait(false); } task.TrySetResult(true); } catch (Exception error) { task.TrySetException(error); } }
public IChannel <T> GetChannel <T>(string channelName) { var channel = new MockChannel <T>(channelName); CreatedChannels[channelName] = channel; return(channel); }
public void SendOneSimpleMessage() { var mock = new MockChannel("doi"); var participant = new Participant(mock); participant.Send(new Message("unu")); Assert.True(mock.CheckWriteMessage("unu\0")); }
public void Mock_ReadAllMessage() { var bytes = new byte[10]; var mock = new MockChannel("ana are", "asdf", "razvan"); Assert.Equal(7, mock.Read(bytes, 0, 7)); Assert.Equal(4, mock.Read(bytes, 0, 4)); Assert.Equal(6, mock.Read(bytes, 0, 6)); }
public async Task TitleIsSetProperly() { var mockChannel = new MockChannel(1, "1.0"); mockChannel.SetArtifactUrl("artifact_url"); await _sut.StartAsync(mockChannel, "dest_path"); Assert.AreEqual("Downloading Magpie.Tests Updates...", _sut.Title); }
public void Mock_ReadAPartOfMessage() { var bytes = new byte[50]; var mock = new MockChannel("ana are mere", "tenis de camp", "razvan si dani"); Assert.Equal(3, mock.Read(bytes, 4, 3)); Assert.Equal(5, mock.Read(bytes, 0, 5)); Assert.Equal(4, mock.Read(bytes, 10, 4)); }
public void SetUp() { client = new AssertionFlowClient( GoogleAuthenticationServer.Description, new X509Certificate2(@"test-key.p12", "notasecret", X509KeyStorageFlags.Exportable)) { Scope = Scope, ServiceAccountId = ServiceAccountId }; state = new AuthorizationState(client.Scope.Split(' ')); channel = new MockChannel() { ResponseMessage = new AssertionFlowMessage(GoogleAuthenticationServer.Description) }; }
public void Initialize() { var debuggingInfoLogger = Substitute.For <IDebuggingInfoLogger>(); _analyticsLogger = Substitute.For <IAnalyticsLogger>(); var remoteContentDownloader = Substitute.For <IRemoteContentDownloader>(); var appInfo = new AppInfo("valid_url"); _channel = new MockChannel(1, "1.0"); AssemblyInjector.Inject(); _mainWindowViewModel = new MockMainWindowViewModel(appInfo, debuggingInfoLogger, remoteContentDownloader, _analyticsLogger); }
public async Task StartAsyncStartsDownloadingFile() { var mockChannel = new MockChannel(1, "1.0"); mockChannel.SetArtifactUrl("artifact_url"); _remoteContentDownloader.DownloadFile("artifact_url", "dest_path", Arg.Any <Action <int> >(), Arg.Any <IDebuggingInfoLogger>()).Returns("saved_dest_path"); var savedAt = await _sut.StartAsync(mockChannel, "dest_path"); await _remoteContentDownloader.Received().DownloadFile("artifact_url", "dest_path", Arg.Any <Action <int> >(), Arg.Any <IDebuggingInfoLogger>()); Assert.AreEqual("saved_dest_path", savedAt); }
public void TestChannelInitialize() { //test may not be doable once initialize is done Channel testChannel = new MockChannel(CHANNEL_NAME, hfclient); Peer peer = hfclient.NewPeer("peer_", "grpc://localhost:7051"); testChannel.AddPeer(peer, PeerOptions.CreatePeerOptions().SetPeerRoles(PeerRole.ENDORSING_PEER)); Assert.IsFalse(testChannel.IsInitialized); testChannel.Initialize(); Assert.IsTrue(testChannel.IsInitialized); }
public void PropertiesAreInitializedCorrectly() { var channel = new MockChannel(1, build: "Test Build", enrollmentEula: "www.example.com"); var enrollment = new Enrollment(channel); var appInfo = new AppInfo("testString") { AppIconPath = "iconPath" }; var sut = new EnrollmentViewModel(enrollment, appInfo); Assert.AreEqual("Test Build", sut.ChannelName); Assert.AreEqual("www.example.com", sut.EnrollmentEulaUrl); Assert.AreEqual("iconPath", sut.AppIconPath); }
public void LeaveParticipant() { var firstMock = new MockChannel("dan"); var secondMock = new MockChannel("mirel"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); room.Leave(secondParticipant); room.Broadcast(new Message("ion")); Assert.True(firstMock.CheckWriteMessage("ion\0")); Assert.Throws <InvalidOperationException> (() => secondMock.CheckWriteMessage("ion\0")); }
public void ParticipantIsRemovedFromRoomWhenHeClosedTheConnection() { var firstMock = new MockChannel("mare\0", "nisip\0"); var secondMock = new MockChannel("doi\0"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); secondParticipant.Receive(); Assert.Throws <CantReadException>(() => secondParticipant.Receive()); room.Broadcast(new Message("dan")); Assert.Throws <InvalidOperationException> (() => secondMock.CheckWriteMessage("dan\0")); Assert.True(firstMock.CheckWriteMessage("dan\0")); }
public async Task UpdatesProgressWhenDownloading() { var mockChannel = new MockChannel(1, "1.0"); mockChannel.SetArtifactUrl("artifact_url"); _remoteContentDownloader.DownloadFile("artifact_url", "dest_path", Arg.Do <Action <int> >(a => { a(50); a(75); }), Arg.Any <IDebuggingInfoLogger>()) .Returns("saved_dest_path"); await _sut.StartAsync(mockChannel, "dest_path"); Assert.AreEqual(75, _sut.ProgressPercent); }
public void ParticipantCantJoinBecauseNicknameAlreadyExistInRoom() { var mock = new MockChannel("ion\0"); var firstParticipant = new Participant(mock); var secondParticipant = new Participant(mock); var thirdParticipant = new Participant(mock); firstParticipant.Nickname = "alex"; secondParticipant.Nickname = "dan"; thirdParticipant.Nickname = "alex"; var room = new Room(); Assert.True(room.Join(firstParticipant)); Assert.True(room.Join(secondParticipant)); Assert.False(room.Join(thirdParticipant)); }
public void BroadcastMessage() { var firstMock = new MockChannel("ana"); var secondMock = new MockChannel("are"); var firstParticipant = new Participant(firstMock); var secondParticipant = new Participant(secondMock); firstParticipant.Nickname = "a"; secondParticipant.Nickname = "b"; var room = new Room(); room.Join(firstParticipant); room.Join(secondParticipant); room.Broadcast(new Message("mere")); Assert.True(firstMock.CheckWriteMessage("b has joined\0")); Assert.True(secondMock.CheckWriteMessage("mere\0")); }
internal static async Task VerifyConnectionIsDuplexed( IConnection child, IConnection parent, CancellationTokenSource cancel, MockChannel childSideChannel, MockChannel parentSideChannel) { //send additional data from the parent across the channel var data = Guid.NewGuid(); var dataCopy = new byte[16]; parent.Write(parentSideChannel.Id, new MemoryStream(data.ToByteArray())); Assert.AreEqual(dataCopy.Length, await childSideChannel.Buffer.ReadAsync(dataCopy, 0, 16, cancel.Token).ConfigureAwait(false)); Assert.AreEqual(data, new Guid(dataCopy.ToArray())); //send additional data from the child across the channel data = Guid.NewGuid(); child.Write(childSideChannel.Id, new MemoryStream(data.ToByteArray())); Assert.AreEqual(dataCopy.Length, await parentSideChannel.Buffer.ReadAsync(dataCopy, 0, 16, cancel.Token).ConfigureAwait(false)); Assert.AreEqual(data, new Guid(dataCopy.ToArray())); }
public void Test_FlushChannelMessages() { TestMessage1 msg1 = new TestMessage1(); msg1.Data.Add(100); msg1.Data.Add(200); string channel1Name = "TestChannel1"; TestMessage2 msg2 = new TestMessage2(); msg2.Data.Add(1000); msg2.Data.Add(2000); string channel2Name = "TestChannel2"; // Setup the mocks MockDistributedMemoryManager distributedMemoryManagerMock = new MockDistributedMemoryManager(); DeferredChannelMessageContextEntry entry = new DeferredChannelMessageContextEntry(distributedMemoryManagerMock); entry.AddOrUpdateMessage(channel1Name, msg1, null); entry.AddOrUpdateMessage(channel2Name, msg2, null); entry.FlushMessages(); TestMessage1 msg1Out; TestMessage2 msg2Out; Assert.IsFalse(entry.TryGetMessage(channel1Name, out msg1Out), "Channel1 should have no messages"); Assert.IsFalse(entry.TryGetMessage(channel2Name, out msg2Out), "Channel2 should have no messages"); // Validation MockChannel <TestMessage1> channel1 = distributedMemoryManagerMock.CreatedChannels[channel1Name] as MockChannel <TestMessage1>; Assert.IsNotNull(channel1, "{0} was not found", channel1Name); Assert.AreEqual(1, channel1.PublishedMessages.Count); Assert.AreSame(msg1, channel1.PublishedMessages[0]); MockChannel <TestMessage2> channel2 = distributedMemoryManagerMock.CreatedChannels[channel2Name] as MockChannel <TestMessage2>; Assert.IsNotNull(channel2, "{0} was not found", channel2Name); Assert.AreEqual(1, channel2.PublishedMessages.Count); Assert.AreSame(msg2, channel2.PublishedMessages[0]); }
public void Test_AddOrUpdateMessage_Merge_FlushChannelMessages() { TestMessage1 msg11 = new TestMessage1(); msg11.Data.Add(100); msg11.Data.Add(200); TestMessage1 msg12 = new TestMessage1(); msg12.Data.Add(300); msg12.Data.Add(400); string channel1Name = "TestChannel1"; TestMessage2 msg21 = new TestMessage2(); msg21.Data.Add(1000); msg21.Data.Add(2000); TestMessage2 msg22 = new TestMessage2(); msg22.Data.Add(3000); msg22.Data.Add(4000); msg22.Data.Add(5000); string channel2Name = "TestChannel2"; // Setup the mocks MockDistributedMemoryManager distributedMemoryManagerMock = new MockDistributedMemoryManager(); DeferredChannelMessageContextEntry entry = new DeferredChannelMessageContextEntry(distributedMemoryManagerMock); entry.AddOrUpdateMessage(channel1Name, msg11, (e, n) => e.Data.UnionWith(n.Data)); entry.AddOrUpdateMessage(channel1Name, msg12, (e, n) => e.Data.UnionWith(n.Data)); // This will merge entry.AddOrUpdateMessage(channel2Name, msg21, (e, n) => e.Data.UnionWith(n.Data)); entry.AddOrUpdateMessage(channel2Name, msg22, (e, n) => e.Data.UnionWith(n.Data)); // This will merge entry.FlushMessages(); TestMessage1 msg1Out; TestMessage2 msg2Out; Assert.IsFalse(entry.TryGetMessage(channel1Name, out msg1Out), "Channel1 should have no messages"); Assert.IsFalse(entry.TryGetMessage(channel2Name, out msg2Out), "Channel2 should have no messages"); // Validation MockChannel <TestMessage1> channel1 = distributedMemoryManagerMock.CreatedChannels[channel1Name] as MockChannel <TestMessage1>; Assert.IsNotNull(channel1, "{0} was not found", channel1Name); Assert.AreEqual(1, channel1.PublishedMessages.Count); // Should still have only one message as it has been merged SortedSet <int> msg1Data = new SortedSet <int>(); msg1Data.UnionWith(msg11.Data); msg1Data.UnionWith(msg12.Data); Assert.AreEqual(msg1Data.Count, channel1.PublishedMessages[0].Data.Count); Assert.IsTrue(channel1.PublishedMessages[0].Data.SetEquals(msg1Data)); MockChannel <TestMessage2> channel2 = distributedMemoryManagerMock.CreatedChannels[channel2Name] as MockChannel <TestMessage2>; Assert.IsNotNull(channel2, "{0} was not found", channel2Name); Assert.AreEqual(1, channel2.PublishedMessages.Count); // Should still have only one message as it has been merged SortedSet <int> msg2Data = new SortedSet <int>(); msg2Data.UnionWith(msg21.Data); msg2Data.UnionWith(msg22.Data); Assert.AreEqual(msg2Data.Count, channel2.PublishedMessages[0].Data.Count); Assert.IsTrue(channel2.PublishedMessages[0].Data.SetEquals(msg2Data)); }
public TestDataspace(string name, DateTime creation) : base(name) { Logger = LogManager.GetLogger(GetType()); RootProperty = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("a48c9c25-1e3a-43c8-be6a-044224cc69cb"), Title = "property", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "unitless", }; Velocity = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("d80b7b4d-f51d-4821-b1db-c595f18c51db"), Title = "velocity", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length per time", }; PenetrationRate = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("d2b70df2-6df3-4751-bd02-150e3fc96450"), Title = "penetration rate", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length per time", }; AvgPenetrationRate = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("7fbf2718-f45a-444e-ae3c-17f79f8817e2"), Title = "avg penetration rate", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length per time", }; Force = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("a5789b56-72a3-4561-b906-b5ba13852c23"), Title = "force", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "force", }; Load = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("3bf92c0b-b712-4128-b7bc-b21e0270d9be"), Title = "load", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "force", }; HookLoad = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("d0a7c1c5-73da-45b5-a762-eb49721d91e9"), Title = "hook load", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "force", }; Length = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("4a305182-221e-4205-9e7c-a36b06fa5b3d"), Title = "length", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length", }; Depth = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("4364b378-899a-403a-8401-b06abd4fc0cf"), Title = "depth", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length", }; MeasuredDepth = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("c48c65d4-9680-4d10-903c-a1b2e30f66b5"), Title = "measured depth", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "length", }; Time = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("3a72f130-4ebf-4ea9-a330-a610a4e4ed0e"), Title = "time", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "time", }; AbsoluteTime = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("df21fba2-fe8c-4d66-9a73-fbd0e6013abb"), Title = "absolute time", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "time", }; TimeStamp = new MockPropertyKind { Dataspace = this, Uuid = Guid.Parse("6a2ecc9b-7561-41eb-8c6d-adf83538c085"), Title = "time stamp", Creation = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), LastUpdate = DateTime.Parse("2016-12-09T17:30:47Z").ToUniversalTime(), IsAbstract = "false", QuantityClass = "time", }; Velocity.SetParent(RootProperty, creation); PenetrationRate.SetParent(Velocity, creation); AvgPenetrationRate.SetParent(PenetrationRate, creation); Force.SetParent(RootProperty, creation); Load.SetParent(Force, creation); HookLoad.SetParent(Load, creation); Length.SetParent(RootProperty, creation); Depth.SetParent(Length, creation); MeasuredDepth.SetParent(Depth, creation); Time.SetParent(RootProperty, creation); AbsoluteTime.SetParent(Time, creation); TimeStamp.SetParent(AbsoluteTime, creation); Well01 = new MockWell { Dataspace = this, Title = "Well 01", Creation = creation, LastUpdate = creation, }; Well02 = new MockWell { Dataspace = this, Title = "Well 02", Creation = creation, LastUpdate = creation, }; Wellbore01 = new MockWellbore { Dataspace = this, Title = "Wellbore 01", Creation = creation, LastUpdate = creation, }; Wellbore01.SetWell(Well01, creation); Wellbore02 = new MockWellbore { Dataspace = this, Title = "Wellbore 02", Creation = creation, LastUpdate = creation, }; Wellbore02.SetWell(Well01, creation); Wellbore03 = new MockWellbore { Dataspace = this, Title = "Wellbore 03 - Deleted Periodically", Creation = creation, LastUpdate = creation, }; Wellbore03.SetWell(Well01, creation); Wellbore04 = new MockWellbore { Dataspace = this, Title = "Wellbore 04 - Permanently Deleted", Creation = creation, LastUpdate = creation, }; Wellbore04.SetWell(Well01, creation); Wellbore05 = new MockWellbore { Dataspace = this, Title = "Wellbore 05 - Automatic Subscription", Creation = creation, LastUpdate = creation, }; Wellbore05.SetWell(Well01, creation); TimeChannel01 = new MockChannel(true) { Dataspace = this, Title = "Average ROP", Creation = creation, LastUpdate = creation, ChannelPropertyKind = AvgPenetrationRate, Mnemonic = "ROPA", Uom = "m/h", }; TimeChannel01.SetWellbore(Wellbore01, creation); TimeChannel02 = new MockChannel(true) { Dataspace = this, Title = "Hook Load", Creation = creation, LastUpdate = creation, ChannelPropertyKind = HookLoad, Mnemonic = "HKLD", Uom = "10 kN", }; TimeChannel02.SetWellbore(Wellbore01, creation); TimeChannel03 = new MockChannel(true) { Dataspace = this, Title = "Bit Depth - Periodically Deleted", Creation = creation, LastUpdate = creation, ChannelPropertyKind = MeasuredDepth, Mnemonic = "BDEP", Uom = "m", }; TimeChannel03.SetWellbore(Wellbore01, creation); TimeChannel04 = new MockChannel(true) { Dataspace = this, Title = "Hole Depth - Periodically Unjoined", Creation = creation, LastUpdate = creation, ChannelPropertyKind = MeasuredDepth, Mnemonic = "HDEP", Uom = "m", }; TimeChannel04.SetWellbore(Wellbore01, creation); TimeChannelSet01 = new MockChannelSet { Dataspace = this, Title = "Time ChannelSet 01", Creation = creation, LastUpdate = creation, }; TimeChannelSet01.SetWellbore(Wellbore01, creation); TimeChannel01.JoinContainer(TimeChannelSet01, creation); TimeChannel02.JoinContainer(TimeChannelSet01, creation); TimeChannel03.JoinContainer(TimeChannelSet01, creation); TimeChannel04.JoinContainer(TimeChannelSet01, creation); DepthChannel01 = new MockChannel(false) { Dataspace = this, Title = "Average ROP", Creation = creation, LastUpdate = creation, ChannelPropertyKind = AvgPenetrationRate, Mnemonic = "ROPA", Uom = "m/h", }; DepthChannel01.SetWellbore(Wellbore01, creation); DepthChannel02 = new MockChannel(false) { Dataspace = this, Title = "Hook Load", Creation = creation, LastUpdate = creation, ChannelPropertyKind = HookLoad, Mnemonic = "HKLD", Uom = "10 kN", }; DepthChannel02.SetWellbore(Wellbore01, creation); DepthChannelSet01 = new MockChannelSet { Dataspace = this, Title = "Depth ChannelSet 01", Creation = creation, LastUpdate = creation, }; DepthChannelSet01.SetWellbore(Wellbore01, creation); DepthChannel01.JoinContainer(DepthChannelSet01, creation); DepthChannel02.JoinContainer(DepthChannelSet01, creation); var objects = new List <MockObject> { Well01, Well02, Wellbore01, Wellbore02, Wellbore03, Wellbore05, RootProperty, Velocity, PenetrationRate, AvgPenetrationRate, Force, Load, HookLoad, Length, Depth, MeasuredDepth, Time, AbsoluteTime, TimeStamp, TimeChannelSet01, TimeChannel01, TimeChannel02, TimeChannel03, TimeChannel04, DepthChannelSet01, DepthChannel01, DepthChannel02, }; Objects.Clear(); foreach (var @object in objects) { Objects[@object.Uuid] = @object; @object.Create(creation); } var deletedObjects = new List <MockObject> { Wellbore04, }; DeletedObjects.Clear(); foreach (var deletedObject in deletedObjects) { DeletedObjects[deletedObject.Uuid] = deletedObject; } Witsml = new MockFamily { Dataspace = this, Title = "WITSML Store (2.0)", Type = MockWitsmlObject.Type, }; Eml = new MockFamily { Dataspace = this, Title = "EML Common (2.1)", Type = MockCommonObject.Type, }; var families = new List <MockFamily> { Witsml, Eml }; Families.Clear(); Families.AddRange(families); }