public void TryResolveAllReturnsExpectedInstances() { using (var container = new IocContainer()) { // Arrange var foo1 = new Foo1(); var foo2 = new Foo2(); var foo3 = new Foo2(); var bar1 = new Bar1(); container.RegisterInstance<IFoo>(foo1); container.RegisterInstance<IFoo>(foo2, "Foo1"); container.RegisterInstance<IFoo>(foo3, "Foo2"); container.RegisterInstance<IBar>(bar1); // Act var results = container.TryResolveAll<IFoo>(); var resultList = results.ToList(); // Assert Assert.IsTrue(results.Count() == 3); CollectionAssert.Contains(resultList, foo1); CollectionAssert.Contains(resultList, foo2); CollectionAssert.Contains(resultList, foo3); } }
public void TestCharMarshalling() { Foo2 foo2 = new Foo2(); for (char c = char.MinValue; c <= sbyte.MaxValue; c++) Assert.That(foo2.testCharMarshalling(c), Is.EqualTo(c)); Assert.Catch<ArgumentException>(() => foo2.testCharMarshalling('ж')); }
public void MessageNull() { IClassValidator vtor = new ClassValidator(typeof(Foo2)); Foo2 f = new Foo2(); vtor.GetInvalidValues(f); }
public void CanChangeMethodBehaviorThroughStaticType() { Foo foo = new Foo(); Foo2 foo2 = new Foo2(); Assert.AreEqual(1, foo.bar()); Assert.AreEqual(2, foo2.bar()); foo = foo2; Assert.AreEqual(1, foo.bar()); }
public void TestHello() { var hello = new Hello(); hello.PrintHello("Hello world"); Assert.That(hello.add(1, 1), Is.EqualTo(2)); Assert.That(hello.add(5, 5), Is.EqualTo(10)); Assert.IsTrue(hello.test1(3, 3.0f)); Assert.IsFalse(hello.test1(2, 3.0f)); var foo = new Foo { A = 4, B = 7 }; Assert.That(hello.AddFoo(foo), Is.EqualTo(11)); Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11)); Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11)); Assert.That(hello.AddFooRef(foo), Is.EqualTo(11)); unsafe { var pointer = foo.SomePointer; var pointerPointer = foo.SomePointerPointer; for (int i = 0; i < 4; i++) { Assert.AreEqual(i, pointer[i]); Assert.AreEqual(i, (*pointerPointer)[i]); } } var bar = new Bar { A = 4, B = 7 }; Assert.That(hello.AddBar(bar), Is.EqualTo(11)); Assert.That(bar.RetItem1(), Is.EqualTo(Bar.Item.Item1)); var retFoo = hello.RetFoo(7, 2.0f); Assert.That(retFoo.A, Is.EqualTo(7)); Assert.That(retFoo.B, Is.EqualTo(2.0)); var foo2 = new Foo2 { A = 4, B = 2, C = 3 }; Assert.That(hello.AddFoo(foo2), Is.EqualTo(6)); Assert.That(hello.AddFoo2(foo2), Is.EqualTo(9)); var bar2 = new Bar2 { A = 4, B = 7, C = 3 }; Assert.That(hello.AddBar2(bar2), Is.EqualTo(14)); Assert.That(hello.RetEnum(Enum.A), Is.EqualTo(0)); Assert.That(hello.RetEnum(Enum.B), Is.EqualTo(2)); Assert.That(hello.RetEnum(Enum.C), Is.EqualTo(5)); //Assert.That(hello.RetEnum(Enum.D), Is.EqualTo(-2147483648)); Assert.That(hello.RetEnum(Enum.E), Is.EqualTo(1)); Assert.That(hello.RetEnum(Enum.F), Is.EqualTo(-9)); }
public void IgnoreMutilineComments() { var input = "/*comment1\r\ncomment2\r\ncomment3*/\r\n{ \"Bars\": [{\"Baz\": \"Test\"}]}"; var expected = new Foo2 { Bars = new List<Bar2> { new Bar2 { Baz="Test"} } }; var actual = new JsonReader().Read<Foo2>(input); Assert.Equal(expected, actual); }
static void Main(string[] args) { var foot = new FooT(); var foo = new Foo<FooT>(); var foo2 = new Foo2<int>(); // prefered solution using CompareTo method var bar = new Bar<string>(); // Bar<T> has implementation eqivalent to Foo2<T> var myGen = new MyGeneric<cMyType>(); Console.WriteLine(foo.IsInRange(foot)); Console.WriteLine(foo2.IsInRange(5)); Console.WriteLine(bar.IsInRange("nine")); Console.WriteLine(myGen + myGen); Console.WriteLine("Press ANY key to exit."); Console.ReadKey(); }
public void CanRoundTripReadOnlyPropertiesWithMatchingConstructorParameters() { var foo = new Foo2( GetReadOnlyCollection(), GetReadOnlyCollection(), GetReadOnlyDictionary(), GetReadOnlyDictionary(), GetReadOnlyCollection()); var serializer = new XmlSerializer<Foo2>(x => x.Indent()); var xml = serializer.Serialize(foo); var roundTrip = serializer.Deserialize(xml); Assert.That(roundTrip, Has.PropertiesEqualTo(foo)); }
public void TryResolveAllByTypeNotRegisteredReturnsEmptyEnumerable() { using (var container = new IocContainer()) { // Arrange var foo1 = new Foo1(); var foo2 = new Foo2(); var bar1 = new Bar1(); container.RegisterInstance<IFoo>(foo1); container.RegisterInstance<IFoo>(foo2, "Foo"); container.RegisterInstance<IBar>(bar1); // Act var results = container.TryResolveAll<IFooBar>(); // Assert Assert.IsTrue(results.Count() == 0); } }
public T Get_T2(double d, T t) { return(Foo2 <T> .Get_T2(d, 1, 2, 3, 4, 5, 6, 7, 8, t)); }
public void TestInitializationWithServiceTypeAndComponentAndInnerException() { Type serviceType = typeof (Foo); Foo2 component = new Foo2(); Exception innerException = new Exception(); ServiceMissingException exception = new ServiceMissingException(serviceType, component, innerException); Assert.IsTrue(exception.Message.Contains(serviceType.ToString())); Assert.IsTrue(exception.Message.Contains(component.ToString())); Assert.AreEqual(innerException, exception.InnerException); }
public void TestCtorByValue() { var bar = new Bar { A = 4, B = 5.5f }; var foo2 = new Foo2 { C = 4, valueTypeField = bar }; var result = foo2 << 2; Assert.AreEqual(foo2.C << 2, result.C); Assert.AreEqual(bar.A << 2, result.valueTypeField.A); Assert.AreEqual(bar.B, result.valueTypeField.B); }
public void Foo2(Foo2 input) { }
public void Init(Foo2 foo) { }
public void InstanceMethod() { var capturedVariable = Math.Pow(42, 1); _field = () => Foo2.StaticMethod(capturedVariable); //Foo2 }
public Baz() { Foo foo = new Foo(); Foo2 foo2 = new Foo2(); }
public unsafe void TestCodeGeneration() { #pragma warning disable 0168 // warning CS0168: The variable `foo' is declared but never used #pragma warning disable 0219 // warning CS0219: The variable `foo' is assigned but its value is never used using (var changedAccessOfInheritedProperty = new ChangedAccessOfInheritedProperty()) { Assert.That(changedAccessOfInheritedProperty.Property, Is.EqualTo(2)); } Foo.NestedAbstract a; Foo.RenamedEmptyEnum.EmptyEnum1.GetHashCode(); using (var foo = new Foo()) { Bar bar = foo; Assert.IsTrue(Bar.Item.Item1 == bar); using (var hasOverloadsWithDifferentPointerKindsToSameType = new HasOverloadsWithDifferentPointerKindsToSameType()) { hasOverloadsWithDifferentPointerKindsToSameType.Overload(foo, 0); using (var foo2 = new Foo2()) hasOverloadsWithDifferentPointerKindsToSameType.Overload(foo2, 0); } } using (var overridesNonDirectVirtual = new OverridesNonDirectVirtual()) { using (var foo = new Foo()) { Assert.That(overridesNonDirectVirtual.RetInt(foo), Is.EqualTo(3)); Assert.That(foo.FooPtr, Is.EqualTo(1)); } } using (var derivedFromTemplateInstantiationWithVirtual = new DerivedFromTemplateInstantiationWithVirtual()) { } using (var hasProtectedEnum = new HasProtectedEnum()) { } using (var hasPropertyNamedAsParent = new HasPropertyNamedAsParent()) { hasPropertyNamedAsParent.hasPropertyNamedAsParent.GetHashCode(); } EnumWithUnderscores e = EnumWithUnderscores.lOWER_BEFORE_CAPITAL; e = EnumWithUnderscores.UnderscoreAtEnd; e = EnumWithUnderscores.CAPITALS_More; e = EnumWithUnderscores.UsesDigits1_0; e.GetHashCode(); ItemsDifferByCase itemsDifferByCase = ItemsDifferByCase.Case_a; itemsDifferByCase = ItemsDifferByCase.CaseA; itemsDifferByCase.GetHashCode(); new AmbiguousParamNames(0, 0).Dispose(); Common.SMallFollowedByCapital(); Common.IntegerOverload(0); Common.IntegerOverload((uint)0); Common.TakeVoidStarStar(null); Common.OverloadPointer(IntPtr.Zero, 1); using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { } #pragma warning restore 0168 #pragma warning restore 0219 }
public void UpdateServerSideReferenceField2() { using (Session session = Domain.OpenSession()) { using (TransactionScope trx = session.OpenTransaction()) { DateTime date = DateTime.Now; Guid id = Guid.NewGuid(); var bar = new Bar2(session, date, id); var foo = new Foo2(session, 1, "1"); var bar2 = new Bar2(session, DateTime.Now, Guid.NewGuid()); session.SaveChanges(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.Single(Key.Create(Domain, typeof(Bar2), date, id))).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.Single <Bar2>(Key.Create <Bar2>(Domain, date, id))).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.Single <Bar2>(date, id)).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.SingleOrDefault(Key.Create(Domain, typeof(Bar2), date, id))).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.SingleOrDefault <Bar2>(Key.Create <Bar2>(Domain, date, id))).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.SingleOrDefault <Bar2>(date, id)).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().Where(b => b.Id2 == id).First()). Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().First(b => b.Id2 == id)).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.All <Bar2>().Where(b => b.Id2 == id).FirstOrDefault()).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().FirstOrDefault(b => b.Id2 == id)). Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().Where(b => b.Id2 == id).Single()). Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().Single(b => b.Id2 == id)).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set( a => a.Bar, a => session.Query.All <Bar2>().Where(b => b.Id2 == id).SingleOrDefault()).Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); session.Query.All <Foo2>().Set(a => a.Bar, (Bar2)null).Update(); Assert.That(foo.Bar, Is.Null); session.AssertCommandCount( Is.EqualTo(1), () => session.Query.All <Foo2>().Set(a => a.Bar, a => session.Query.All <Bar2>().SingleOrDefault(b => b.Id2 == id)). Update()); Assert.That(bar, Is.EqualTo(foo.Bar)); trx.Complete(); } } }
public TestCtor(IFoo foo, Foo2 foo2) { Foo = foo; Foo2 = foo2; }
static void Helper <T> (T f, Foo2 arg2) where T : IFoo { }
public void CanSerializeUri() { var serializer = new JsonSerializer<Foo2>(); var foo = new Foo2 { Bar = new Uri("http://google.com/") }; var json = serializer.Serialize(foo); Assert.That(json, Is.EqualTo(@"{""Bar"":""http:\/\/google.com\/""}")); }
public static T Get_T(double d, T t) { return(Foo2 <T> .Get_T(d, t)); }
public double Run2() { var bar1 = new Foo1(); var bar2 = new Foo2(); return Run(bar1) + Run(bar2); }
public static Action Dingus(ref Foo2 f) { return(new Action(f.MoveNext)); }
public void Read_NestedList_DeserializesList() { var input = @"{""Bars"":[{""Baz"":""Test""}]}"; var expected = new Foo2 { Bars = new List<Bar2> { new Bar2 { Baz="Test"} } }; var actual = new JsonReader().Read<Foo2>(input); Assert.Equal(expected, actual); }
public Foo2([Mapping("contoso://myfoo")] Foo2 myFoo) { myFoo.MyFoo = myFoo; MyFoo = myFoo; Qux = new Qux2(); }
public void Init(Foo2 foo) { }
public void TestHello() { var hello = new Hello(); hello.PrintHello("Hello world"); Assert.That(hello.Add(1, 1), Is.EqualTo(2)); Assert.That(hello.Add(5, 5), Is.EqualTo(10)); Assert.IsTrue(hello.Test1(3, 3.0f)); Assert.IsFalse(hello.Test1(2, 3.0f)); var foo = new Foo { A = 4, B = 7 }; Assert.That(hello.AddFoo(foo), Is.EqualTo(11)); Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11)); Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11)); Assert.That(hello.AddFooRef(foo), Is.EqualTo(11)); unsafe { var pointer = foo.SomePointer; var pointerPointer = foo.SomePointerPointer; for (int i = 0; i < 4; i++) { Assert.AreEqual(i, pointer[i]); Assert.AreEqual(i, (*pointerPointer)[i]); } } var bar = new Bar { A = 4, B = 7 }; Assert.That(hello.AddBar(bar), Is.EqualTo(11)); Assert.That(bar.RetItem1(), Is.EqualTo(Bar.Item.Item1)); var retFoo = hello.RetFoo(7, 2.0f); Assert.That(retFoo.A, Is.EqualTo(7)); Assert.That(retFoo.B, Is.EqualTo(2.0)); var foo2 = new Foo2 { A = 4, B = 2, C = 3 }; Assert.That(hello.AddFoo(foo2), Is.EqualTo(6)); Assert.That(hello.AddFoo2(foo2), Is.EqualTo(9)); var bar2 = new Bar2 { A = 4, B = 7, C = 3 }; Assert.That(hello.AddBar2(bar2), Is.EqualTo(14)); Assert.That(hello.RetEnum(Enum.A), Is.EqualTo(0)); Assert.That(hello.RetEnum(Enum.B), Is.EqualTo(2)); Assert.That(hello.RetEnum(Enum.C), Is.EqualTo(5)); //Assert.That(hello.RetEnum(Enum.D), Is.EqualTo(-2147483648)); Assert.That(hello.RetEnum(Enum.E), Is.EqualTo(1)); Assert.That(hello.RetEnum(Enum.F), Is.EqualTo(-9)); }
private static int TestInterfaceCache() { MyInterface[] itfs = new MyInterface[50]; itfs[0] = new Foo0(); itfs[1] = new Foo1(); itfs[2] = new Foo2(); itfs[3] = new Foo3(); itfs[4] = new Foo4(); itfs[5] = new Foo5(); itfs[6] = new Foo6(); itfs[7] = new Foo7(); itfs[8] = new Foo8(); itfs[9] = new Foo9(); itfs[10] = new Foo10(); itfs[11] = new Foo11(); itfs[12] = new Foo12(); itfs[13] = new Foo13(); itfs[14] = new Foo14(); itfs[15] = new Foo15(); itfs[16] = new Foo16(); itfs[17] = new Foo17(); itfs[18] = new Foo18(); itfs[19] = new Foo19(); itfs[20] = new Foo20(); itfs[21] = new Foo21(); itfs[22] = new Foo22(); itfs[23] = new Foo23(); itfs[24] = new Foo24(); itfs[25] = new Foo25(); itfs[26] = new Foo26(); itfs[27] = new Foo27(); itfs[28] = new Foo28(); itfs[29] = new Foo29(); itfs[30] = new Foo30(); itfs[31] = new Foo31(); itfs[32] = new Foo32(); itfs[33] = new Foo33(); itfs[34] = new Foo34(); itfs[35] = new Foo35(); itfs[36] = new Foo36(); itfs[37] = new Foo37(); itfs[38] = new Foo38(); itfs[39] = new Foo39(); itfs[40] = new Foo40(); itfs[41] = new Foo41(); itfs[42] = new Foo42(); itfs[43] = new Foo43(); itfs[44] = new Foo44(); itfs[45] = new Foo45(); itfs[46] = new Foo46(); itfs[47] = new Foo47(); itfs[48] = new Foo48(); itfs[49] = new Foo49(); StringBuilder sb = new StringBuilder(); int counter = 0; for (int i = 0; i < 50; i++) { sb.Append(itfs[i].GetAString()); counter += itfs[i].GetAnInt(); } string expected = "Foo0Foo1Foo2Foo3Foo4Foo5Foo6Foo7Foo8Foo9Foo10Foo11Foo12Foo13Foo14Foo15Foo16Foo17Foo18Foo19Foo20Foo21Foo22Foo23Foo24Foo25Foo26Foo27Foo28Foo29Foo30Foo31Foo32Foo33Foo34Foo35Foo36Foo37Foo38Foo39Foo40Foo41Foo42Foo43Foo44Foo45Foo46Foo47Foo48Foo49"; if (!expected.Equals(sb.ToString())) { Console.WriteLine("Concatenating strings from interface calls failed."); Console.Write("Expected: "); Console.WriteLine(expected); Console.Write(" Actual: "); Console.WriteLine(sb.ToString()); return(Fail); } if (counter != 1225) { Console.WriteLine("Summing ints from interface calls failed."); Console.WriteLine("Expected: 1225"); Console.Write("Actual: "); Console.WriteLine(counter); return(Fail); } return(100); }
public static void locals <T> (T t) { Foo2 <T> t2 = new Foo2 <T> (); object o = t2; }
public void TestLeftShiftOperator() { var foo2 = new Foo2 {C = 2}; Foo2 result = foo2 << 3; Assert.That(result.C, Is.EqualTo(16)); }
static void HelperToUseFoo2(Foo2 f) { }
public void TestLeftShiftOperator() { var foo2 = new Foo2 { C = 2 }; Foo2 result = foo2 << 3; foo2.testKeywordParam(IntPtr.Zero, Bar.Item.Item1, 1); Assert.That(result.C, Is.EqualTo(16)); }
public void TestInitializationWithServiceTypeAndComponent() { Type serviceType = typeof (Foo); Foo2 component = new Foo2(); ServiceMissingException exception = new ServiceMissingException(serviceType, component); Assert.IsTrue(exception.Message.Contains(serviceType.ToString())); Assert.IsTrue(exception.Message.Contains(component.ToString())); }
public void ForFoo2(Foo2 foo) { }
public void Foo2(Foo2 input) { }