public void TestUnpackByteStream_Stream_LengthIsGreaterThanInt32MaxValue_CanReadToEnd() { // Header + Body Length ( Int32.MaxValue + 1 ) var bodyLength = Int32.MaxValue + 1L; var length = 1L + 4L + bodyLength; string filePath = Path.GetTempFileName(); try { File.SetAttributes(filePath, FileAttributes.SparseFile); using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 64 * 1024)) { fileStream.SetLength(length); fileStream.Position = 0; fileStream.Write(new byte[] { 0xDB, 0x80, 0x00, 0x00, 0x00 }, 0, 5); fileStream.Flush(); fileStream.Position = 0; using (var target = Unpacking.UnpackByteStream(fileStream)) { Assert.That(target.Length, Is.EqualTo(bodyLength)); byte[] buffer = new byte[64 * 1024]; long totalLength = 0; for (int read = target.Read(buffer, 0, buffer.Length); read > 0; read = target.Read(buffer, 0, buffer.Length)) { totalLength += read; } Assert.That(totalLength, Is.EqualTo(bodyLength)); } } } finally { File.Delete(filePath); } }
public void FindElementsTwoByEmptyChild() { Mock <IAllDriver> driver = new Mock <IAllDriver>(); Mock <IAllElement> elem1 = new Mock <IAllElement>(); Mock <IAllElement> elem2 = new Mock <IAllElement>(); Mock <IAllElement> elem3 = new Mock <IAllElement>(); Mock <IAllElement> elem4 = new Mock <IAllElement>(); Mock <IAllElement> elem5 = new Mock <IAllElement>(); var elems = new List <IWebElement>().AsReadOnly(); var elems12 = new List <IWebElement>() { elem1.Object, elem2.Object }.AsReadOnly(); var elems34 = new List <IWebElement>() { elem3.Object, elem4.Object }.AsReadOnly(); var elems5 = new List <IWebElement>() { elem5.Object }.AsReadOnly(); var elems345 = new List <IWebElement>() { elem3.Object, elem4.Object, elem5.Object }.AsReadOnly(); driver.Setup(_ => _.FindElementsByName(It.Is <string>(x => x == "cheese"))).Returns(elems12); elem1.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.Name("photo"))))).Returns(elems); elem2.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.Name("photo"))))).Returns(elems5); ByChained by = new ByChained(By.Name("cheese"), By.Name("photo")); Assert.That(by.FindElements(driver.Object), Is.EqualTo(new[] { elem5.Object })); driver.Verify(_ => _.FindElementsByName("cheese"), Times.Once); elem1.Verify(_ => _.FindElements(By.Name("photo")), Times.Once); elem2.Verify(_ => _.FindElements(By.Name("photo")), Times.Once); }
public void TestIssue111() { var context = new SerializationContext { SerializationMethod = SerializationMethod.Map, EnumSerializationMethod = EnumSerializationMethod.ByName, CompatibilityOptions = { PackerCompatibilityOptions = PackerCompatibilityOptions.None } }; var serializer = context.GetSerializer <Dictionary <string, object> >(); var dict = new Dictionary <string, object>(); dict["a"] = "x"; dict["b"] = true; dict["c"] = 5; dict["myclass"] = new Issue111Class() { x = 8, y = "ola" }; byte[] body = serializer.PackSingleObject(dict); using (var stream = new MemoryStream(body)) { var unpackedDictionary = Unpacking.UnpackDictionary(stream); Assert.That(unpackedDictionary.Count, Is.EqualTo(4)); Assert.That(unpackedDictionary["a"] == "x"); Assert.That(unpackedDictionary["b"] == true); Assert.That(unpackedDictionary["c"] == 5); Assert.That(unpackedDictionary["myclass"].IsDictionary); var myClass = unpackedDictionary["myclass"].AsDictionary(); Assert.That(myClass["x"] == 8); Assert.That(myClass["y"] == "ola"); } }
public async Task TestSkipAsync_BetweenSubtreeReader_NestedMap_AsIs() { if (!this.ShouldCheckSubtreeUnpacker) { #if MSTEST // MSTEST cannot handle inconclusive in async test correctly. await Task.Delay(0); return; #endif // MSTEST Assert.Ignore("Cannot test subtree unpacker in " + this.GetType().Name); } using (var stream = new MemoryStream(new byte[] { 0x83, 0x1, 0x81, 0x2, 0x2, 0x3, 0x3, 0x4, 0x81, 0x4, 0x4 })) using (var target = this.CreateUnpacker(stream)) { Assert.That(await target.ReadAsync()); Assert.That(await target.SkipAsync(), Is.EqualTo(1)); Assert.That(await target.ReadAsync()); using (var subTreeReader = target.ReadSubtree()) { Assert.That(await subTreeReader.SkipAsync(), Is.EqualTo(1)); Assert.That(await subTreeReader.SkipAsync(), Is.EqualTo(1)); } Assert.That(await target.SkipAsync(), Is.EqualTo(1)); Assert.That(await target.SkipAsync(), Is.EqualTo(1)); Assert.That(await target.SkipAsync(), Is.EqualTo(1)); Assert.That(await target.ReadAsync()); using (var subTreeReader = target.ReadSubtree()) { Assert.That(await subTreeReader.SkipAsync(), Is.EqualTo(1)); Assert.That(await subTreeReader.SkipAsync(), Is.EqualTo(1)); } } }
public void TestUpdateMultipleFiles() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; using (StreamWriter w = new StreamWriter(Path.Combine(WcPath, "Form.cs"))) w.Write("Moo"); using (StreamWriter w = new StreamWriter(Path.Combine(WcPath, "AssemblyInfo.cs"))) w.Write("Moo"); SvnCommitArgs ca = new SvnCommitArgs(); ca.LogMessage = ""; Client.Commit(WcPath, ca); SvnUpdateArgs a = new SvnUpdateArgs(); a.Depth = SvnDepth.Empty; SvnUpdateResult result; Assert.That(Client.Update(new string[] { Path.Combine(WcPath, "Form.cs"), Path.Combine(WcPath, "AssemblyInfo.cs") }, a, out result)); Assert.That(result.ResultMap.Count, Is.EqualTo(2)); string s; using (StreamReader r = new StreamReader(Path.Combine(WcPath, "Form.cs"))) s = r.ReadToEnd(); Assert.That(s, Is.EqualTo("Moo"), "File not updated"); using (StreamReader r = new StreamReader(Path.Combine(WcPath, "AssemblyInfo.cs"))) s = r.ReadToEnd(); Assert.That(s, Is.EqualTo("Moo"), "File not updated"); }
private void TestEnumForByName <T>(SerializationContext context, T value, string property) { var serializer = context.GetSerializer <T>(); using (var stream = new MemoryStream()) { serializer.Pack(stream, value); stream.Position = 0; var deserialized = serializer.Unpack(stream); if (property == null) { Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; Assert.That(Unpacking.UnpackString(stream), Is.EqualTo(value.ToString())); } else { var propertyInfo = typeof(T).GetProperty(property); #if !UNITY Assert.That(propertyInfo.GetValue(deserialized, null), Is.EqualTo(propertyInfo.GetValue(value, null))); #else Assert.That(propertyInfo.GetGetMethod().Invoke(deserialized, null), Is.EqualTo(propertyInfo.GetGetMethod().Invoke(value, null))); #endif // !UNITY stream.Position = 0; var result = Unpacking.UnpackDictionary(stream); Assert.That( #if !UNITY result[property].Equals(propertyInfo.GetValue(value, null).ToString()), result[property] + " == " + propertyInfo.GetValue(value, null) #else result[property].Equals(propertyInfo.GetGetMethod().Invoke(value, null).ToString()), result[property] + " == " + propertyInfo.GetGetMethod().Invoke(value, null) #endif // !UNITY ); } } }
public void TestProperties_Plus1Sec() { // 1970-01-01T00:00:01.000000000Z var target = new Timestamp(1, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(1), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(1970), "Year"); Assert.That(target.Month, Is.EqualTo(1), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(1), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(1), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Thursday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestProperties_YearMinus400() { // -0400-03-01T00:00:00.000000000Z var target = new Timestamp(-74784816000, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-74784816000), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(-400), "Year"); Assert.That(target.Month, Is.EqualTo(3), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(61), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Wednesday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(true), "IsLeapYear"); }
public void TestProperties_Minus1Sec() { // 1969-12-31T23:59:59.000000000Z var target = new Timestamp(-1, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-1), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(1969), "Year"); Assert.That(target.Month, Is.EqualTo(12), "Month"); Assert.That(target.Day, Is.EqualTo(31), "Day"); Assert.That(target.Hour, Is.EqualTo(23), "Hour"); Assert.That(target.Minute, Is.EqualTo(59), "Minute"); Assert.That(target.Second, Is.EqualTo(59), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(365), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Wednesday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void PostThrowHandKarma() { FortuneFountainSaveData fortuneFountainSaveData = UglySaveData(nameof(PostThrowHandKarma)); AssertAll.Of( () => Assert.That(fortuneFountainSaveData.Karma, Is.EqualTo(0)), () => Assert.That(fortuneFountainSaveData.Hand.Throwables, Is.Not.Empty) ); var expectedPostThrowKarma = fortuneFountainSaveData.Hand.KarmaInHand; LogUtils.Log( $"Before throwing, there is {fortuneFountainSaveData.Karma} karma", $"In my hand, there is {fortuneFountainSaveData.Hand.KarmaInHand} karma" ); fortuneFountainSaveData.Hand.Throw(); AssertAll.Of( () => Assert.That(fortuneFountainSaveData.Karma, Is.EqualTo(expectedPostThrowKarma)), () => Assert.That(fortuneFountainSaveData.Hand.Throwables, Is.Empty) ); }
public void TestProperties_TimestampMin() { // -292277022657-01-27T08:29:52.000000000Z var target = new Timestamp(-9223372036854775808, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-9223372036854775808), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(-292277022657), "Year"); Assert.That(target.Month, Is.EqualTo(1), "Month"); Assert.That(target.Day, Is.EqualTo(27), "Day"); Assert.That(target.Hour, Is.EqualTo(8), "Hour"); Assert.That(target.Minute, Is.EqualTo(29), "Minute"); Assert.That(target.Second, Is.EqualTo(52), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(27), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestProperties_DateTimeMaxPlus1Nsec() { // 9999-12-31T23:59:59.000000001Z var target = new Timestamp(253402300799, 1); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(253402300799), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(1), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(9999), "Year"); Assert.That(target.Month, Is.EqualTo(12), "Month"); Assert.That(target.Day, Is.EqualTo(31), "Day"); Assert.That(target.Hour, Is.EqualTo(23), "Hour"); Assert.That(target.Minute, Is.EqualTo(59), "Minute"); Assert.That(target.Second, Is.EqualTo(59), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(1), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(365), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Friday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestProperties_DateTimeMinMinus1Nsec() { // 0000-12-31T23:59:59.999999999Z var target = new Timestamp(-62135596801, 999999999); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-62135596801), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(999999999), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(0), "Year"); Assert.That(target.Month, Is.EqualTo(12), "Month"); Assert.That(target.Day, Is.EqualTo(31), "Day"); Assert.That(target.Hour, Is.EqualTo(23), "Hour"); Assert.That(target.Minute, Is.EqualTo(59), "Minute"); Assert.That(target.Second, Is.EqualTo(59), "Second"); Assert.That(target.Millisecond, Is.EqualTo(999), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(999), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(999), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(366), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(true), "IsLeapYear"); }
public void TestProperties_DateTimeMaxPlus1Sec() { // 10000-01-01T00:00:00.000000000Z var target = new Timestamp(253402300800, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(253402300800), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(10000), "Year"); Assert.That(target.Month, Is.EqualTo(1), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(1), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(true), "IsLeapYear"); }
public void TestProperties_DateTimeMinMinus1Day() { // 0000-12-31T00:00:00.000000000Z var target = new Timestamp(-62135683200, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-62135683200), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(0), "Year"); Assert.That(target.Month, Is.EqualTo(12), "Month"); Assert.That(target.Day, Is.EqualTo(31), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(366), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(true), "IsLeapYear"); }
public void TestProperties_DateTimeMin() { // 0001-01-01T00:00:00.000000000Z var target = new Timestamp(-62135596800, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-62135596800), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(1), "Year"); Assert.That(target.Month, Is.EqualTo(1), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(1), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Monday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void LoadMostRecentFromInstance() { var saveData = SaveDataTestImpl.NewSaveFile(nameof(LoadMostRecentFromInstance)); var firstEdit = "First Edit"; saveData.Word = firstEdit; saveData.Save(false); var saveData2 = SaveDataTestImpl.NewSaveFile(saveData.Nickname); var secondEdit = "Second Edit"; saveData2.Word = secondEdit; saveData2.Save(false); Assert.That(saveData.Word, Is.EqualTo(firstEdit)); Assert.That(saveData, Is.Not.SameAs(saveData2)); var loadedSave = saveData.Reload(); Assert.That(loadedSave, Is.SameAs(saveData)); Assert.That(saveData.Word, Is.Not.EqualTo(firstEdit)); Assert.That(saveData.Word, Is.EqualTo(secondEdit)); }
public void TestProperties_TimestampMax() { // 292277026596-12-04T15:30:07.999999999Z var target = new Timestamp(9223372036854775807, 999999999); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(9223372036854775807), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(999999999), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(292277026596), "Year"); Assert.That(target.Month, Is.EqualTo(12), "Month"); Assert.That(target.Day, Is.EqualTo(4), "Day"); Assert.That(target.Hour, Is.EqualTo(15), "Hour"); Assert.That(target.Minute, Is.EqualTo(30), "Minute"); Assert.That(target.Second, Is.EqualTo(7), "Second"); Assert.That(target.Millisecond, Is.EqualTo(999), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(999), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(999), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(339), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Monday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(true), "IsLeapYear"); }
public void TestDispose_NotTail_Drained() { using (var buffer = new MemoryStream(new byte[] { 0x1, 0x92, 0x2, 0x3, 0x4 })) using (var root = Unpacker.Create(buffer)) { int lastValue; Assert.That(root.ReadInt32(out lastValue)); Assert.That(lastValue, Is.EqualTo(1)); long length; Assert.That(root.ReadArrayLength(out length)); Assert.That(length, Is.EqualTo(2)); using (var subtree = root.ReadSubtree()) { Assert.That(subtree.ReadInt32(out lastValue)); Assert.That(lastValue, Is.EqualTo(2)); } Assert.That(root.ReadInt32(out lastValue)); Assert.That(lastValue, Is.EqualTo(4)); } }
public void RevTests() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string dir = sbox.Wc; SvnUpdateResult result; Assert.That(Client.CheckOut(new SvnUriTarget(new Uri(CollabReposUri, "trunk")), dir, out result)); long head = result.Revision; Assert.That(Client.Update(dir, out result)); Assert.That(result.Revision, Is.EqualTo(head)); SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = head - 5; Assert.That(Client.Update(dir, ua, out result)); Assert.That(result.Revision, Is.EqualTo(head - 5)); }
public void GetMetadata_WithReadOnlyMixedPropertyHavingSetterOnMixin() { IPropertyInformation propertyInfo = GetPropertyInfo( MixinTypeUtility.GetConcreteMixedType(typeof(ClassWithMixedProperty)), typeof(IMixinAddingProperty), "MixedReadOnlyPropertyHavingSetterOnMixin"); Assertion.IsTrue(propertyInfo is MixinIntroducedPropertyInformation); PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider); Assert.That(GetUnderlyingType(propertyReflector), Is.SameAs(typeof(string))); IBusinessObjectProperty businessObjectProperty = propertyReflector.GetMetadata(); Assert.That(businessObjectProperty, Is.InstanceOf(typeof(PropertyBase))); Assert.That(((PropertyBase)businessObjectProperty).PropertyInfo, Is.SameAs(propertyInfo)); Assert.That(businessObjectProperty.Identifier, Is.EqualTo("MixedReadOnlyPropertyHavingSetterOnMixin")); Assert.That(businessObjectProperty.PropertyType, Is.SameAs(typeof(string))); Assert.That(businessObjectProperty.IsList, Is.False); Assert.That(businessObjectProperty.IsRequired, Is.False); Assert.That(businessObjectProperty.IsReadOnly(null), Is.True); }
public void TestProperties_Year10100() { // 10100-03-01T00:00:00.000000000Z var target = new Timestamp(256563158400, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(256563158400), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(10100), "Year"); Assert.That(target.Month, Is.EqualTo(3), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(60), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Monday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestProperties_Distinguishable() { // 1234-05-06T07:08:09.123456789Z var target = new Timestamp(-23215049511, 123456789); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-23215049511), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(123456789), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(1234), "Year"); Assert.That(target.Month, Is.EqualTo(5), "Month"); Assert.That(target.Day, Is.EqualTo(6), "Day"); Assert.That(target.Hour, Is.EqualTo(7), "Hour"); Assert.That(target.Minute, Is.EqualTo(8), "Minute"); Assert.That(target.Second, Is.EqualTo(9), "Second"); Assert.That(target.Millisecond, Is.EqualTo(123), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(456), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(789), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(126), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestEquality_ValueEqual() { foreach (var testCase in new[] { Tuple.Create(0, 0, new byte[] { 1 }, new byte[] { 1 }, true), Tuple.Create(0, 1, new byte[] { 1 }, new byte[] { 1 }, false), Tuple.Create(0, 0, new byte[] { 1 }, new byte[] { 1, 2 }, false), Tuple.Create(0, 0, new byte[] { 1 }, new byte[] { 2 }, false), }) { checked { MessagePackObject left = new MessagePackExtendedTypeObject(( byte )testCase.Item1, testCase.Item3); MessagePackObject right = new MessagePackExtendedTypeObject(( byte )testCase.Item2, testCase.Item4); Assert.That(left.Equals(right), Is.EqualTo(testCase.Item5), "IEquatable.Equals"); Assert.That(left.Equals(( object )right), Is.EqualTo(testCase.Item5), "Equals"); Assert.That(left == right, Is.EqualTo(testCase.Item5), "=="); Assert.That(left != right, Is.EqualTo(!testCase.Item5), "!="); } } }
public void TypesAppearInTheCorrectOrder() { var names = new[] { "SomeType", "SomeType2", "SomeNamespace.SomeType", "SomeNamespace.InnerNamespace.OtherType1", "SomeNamespace.InnerNamespace.OtherType2", "SomeNamespace.SomeType.StrangeType1", "SomeNamespace.SomeType.StrangeType2", "SomeType2.SomeType3", "SomeTYpe2.SomeType3.SomeType4", }; var rnd = new Random(3); var unorderedNames = names.Select(n => new { n = n, r = rnd.Next() }).OrderBy(x => x.r).Select(x => x.n).ToArray(); var output = Process(unorderedNames.Select(n => new JsClass(CreateMockTypeDefinition(n), JsClass.ClassTypeEnum.Class, null, null, null))); var actual = output.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Where(l => l.StartsWith("// ")).Select(l => l.Substring(3)).ToList(); Assert.That(actual, Is.EqualTo(names)); }
public void TestProperties_YearMinus399() { // -0399-03-01T00:00:00.000000000Z var target = new Timestamp(-74753280000, 0); Assert.That(target.UnixEpochSecondsPart, Is.EqualTo(-74753280000), "UnixEpochSecondsPart"); Assert.That(target.NanosecondsPart, Is.EqualTo(0), "NanosecondsPart"); Assert.That(target.Year, Is.EqualTo(-399), "Year"); Assert.That(target.Month, Is.EqualTo(3), "Month"); Assert.That(target.Day, Is.EqualTo(1), "Day"); Assert.That(target.Hour, Is.EqualTo(0), "Hour"); Assert.That(target.Minute, Is.EqualTo(0), "Minute"); Assert.That(target.Second, Is.EqualTo(0), "Second"); Assert.That(target.Millisecond, Is.EqualTo(0), "Millisecond"); Assert.That(target.Microsecond, Is.EqualTo(0), "Microsecond"); Assert.That(target.Nanosecond, Is.EqualTo(0), "Nanosecond"); Assert.That(target.DayOfYear, Is.EqualTo(60), "DayOfYear"); Assert.That(target.DayOfWeek, Is.EqualTo(DayOfWeek.Thursday), "DayOfWeek"); Assert.That(target.IsLeapYear, Is.EqualTo(false), "IsLeapYear"); }
public void TestIssue70() { var serializer = MessagePackSerializer.Get <DBNull>(new SerializationContext()); #if !UNITY // Should not be created dynamically. Assert.That(serializer, Is.TypeOf(typeof(DefaultSerializers.System_DBNullMessagePackSerializer))); #endif // !UNITY using (var buffer = new MemoryStream()) { serializer.Pack(buffer, DBNull.Value); buffer.Position = 0; var packed = Unpacking.UnpackObject(buffer); Assert.That(packed.IsNil, packed.ToString()); buffer.Position = 0; var unpacked = serializer.Unpack(buffer); Assert.That(Object.ReferenceEquals(unpacked, null), Is.False); Assert.That(unpacked, Is.SameAs(DBNull.Value)); } }
public void TestElelementMissingInTheFirstPlace_Map_MissingMembersAreSkipped() { using (var buffer = new MemoryStream()) { var valueOfValue1 = "123"; using (var packer = Packer.Create(buffer, false)) { packer.PackMapHeader(1); packer.PackString("Value1"); packer.PackString(valueOfValue1); } buffer.Position = 0; var context = this.CreateSerializationContext(); context.SerializationMethod = SerializationMethod.Map; var target = CreateTarget <ComplexTypeWithTwoMember>(context); var result = target.Unpack(buffer); Assert.That(result.Value1, Is.EqualTo(valueOfValue1)); Assert.That(result.Value2, Is.EqualTo(new ComplexTypeWithTwoMember().Value2)); } }
public void TestUnpackCharStream_Stream_Encoding_1Byte_AsIsAndBounded() { #if !NETFX_CORE && !SILVERLIGHT using (var stream = new MemoryStream(new byte[] { 0xA4, 0x00, 0x00, 0x00, ( byte )'A', 0xFF })) #else using (var stream = new MemoryStream(new byte[] { 0xA2, 0x00, ( byte )'A', 0xFF })) #endif // !NETFX_CORE && !SILVERLIGHT { #if !NETFX_CORE && !SILVERLIGHT using (var result = Unpacking.UnpackCharStream(stream, new UTF32Encoding(bigEndian: true, byteOrderMark: false, throwOnInvalidCharacters: true))) { AssertStringReader(result, 4, "A"); } #else using (var result = Unpacking.UnpackCharStream(stream, new UnicodeEncoding(bigEndian: true, byteOrderMark: false, throwOnInvalidBytes: true))) { AssertStringReader(result, 2, "A"); } #endif // !NETFX_CORE && !SILVERLIGHT // Assert is valid position on unerlying stream. Assert.That(Unpacking.UnpackInt32(stream), Is.EqualTo(-1)); } }
public void TestUpdateExternal() { SvnSandBox sbox = new SvnSandBox(this); Uri root = sbox.CreateRepository(SandBoxRepository.Empty); Uri trunk = new Uri(root, "trunk/"); Uri alt = new Uri(root, "alt/"); Client.RemoteCreateDirectory(trunk); Client.RemoteCreateDirectory(alt); string dir = sbox.GetTempDir(); Client.CheckOut(trunk, dir); Client.SetProperty(dir, SvnPropertyNames.SvnExternals, string.Format("alt1 {0}\r\n" + "alt2 {0}\n" + "alt3 {0}", alt)); SvnUpdateArgs ua = new SvnUpdateArgs(); SortedList <string, string> paths = new SortedList <string, string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { if (e.Action != SvnNotifyAction.UpdateExternal) { return; } paths.Add(e.FullPath, e.FullPath); }; Client.Update(dir, ua); Assert.That(paths.Count, Is.EqualTo(3)); Assert.That(paths.ContainsKey(Path.Combine(dir, "alt2"))); }
public void ParseTokensTests() { var @is = new Is(); new[] { TestData.Create(" ", new Token[0]), TestData.Create("'Hello'", new Token[] {new StringLiteralToken("Hello")}), TestData.Create("\"Hello\"", new Token[] {new StringLiteralToken("Hello")}), TestData.Create("15", new Token[] {new NumberLiteralToken(15)}), TestData.Create("1.4", new Token[] {new NumberLiteralToken(1.4)}), TestData.Create("select", new Token[] {new KeywordToken(Keyword.Select)}), TestData.Create("SELECT", new Token[] {new KeywordToken(Keyword.Select)}), TestData.Create("select from", new Token[] {new KeywordToken(Keyword.Select), new KeywordToken(Keyword.From)}), TestData.Create("hello", new Token[] {new IdentifierToken("hello")}), TestData.Create("a1", new Token[] {new IdentifierToken("a1")}), TestData.Create("_a", new Token[] {new IdentifierToken("_a")}), }.AssertDataDrivenTest( s => new QueryTokenizer().ParseTokens(s), _ => Is.Not.Null, expected => @is.EquivalentTo(expected, new TokenComparer())); }