public void When_object_removed_modified_event_should_be_called() { var subscriber = Substitute.For <IDummySubscriber>(); var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var jObject = JObject.FromObject(item); var collection = new StreamCollection(_name); collection.Added(item.Id, jObject); collection.Modified += subscriber.React; // Act collection.Removed(item.Id); // Assert subscriber.Received() .React(Arg.Any <object>(), Arg.Is <StreamCollectionEventArgs>(args => args.ModificationType == ModificationType.Removed && args.Result == jObject )); }
public void When_an_empty_object_is_given_for_change_update_nothing() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var other = new { }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
public void When_object_is_added_and_collection_is_contains_id_override_new_object() { var existing = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(existing.Id, JObject.FromObject(existing)); collection.Added(existing.Id, JObject.FromObject(item)); // Assert var result = collection.GetAnonymousTypeById(existing.Id, item); result.Should().Be(item); }
private StreamCollection CreateUploadData(Stream imageStream, string fileName, Dictionary <string, string> parameters, string boundary) { var oAuth = parameters.ContainsKey("oauth_consumer_key"); var keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); var hashStringBuilder = new StringBuilder(SecretAccesToken, 2 * 1024); var ms1 = new MemoryStream(); var contentStringBuilder = new StreamWriter(ms1, new UTF8Encoding(false)); foreach (var key in keys) { #if !SILVERLIGHT // Silverlight < 5 doesn't support modification of the Authorization header, so all data must be sent in post body. if (key.StartsWith("oauth", StringComparison.Ordinal)) { continue; } #endif hashStringBuilder.Append(key); hashStringBuilder.Append(parameters[key]); contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"" + key + "\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(parameters[key] + "\r\n"); } if (!oAuth) { contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"api_sig\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(MD5Hash(hashStringBuilder.ToString()) + "\r\n"); } // Photo contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"photo\"; filename=\"" + Path.GetFileName(fileName) + "\"\r\n"); contentStringBuilder.Write("Content-Type: image/jpg\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Flush(); var photoContents = ConvertNonSeekableStreamToByteArray(imageStream); var ms2 = new MemoryStream(); var postFooterWriter = new StreamWriter(ms2, new UTF8Encoding(false)); postFooterWriter.Write("\r\n--" + boundary + "--\r\n"); postFooterWriter.Flush(); var collection = new StreamCollection(new[] { ms1, photoContents, ms2 }); return(collection); }
public void When_object_doesnt_exist_return_null() { var collection = new StreamCollection(_name); // Act var result = collection.GetById <StreamCollectionFixture>(AutoFixture.Create <string>()); // Assert result.Should().BeNull(); }
public void When_name_is_set_store_it() { var collection = new StreamCollection(_name); var name = AutoFixture.Create <string>(); // Act collection.Name = name; // Assert collection.Name.Should().Be(name); }
public void When_objects_not_exists_return_jobject() { var collection = new StreamCollection(_name); // Act // Assert var result = collection.GetJObjectById(AutoFixture.Create <string>()); ((object)result).Should().BeNull(); }
public StreamBufferEnumerator(int id, Stream stream, long streamLen, int chunkSize = BlockSize) { this.logId = id; DiagnoseHelper.CheckArgument(stream, "target stream can not null"); LogHelper.OnlineLogger.Debug(string.Format("Create stream enumerator, length={0}, chunksize={1}, {2}", streamLen, chunkSize, HttpLayer.LogRequetId(logId))); ChunkSize = chunkSize; targetStreams = new StreamCollection(stream); streamLength = streamLen; Reset(); }
public void When_acessing_name_it_should_pull_from_underlining_collection() { IStreamCollection fixture = new StreamCollection(_name); var collection = new TypedStreamCollection <StreamCollectionFixture>(fixture); // Act var name = collection.Name; // Assert name.Should().Be(_name); }
public void SetRequestStream(Stream requestStream, string contentType, long contentLength = -1, bool disposeWhenReset = true) { RequestStreams = new StreamCollection(new Stream[] { requestStream }); RequestStreams.Seek(0); needDisposeWhenReset = disposeWhenReset; LogHelper.OnlineLogger.Debug(string.Format("Set ContentLength={0},ContentType={1}", requestStream.Length, contentType)); //OriginalRequest.ContentLength = contentLength == -1 ? RequestStreams.Length : contentLength; OriginalRequest.ContentType = contentType; //OriginalRequest.AllowWriteStreamBuffering = false; }
public void When_object_does_exist_but_generic_is_not_of_type_thow() { var fixture = AutoFixture.Create <StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act Action action = () => collection.GetById <string>(fixture.Id); // Assert action.ShouldThrow <ArgumentException>(); }
public void When_object_does_exist_return_object() { var fixture = AutoFixture.Create <StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act var result = collection.GetById <StreamCollectionFixture>(fixture.Id); // Assert result.Should().Be(fixture); }
public void TestStreamCollection_Normal() { string[] source = { "1", "2", "3" }; var sc = new StreamCollection <string>(0, GetDataSourceYielding(source)); int i = 1; foreach (string s in sc) { Debug.WriteLine("Retrieved " + s); Assert.AreEqual(i++.ToString(), s); } }
private void Reset() { if (RequestStreamEnumerator != null) { RequestStreamEnumerator.Dispose(); RequestStreamEnumerator = null; } if (needDisposeWhenReset && requestStreams != null) { requestStreams.Dispose(); requestStreams = null; } }
public void When_object_is_changed_merge_existing_values() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { OldValue = AutoFixture.Create <string>(), Value = AutoFixture.Create <string>() } }; var other = new { Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { OldVaue = item.Obj.OldValue, Value = AutoFixture.Create <string>(), NewValue = AutoFixture.Create <string>() }, NewValue = AutoFixture.Create <string>() }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, other); result.Int.Should().Be(other.Int); result.Str.Should().Be(other.Str); result.Obj.Should().Be(other.Obj); other.Should().NotBeSameAs(result); var result2 = collection.GetAnonymousTypeById(item.Id, item); result2.Id.Should().Be(item.Id); item.Should().NotBeSameAs(result2); }
private StreamCollection CreateUploadData(Stream imageStream, string fileName, Dictionary <string, string> parameters, string boundary) { var keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); var hashStringBuilder = new StringBuilder(sharedSecret, 2 * 1024); var ms1 = new MemoryStream(); var contentStringBuilder = new StreamWriter(ms1, new UTF8Encoding(false)); foreach (var key in keys) { hashStringBuilder.Append(key); hashStringBuilder.Append(parameters[key]); contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"" + key + "\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(parameters[key] + "\r\n"); } contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"api_sig\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(UtilityMethods.MD5Hash(hashStringBuilder.ToString()) + "\r\n"); // Photo contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"photo\"; filename=\"" + Path.GetFileName(fileName) + "\"\r\n"); contentStringBuilder.Write("Content-Type: image/jpeg\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Flush(); var photoContents = ConvertNonSeekableStreamToByteArray(imageStream); var ms2 = new MemoryStream(); var postFooterWriter = new StreamWriter(ms2, new UTF8Encoding(false)); postFooterWriter.Write("\r\n--" + boundary + "--\r\n"); postFooterWriter.Flush(); var collection = new StreamCollection(new[] { ms1, photoContents, ms2 }); return(collection); }
static void BugTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.Open, System.IO.FileAccess.Read); Ar = new StreamCollection <TestClass>(System.IO.File.Open(Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate)); StreamLoger.DebugStream((c) => { if (c.IsSafe) { c.Action(); } else { c.Action(); } }); }
public void When_object_does_not_exists_object_should_not_exist() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeFalse(); }
public void When_object_exists_object_should_exist() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeTrue(); }
public async Task Login_with_email() { var email = AutoFixture.Create <string>(); var password = AutoFixture.Create <string>(); var payload = new { user = new { email }, password = new { digest = EncodingHelper.Sha256Hash(password), algorithm = EncodingHelper.Sha256 } }; var loginResult = AutoFixture.Create <LoginResult>(); var loginResponse = JObject.FromObject(new { result = loginResult }); _mockClient.CallAsync(Arg.Any <string>(), CancellationToken, Arg.Any <object[]>()) .ReturnsForAnyArgs(Task.FromResult(loginResponse)); IStreamCollection collection = new StreamCollection("users"); var user = JObject.FromObject(new { username = "" }); collection.Added(loginResult.UserId, user); _mockCollectionDatabase.WaitForObjectInCollectionAsync("users", loginResult.UserId, CancellationToken) .Returns(Task.FromResult(collection)); // Act await _driver.LoginWithEmailAsync(email, password); // Assert await _mockClient.ReceivedWithAnyArgs().CallAsync("login", CancellationToken, payload); }
public void When_object_exists_object_should_exist() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeTrue(); }
public void TestStreamCollection_Modifying() { LinkedList <string> list = new LinkedList <string>(); for (int i = 0; i < 10; i++) { list.AddLast(i.ToString()); } var sc = new StreamCollection <string>(0, list); var enumerator = sc.GetEnumerator(); int j = 0; for (int i = 0; i < 5; i++) { enumerator.MoveNext(); Assert.AreEqual(j++.ToString(), enumerator.Current); } list.AddLast("10"); enumerator.MoveNext(); Assert.AreEqual(j++.ToString(), enumerator.Current); }
public void When_objects_exists_return_jobject() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); // Assert var result = collection.GetJObjectById(item.Id); ((string)result["Id"]).Should().Be(item.Id); }
public void When_object_is_added_and_collection_is_empty_add_new_object() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
public void When_object_deleted_remove_from_collection() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Removed(item.Id); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().BeNull(); }
public void When_objects_exists_return_jobject() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); // Assert var result = collection.GetJObjectById(item.Id); ((string) result["Id"]).Should().Be(item.Id); }
public void When_object_does_not_exists_object_should_not_exist() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeFalse(); }
static void PerformanceTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); var FileStream = System.IO.File.Open(System.Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate); var MemoryStream = new System.IO.MemoryStream(); var Sr = new List <int>(); var Stream = new StreamCollection <int>(FileStream); //// warm up Stream.Insert(0); Stream.DeleteByPosition(0); var Count = 1_000_000; var InsertTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.Insert(i, i); } }); var Inserts_Per_Second = (int)(Count / InsertTime.TotalSeconds); var EveryInsert = (InsertTime.TotalSeconds / Count).ToString("0.##########"); var EveryInsert_Milisecond = ((InsertTime.TotalSeconds / Count) * 1000).ToString("0.##########"); var UpdateTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream[i] = i; } }); var Update1_Per_Second = (int)(Count / UpdateTime.TotalSeconds); var GetTimeByPosition = Timing.run(() => { for (int i = 0; i < Count; i++) { var c = Stream[i]; if (c == null) { throw new Exception(); } } }); var Get_Position_Per_Second = (int)(Count / GetTimeByPosition.TotalSeconds); var DeleteTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.DeleteByPosition(0); } }); var Delete_Per_Second = (int)(Count / DeleteTime.TotalSeconds); }
public void When_object_removed_modified_event_should_be_called() { var subscriber = Substitute.For<IDummySubscriber>(); var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var jObject = JObject.FromObject(item); var collection = new StreamCollection(_name); collection.Added(item.Id, jObject); collection.Modified += subscriber.React; // Act collection.Removed(item.Id); // Assert subscriber.Received() .React(Arg.Any<object>(), Arg.Is<StreamCollectionEventArgs>(args => args.ModificationType == ModificationType.Removed && args.Result == jObject )); }
public void When_object_deleted_remove_from_collection() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Removed(item.Id); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().BeNull(); }
public void When_object_does_exist_but_generic_is_not_of_type_thow() { var fixture = AutoFixture.Create<StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act Action action = () => collection.GetById<string>(fixture.Id); // Assert action.ShouldThrow<ArgumentException>(); }
public Replay(LogPrinter logger, string server, string store, string writeStream, uint ramSizeInMiB) { _logger = logger; _server = server; _store = store; _numWrites = new long[4]; _streams = new StreamCollection <Streams>(); _screenLock = new Object(); _state = ReplayState.Suspend; // Connect to the server and open the specified store _log("Connecting to server '{0}'...", server); _session = Native.StSessionCreate(server); if (_session == Native.INVALID_SESSION_ID) { throw new SimutraceException(); } _log("ok\n"); try { // Open the specified store _log("Opening store '{0}'...", store); if (!Native.StSessionOpenStore(_session, store)) { throw new SimutraceException(); } _log("ok\n"); List <uint> ids = new List <uint>(); // Find the memory write stream _log("Using memory write stream '{0}'...", writeStream); Guid mtype = new Guid("{6E943CDD-D2DA-4E83-984F-585C47EB0E36}"); _streams[Streams.Write] = new Stream(_session, writeStream, _applyWrite, mtype); if (!_streams[Streams.Write].IsValid) { throw new ReplayException("Could not find memory stream."); } ids.Add(_streams[Streams.Write].Id); _log("ok\n"); // Find the streams that contain dumps from the screen output _log("Searching for screen streams..."); Stream screen = new Stream(_session, "screen", _applyScreen); Stream screenData = new Stream(_session, "screen_data"); if (!screen.IsValid || !screenData.IsValid) { screen.Dispose(); screenData.Dispose(); _log("not found. Screen output not available.\n"); } else { _streams[Streams.Screen] = screen; _streams[Streams.ScreenData] = screenData; ids.Add(screen.Id); _log("ok\n"); } // Find the stream that contains cr3 change information _log("Searching for page directory set stream..."); Stream cr3 = new Stream(_session, "cpu_set_pagedirectory", _applyCr3); if (!cr3.IsValid) { cr3.Dispose(); _log("not found\n"); } else { _streams[Streams.Cr3] = cr3; ids.Add(cr3.Id); _log("ok\n"); } // Create multiplexer _streams[Streams.Multiplexer] = new Stream(_session, NativeX.StXMultiplexerCreate(_session, "mult", NativeX.MultiplexingRule.MxrCylceCount, NativeX.MultiplexerFlags.MxfIndirect, ids.ToArray())); if (!_streams[Streams.Multiplexer].IsValid) { throw new SimutraceException(); } _streams[Streams.Multiplexer].Open(); // Allocate a buffer that will hold the guest's RAM and a // ram bitmap for visualization _log("Configuring ram size for replay {0} MiB...", ramSizeInMiB); _ram = new RamMap((ulong)ramSizeInMiB << 20, true); _ramBitmap = new RamBitmap(_ram); _log("ok\n"); // Create the thread that will perform the replay _log("Creating replay thread..."); _replayer = new Thread(_replayThreadMain); _log("ok\n"); } catch (Exception) { _log("failed\n"); _finalize(); throw; } }
public void When_an_empty_object_is_given_for_change_update_nothing() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var other = new { }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
static void SafeTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); StreamLoger.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\DebugLog", System.IO.FileMode.OpenOrCreate); Ar = new StreamCollection <TestClass>(); Ar.Collection.Stream = System.IO.File.Open(Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate); s: var Role = random.Next(0, 5); switch (Role) { case 0: { var Pos = random.Next(0, Ar.Length); var Data = new TestClass() { Bytes = new byte[random.Next(0, 50)] }; Data.count = Data.Bytes.Length; StreamLoger.run(() => { Ar.Insert(Data, Pos); var OldData = Ar[Pos]; if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length) { throw new Exception(); } }); } break; case 1: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length - 1); var Data = new TestClass() { Bytes = new byte[random.Next(0, 50)] }; Data.count = Data.Bytes.Length; StreamLoger.run(() => { Ar[Pos] = Data; var OldData = Ar[Pos]; if (OldData.count != Data.count | OldData.Bytes.Length != Data.Bytes.Length) { throw new Exception(); } }); } break; case 2: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length); StreamLoger.run(() => { var InnerData = Ar[Pos]; }); } break; case 3: if (Ar.Length > 0) { var Pos = random.Next(0, Ar.Length - 1); StreamLoger.run(() => { Ar.DeleteByPosition(Pos); }); } break; case 4: StreamLoger.run(() => { var newar = Ar.Serialize().Deserialize(Ar); //newar.Info.Browse(newar); }); break; } goto s; }
public void When_object_is_changed_merge_existing_values() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { OldValue = AutoFixture.Create<string>(), Value = AutoFixture.Create<string>() } }; var other = new { Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { OldVaue = item.Obj.OldValue, Value = AutoFixture.Create<string>(), NewValue = AutoFixture.Create<string>() }, NewValue = AutoFixture.Create<string>() }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, other); result.Int.Should().Be(other.Int); result.Str.Should().Be(other.Str); result.Obj.Should().Be(other.Obj); other.Should().NotBeSameAs(result); var result2 = collection.GetAnonymousTypeById(item.Id, item); result2.Id.Should().Be(item.Id); item.Should().NotBeSameAs(result2); }
public void When_name_is_set_store_it() { var collection = new StreamCollection(_name); var name = AutoFixture.Create<string>(); // Act collection.Name = name; // Assert collection.Name.Should().Be(name); }
public void When_objects_not_exists_return_jobject() { var collection = new StreamCollection(_name); // Act // Assert var result = collection.GetJObjectById(AutoFixture.Create<string>()); ((object) result).Should().BeNull(); }
public void Dispose() { targetStreams = null; }
public async Task Login_with_email() { var email = AutoFixture.Create<string>(); var password = AutoFixture.Create<string>(); var payload = new { user = new { email }, password = new { digest = EncodingHelper.Sha256Hash(password), algorithm = EncodingHelper.Sha256 } }; var loginResult = AutoFixture.Create<LoginResult>(); var loginResponse = JObject.FromObject(new { result = loginResult }); _mockClient.CallAsync(Arg.Any<string>(), CancellationToken, Arg.Any<object[]>()) .ReturnsForAnyArgs(Task.FromResult(loginResponse)); IStreamCollection collection = new StreamCollection("users"); var user = JObject.FromObject(new {username = ""}); collection.Added(loginResult.UserId, user); _mockCollectionDatabase.WaitForObjectInCollectionAsync("users", loginResult.UserId, CancellationToken) .Returns(Task.FromResult(collection)); // Act await _driver.LoginWithEmailAsync(email, password); // Assert await _mockClient.ReceivedWithAnyArgs().CallAsync("login", CancellationToken, payload); }
public void When_object_doesnt_exist_return_null() { var collection = new StreamCollection(_name); // Act var result = collection.GetById<StreamCollectionFixture>(AutoFixture.Create<string>()); // Assert result.Should().BeNull(); }
/// <summary> /// Called when a stream has changed within the client. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void OnClientStreamsChanged(object sender, EventArgs e) { if (closing) { return; } streams = client.Status.Streams; Invoke((Action) delegate { streamsTree.BeginUpdate(); List <TreeNode> removals = new List <TreeNode>(); foreach (TreeNode n in streamsTree.Nodes) { removals.Add(n); } foreach (Stream stream in streams) { bool added = false; TreeNode node = null; if (!showClosedCheckBox.Checked) { if (stream.Status == StreamStatus.Failed || stream.Status == StreamStatus.Closed) { continue; } } foreach (TreeNode existingNode in streamsTree.Nodes) { if (((Stream)existingNode.Tag).ID == stream.ID) { node = existingNode; break; } } Circuit circuit = null; if (stream.CircuitID > 0) { circuit = circuits.Where(c => c.ID == stream.CircuitID).FirstOrDefault(); } string text = string.Format("Stream #{0} [{1}] ({2}, {3})", stream.ID, stream.Status, stream.Target, circuit == null ? "detached" : "circuit #" + circuit.ID); string tooltip = string.Format("Purpose: {0}", stream.Purpose); if (node == null) { node = new TreeNode(text); node.ContextMenuStrip = streamMenuStrip; node.Tag = stream; node.ToolTipText = tooltip; added = true; } else { node.Text = text; node.ToolTipText = tooltip; node.Nodes.Clear(); removals.Remove(node); } if (added) { streamsTree.Nodes.Add(node); } } foreach (TreeNode remove in removals) { streamsTree.Nodes.Remove(remove); } streamsTree.EndUpdate(); }); }
static void PerformanceTest() { System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\a.txt", new byte[0]); var FileStream = System.IO.File.Open(System.Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.Truncate); var SC = new StreamCollection <Data>(); SC.Collection.Stream = FileStream; var Stream = new Monsajem_Incs.Database.Base.Table <Data, string>( SC, (c) => c.Name, false); System.IO.File.WriteAllBytes(System.Environment.CurrentDirectory + "\\b.txt", new byte[0]); //// warm up Stream.Insert(new Data() { Name = "0", Id = 0 }); Stream.Delete(); var Count = 1000000; var InsertTime = Timing.run(() => { for (int i = Count - 1; i > -1; i--) { Stream.Insert((c) => { c.Name = i.ToString(); c.Id = i; }); } }); var Inserts_Per_Second = (int)(Count / InsertTime.TotalSeconds); var EveryInsert = (InsertTime.TotalSeconds / Count).ToString("0.##########"); var EveryInsert_Milisecond = ((InsertTime.TotalSeconds / Count) * 1000).ToString("0.##########"); var UpdateTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.Update((c) => { c.Name = i.ToString(); c.Id = i; }, (c) => { c.Name = i.ToString(); c.Id = i; }); } }); var Update1_Per_Second = (int)(Count / UpdateTime.TotalSeconds); var UpdateTime2 = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.Update(new Data() { Name = i.ToString(), Id = i }, (c) => { c.Name = i.ToString(); c.Id = i; }); } }); var Update2_Per_Second = (int)(Count / UpdateTime2.TotalSeconds); var GetTime = Timing.run(() => { for (int i = 0; i < Count; i++) { var c = Stream.GetItem(i); if (c == null) { throw new Exception(); } } }); var GetT_Per_Second = (int)(Count / GetTime.TotalSeconds); var DeleteTime = Timing.run(() => { for (int i = 0; i < Count; i++) { Stream.Delete(new Data() { Name = i.ToString() }); } }); var Delete_Per_Second = (int)(Count / DeleteTime.TotalSeconds); var stdb = SC.Serialize().Deserialize(SC); //FileStream.Flush(); FileStream.Close(); FileStream = System.IO.File.Open(System.Environment.CurrentDirectory + "\\a.txt", System.IO.FileMode.OpenOrCreate); var OldKeys = Stream.KeysInfo.Keys; Stream.KeysInfo.Keys = OldKeys; var data = Stream.GetItem(new Data() { Name = "ahmad" }); }
public void When_object_does_exist_return_object() { var fixture = AutoFixture.Create<StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act var result = collection.GetById<StreamCollectionFixture>(fixture.Id); // Assert result.Should().Be(fixture); }
private StreamCollection CreateUploadData(Stream imageStream, string fileName, Dictionary<string, string> parameters, string boundary) { var oAuth = parameters.ContainsKey("oauth_consumer_key"); var keys = new string[parameters.Keys.Count]; parameters.Keys.CopyTo(keys, 0); Array.Sort(keys); var hashStringBuilder = new StringBuilder(sharedSecret, 2 * 1024); var ms1 = new MemoryStream(); var contentStringBuilder = new StreamWriter(ms1, new UTF8Encoding(false)); foreach (var key in keys) { #if !SILVERLIGHT // Silverlight < 5 doesn't support modification of the Authorization header, so all data must be sent in post body. if (key.StartsWith("oauth")) continue; #endif hashStringBuilder.Append(key); hashStringBuilder.Append(parameters[key]); contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"" + key + "\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(parameters[key] + "\r\n"); } if (!oAuth) { contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"api_sig\"\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Write(UtilityMethods.MD5Hash(hashStringBuilder.ToString()) + "\r\n"); } // Photo contentStringBuilder.Write("--" + boundary + "\r\n"); contentStringBuilder.Write("Content-Disposition: form-data; name=\"photo\"; filename=\"" + Path.GetFileName(fileName) + "\"\r\n"); contentStringBuilder.Write("Content-Type: image/jpeg\r\n"); contentStringBuilder.Write("\r\n"); contentStringBuilder.Flush(); var photoContents = ConvertNonSeekableStreamToByteArray(imageStream); var ms2 = new MemoryStream(); var postFooterWriter = new StreamWriter(ms2, new UTF8Encoding(false)); postFooterWriter.Write("\r\n--" + boundary + "--\r\n"); postFooterWriter.Flush(); var collection = new StreamCollection(new[] { ms1, photoContents, ms2 }); return collection; }
public StreamOutputHubV2(StreamCollection sensorCollection) { _sensorCollection = sensorCollection; }